From d0d675a0094d5e901288513e831a3fbe25cce8aa Mon Sep 17 00:00:00 2001 From: Emotion Date: Tue, 8 Aug 2023 23:06:30 +1200 Subject: [PATCH] Added some files I missed --- .../_common/Config/ImgSearchEngine.cs | 7 ++ .../_common/Config/SearchesConfig.cs | 77 +++++++++++++++++++ .../_common/Config/SearchesConfigService.cs | 45 +++++++++++ .../_common/Config/WebSearchEngine.cs | 9 +++ .../Exceptions/StreamNotFoundException.cs | 18 +++++ 5 files changed, 156 insertions(+) create mode 100644 src/Ellie.Bot.Modules.Searches/_common/Config/ImgSearchEngine.cs create mode 100644 src/Ellie.Bot.Modules.Searches/_common/Config/SearchesConfig.cs create mode 100644 src/Ellie.Bot.Modules.Searches/_common/Config/SearchesConfigService.cs create mode 100644 src/Ellie.Bot.Modules.Searches/_common/Config/WebSearchEngine.cs create mode 100644 src/Ellie.Bot.Modules.Searches/_common/Exceptions/StreamNotFoundException.cs diff --git a/src/Ellie.Bot.Modules.Searches/_common/Config/ImgSearchEngine.cs b/src/Ellie.Bot.Modules.Searches/_common/Config/ImgSearchEngine.cs new file mode 100644 index 0000000..6132c28 --- /dev/null +++ b/src/Ellie.Bot.Modules.Searches/_common/Config/ImgSearchEngine.cs @@ -0,0 +1,7 @@ +namespace Ellie.Modules.Searches; + +public enum ImgSearchEngine +{ + Google, + Searx, +} \ No newline at end of file diff --git a/src/Ellie.Bot.Modules.Searches/_common/Config/SearchesConfig.cs b/src/Ellie.Bot.Modules.Searches/_common/Config/SearchesConfig.cs new file mode 100644 index 0000000..d7f38d9 --- /dev/null +++ b/src/Ellie.Bot.Modules.Searches/_common/Config/SearchesConfig.cs @@ -0,0 +1,77 @@ +using Cloneable; +using Ellie.Common.Yml; + +namespace Ellie.Modules.Searches; + +[Cloneable] +public partial class SearchesConfig : ICloneable +{ + [Comment("DO NOT CHANGE")] + public int Version { get; set; } = 0; + + [Comment(""" + Which engine should .search command + 'google_scrape' - default. Scrapes the webpage for results. May break. Requires no api keys. + 'google' - official google api. Requires googleApiKey and google.searchId set in creds.yml + 'searx' - requires at least one searx instance specified in the 'searxInstances' property below + """)] + public WebSearchEngine WebSearchEngine { get; set; } = WebSearchEngine.Google_Scrape; + + [Comment(""" + Which engine should .image command use + 'google'- official google api. googleApiKey and google.imageSearchId set in creds.yml + 'searx' requires at least one searx instance specified in the 'searxInstances' property below + """)] + public ImgSearchEngine ImgSearchEngine { get; set; } = ImgSearchEngine.Google; + + + [Comment(""" + Which search provider will be used for the `.youtube` command. + + - `ytDataApiv3` - uses google's official youtube data api. Requires `GoogleApiKey` set in creds and youtube data api enabled in developers console + + - `ytdl` - default, uses youtube-dl. Requires `youtube-dl` to be installed and it's path added to env variables. Slow. + + - `ytdlp` - recommended easy, uses `yt-dlp`. Requires `yt-dlp` to be installed and it's path added to env variables + + - `invidious` - recommended advanced, uses invidious api. Requires at least one invidious instance specified in the `invidiousInstances` property + """)] + public YoutubeSearcher YtProvider { get; set; } = YoutubeSearcher.Ytdlp; + + [Comment(""" + Set the searx instance urls in case you want to use 'searx' for either img or web search. + Nadeko will use a random one for each request. + Use a fully qualified url. Example: `https://my-searx-instance.mydomain.com` + Instances specified must support 'format=json' query parameter. + - In case you're running your own searx instance, set + + search: + formats: + - json + + in 'searxng/settings.yml' on your server + + - If you're using a public instance, make sure that the instance you're using supports it (they usually don't) + """)] + public List SearxInstances { get; set; } = new List(); + + [Comment(""" + Set the invidious instance urls in case you want to use 'invidious' for `.youtube` search + Nadeko will use a random one for each request. + These instances may be used for music queue functionality in the future. + Use a fully qualified url. Example: https://my-invidious-instance.mydomain.com + + Instances specified must have api available. + You check that by opening an api endpoint in your browser. For example: https://my-invidious-instance.mydomain.com/api/v1/trending + """)] + public List InvidiousInstances { get; set; } = new List(); +} + +public enum YoutubeSearcher +{ + YtDataApiv3, + Ytdl, + Ytdlp, + Invid, + Invidious = 3 +} \ No newline at end of file diff --git a/src/Ellie.Bot.Modules.Searches/_common/Config/SearchesConfigService.cs b/src/Ellie.Bot.Modules.Searches/_common/Config/SearchesConfigService.cs new file mode 100644 index 0000000..34edc0c --- /dev/null +++ b/src/Ellie.Bot.Modules.Searches/_common/Config/SearchesConfigService.cs @@ -0,0 +1,45 @@ +using Ellie.Common.Configs; + +namespace Ellie.Modules.Searches; + +public class SearchesConfigService : ConfigServiceBase +{ + private static string FILE_PATH = "data/searches.yml"; + private static readonly TypedKey _changeKey = new("config.searches.updated"); + + public override string Name + => "searches"; + + public SearchesConfigService(IConfigSeria serializer, IPubSub pubSub) + : base(FILE_PATH, serializer, pubSub, _changeKey) + { + AddParsedProp("webEngine", + sc => sc.WebSearchEngine, + ConfigParsers.InsensitiveEnum, + ConfigPrinters.ToString); + + AddParsedProp("imgEngine", + sc => sc.ImgSearchEngine, + ConfigParsers.InsensitiveEnum, + ConfigPrinters.ToString); + + AddParsedProp("ytProvider", + sc => sc.YtProvider, + ConfigParsers.InsensitiveEnum, + ConfigPrinters.ToString); + + Migrate(); + } + + private void Migrate() + { + if (data.Version < 1) + { + ModifyConfig(c => + { + c.Version = 1; + c.WebSearchEngine = WebSearchEngine.Google_Scrape; + }); + } + } +} \ No newline at end of file diff --git a/src/Ellie.Bot.Modules.Searches/_common/Config/WebSearchEngine.cs b/src/Ellie.Bot.Modules.Searches/_common/Config/WebSearchEngine.cs new file mode 100644 index 0000000..7d16a86 --- /dev/null +++ b/src/Ellie.Bot.Modules.Searches/_common/Config/WebSearchEngine.cs @@ -0,0 +1,9 @@ +// ReSharper disable InconsistentNaming +namespace Ellie.Modules.Searches; + +public enum WebSearchEngine +{ + Google, + Google_Scrape, + Searx, +} \ No newline at end of file diff --git a/src/Ellie.Bot.Modules.Searches/_common/Exceptions/StreamNotFoundException.cs b/src/Ellie.Bot.Modules.Searches/_common/Exceptions/StreamNotFoundException.cs new file mode 100644 index 0000000..0fbf098 --- /dev/null +++ b/src/Ellie.Bot.Modules.Searches/_common/Exceptions/StreamNotFoundException.cs @@ -0,0 +1,18 @@ +namespace Ellie.Modules.Searches.Common.Exceptions; + +public class StreamNotFoundException : Exception +{ + public StreamNotFoundException() + { + } + + public StreamNotFoundException(string message) + : base(message) + { + } + + public StreamNotFoundException(string message, Exception innerException) + : base(message, innerException) + { + } +} \ No newline at end of file