From 769d034eabd4ea712982dbe49d3435608c7e8f79 Mon Sep 17 00:00:00 2001 From: fkndean Date: Mon, 14 Nov 2016 05:17:50 -0500 Subject: [PATCH 1/4] Add Yande.re search --- src/NadekoBot/Modules/Searches/Searches.cs | 30 +++++++++++++++++++ .../Resources/CommandStrings.Designer.cs | 27 +++++++++++++++++ src/NadekoBot/Resources/CommandStrings.resx | 9 ++++++ 3 files changed, 66 insertions(+) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 19642917..b9589a99 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -385,6 +385,20 @@ $@"🌍 **Weather for** 【{obj["target"]}】 return; await channel.SendMessageAsync($"https://images.google.com/searchbyimage?image_url={imageLink}").ConfigureAwait(false); } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task Yandere(IUserMessage umsg, [Remainder] string tag = null) + { + var channel = (ITextChannel)umsg.Channel; + + tag = tag?.Trim() ?? ""; + var link = await GetYandereImageLink(tag).ConfigureAwait(false); + if (link == null) + await channel.SendMessageAsync("`No results.`"); + else + await channel.SendMessageAsync(link).ConfigureAwait(false); + } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] @@ -477,6 +491,22 @@ $@"🌍 **Weather for** 【{obj["target"]}】 } await channel.SendMessageAsync(await _google.ShortenUrl(usr.AvatarUrl).ConfigureAwait(false)).ConfigureAwait(false); } + + public static async Task GetYandereImageLink(string tag) + { + var rng = new NadekoRandom(); + var url = + $"https://yande.re/post.xml?limit=100&tags={tag.Replace(" ", "_")}"; + using (var http = new HttpClient()) + { + var webpage = await http.GetStringAsync(url).ConfigureAwait(false); + var matches = Regex.Matches(webpage, "file_url=\"(?.*?)\""); + if (matches.Count == 0) + return null; + var match = matches[rng.Next(0, matches.Count)]; + return matches[rng.Next(0, matches.Count)].Groups["url"].Value; + } + } public static async Task GetSafebooruImageLink(string tag) { diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index ebfe4e3c..289ab0cd 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -7753,5 +7753,32 @@ namespace NadekoBot.Resources { return ResourceManager.GetString("youtube_usage", resourceCulture); } } + + /// + /// Looks up a localized string similar to yandere. + /// + public static string yandere_cmd { + get { + return ResourceManager.GetString("yandere_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shows a random image from yandere with a given tag. Tag is optional but preferred. (multiple tags are appended with +). + /// + public static string yandere_desc { + get { + return ResourceManager.GetString("yandere_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}yandere tag1+tag2`. + /// + public static string yandere_usage { + get { + return ResourceManager.GetString("yandere_usage", resourceCulture); + } + } } } diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 1d924628..03a7cd21 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2682,4 +2682,13 @@ `{0}bfu platform game user` + + yandere + + + Shows a random image from yandere with a given tag. Tag is optional but preferred. (multiple tags are appended with +) + + + `{0}yandere tag1+tag2` + \ No newline at end of file From 1ccc0496555af7763655ad21ceb76dc2e035abdd Mon Sep 17 00:00:00 2001 From: fkndean Date: Mon, 14 Nov 2016 16:34:11 -0500 Subject: [PATCH 2/4] Add Safeyandere, Moved Yandere to NSFW and added to :bomb: --- src/NadekoBot/Modules/NSFW/NSFW.cs | 46 +++++++++- src/NadekoBot/Modules/Searches/Searches.cs | 22 +++-- .../Resources/CommandStrings.Designer.cs | 85 ++++++++++++------- src/NadekoBot/Resources/CommandStrings.resx | 11 ++- 4 files changed, 127 insertions(+), 37 deletions(-) diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index 2ae6a96e..e94a7f46 100644 --- a/src/NadekoBot/Modules/NSFW/NSFW.cs +++ b/src/NadekoBot/Modules/NSFW/NSFW.cs @@ -34,7 +34,7 @@ namespace NadekoBot.Modules.NSFW var rng = new NadekoRandom(); Task provider = Task.FromResult(""); - switch (rng.Next(0,4)) + switch (rng.Next(0,5)) { case 0: provider = GetDanbooruImageLink(tag); @@ -48,6 +48,9 @@ namespace NadekoBot.Modules.NSFW case 3: provider = GetKonachanImageLink(tag); break; + case 4: + provider = GetYandereImageLink(tag); + break; default: break; } @@ -70,6 +73,7 @@ namespace NadekoBot.Modules.NSFW var links = await Task.WhenAll(GetGelbooruImageLink(tag), GetDanbooruImageLink(tag), GetKonachanImageLink(tag), + GetYandereImageLink(tag), GetATFbooruImageLink(tag)).ConfigureAwait(false); if (links.All(l => l == null)) @@ -94,6 +98,46 @@ namespace NadekoBot.Modules.NSFW else await channel.SendMessageAsync(link).ConfigureAwait(false); } + + public static async Task GetYandereImageLink(string tag) + { + var rng = new NadekoRandom(); + var url = + $"https://yande.re/post.xml?" + + $"limit=25" + + $"&page={rng.Next(0, 15)}" + + $"&tags={tag.Replace(" ", "_")}"; + using (var http = new HttpClient()) + { + var webpage = await http.GetStringAsync(url).ConfigureAwait(false); + var matches = Regex.Matches(webpage, "file_url=\"(?.*?)\""); + var rating = Regex.Matches(webpage, "rating=\"(?.*?)\""); + if (matches.Count == 0) + return null; + if (string.Equals(rating[rng.Next(0, rating.Count)].Groups["rate"].Value.ToString(), "e") || string.Equals(rating[rng.Next(0, rating.Count)].Groups["rate"].Value.ToString(), "q")) + { + return matches[rng.Next(0, matches.Count)].Groups["url"].Value; + } + else + { + return null; + } + } + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task Yandere(IUserMessage umsg, [Remainder] string tag = null) + { + var channel = (ITextChannel)umsg.Channel; + + tag = tag?.Trim() ?? ""; + var link = await GetYandereImageLink(tag).ConfigureAwait(false); + if (string.IsNullOrWhiteSpace(link)) + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); + else + await channel.SendMessageAsync(link).ConfigureAwait(false); + } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index b9589a99..1dcb8f6e 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -388,12 +388,12 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task Yandere(IUserMessage umsg, [Remainder] string tag = null) + public async Task Safeyandere(IUserMessage umsg, [Remainder] string tag = null) { var channel = (ITextChannel)umsg.Channel; tag = tag?.Trim() ?? ""; - var link = await GetYandereImageLink(tag).ConfigureAwait(false); + var link = await GetSafeYandereImageLink(tag).ConfigureAwait(false); if (link == null) await channel.SendMessageAsync("`No results.`"); else @@ -492,19 +492,29 @@ $@"🌍 **Weather for** 【{obj["target"]}】 await channel.SendMessageAsync(await _google.ShortenUrl(usr.AvatarUrl).ConfigureAwait(false)).ConfigureAwait(false); } - public static async Task GetYandereImageLink(string tag) + public static async Task GetSafeYandereImageLink(string tag) { var rng = new NadekoRandom(); var url = - $"https://yande.re/post.xml?limit=100&tags={tag.Replace(" ", "_")}"; + $"https://yande.re/post.xml?" + + $"limit=25" + + $"&page={rng.Next(0, 15)}" + + $"&tags={tag.Replace(" ", "_")}"; using (var http = new HttpClient()) { var webpage = await http.GetStringAsync(url).ConfigureAwait(false); var matches = Regex.Matches(webpage, "file_url=\"(?.*?)\""); + var rating = Regex.Matches(webpage, "rating=\"(?.*?)\""); if (matches.Count == 0) return null; - var match = matches[rng.Next(0, matches.Count)]; - return matches[rng.Next(0, matches.Count)].Groups["url"].Value; + if (string.Equals(rating[rng.Next(0, rating.Count)].Groups["rate"].Value.ToString(), "s") || string.Equals(rating[rng.Next(0, rating.Count)].Groups["rate"].Value.ToString(), "q")) + { + return matches[rng.Next(0, matches.Count)].Groups["url"].Value; + } + else + { + return null; + } } } diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 289ab0cd..b382641f 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -2931,7 +2931,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Shows a hentai image from a random website (gelbooru or danbooru or konachan or atfbooru) with a given tag. Tag is optional but preferred. Only 1 tag allowed.. + /// Looks up a localized string similar to Shows a hentai image from a random website (gelbooru or danbooru or konachan or atfbooru or yandere) with a given tag. Tag is optional but preferred. Only 1 tag allowed.. /// public static string hentai_desc { get { @@ -2958,7 +2958,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Shows a total 4 images (from gelbooru, danbooru, konachan and atfbooru). Tag is optional but preferred.. + /// Looks up a localized string similar to Shows a total 5 images (from gelbooru, danbooru, konachan, yandere and atfbooru). Tag is optional but preferred.. /// public static string hentaibomb_desc { get { @@ -6673,6 +6673,33 @@ namespace NadekoBot.Resources { return ResourceManager.GetString("stop_usage", resourceCulture); } } + + /// + /// Looks up a localized string similar to safeyandere sy. + /// + public static string safeyandere_cmd { + get { + return ResourceManager.GetString("sy_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shows a safe random image from yandere with a given tag. Tag is optional but preferred. (multiple tags are appended with +). + /// + public static string safeyandere_desc { + get { + return ResourceManager.GetString("sy_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}sy tag1+tag2` or `{0}safeyandere tag1+tag2`. + /// + public static string safeyandere_usage { + get { + return ResourceManager.GetString("sy_usage", resourceCulture); + } + } /// /// Looks up a localized string similar to take. @@ -7699,6 +7726,33 @@ namespace NadekoBot.Resources { return ResourceManager.GetString("xkcd_usage", resourceCulture); } } + + /// + /// Looks up a localized string similar to yandere. + /// + public static string yandere_cmd { + get { + return ResourceManager.GetString("yandere_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shows a random image from yandere with a given tag. Tag is optional but preferred. (multiple tags are appended with +). + /// + public static string yandere_desc { + get { + return ResourceManager.GetString("yandere_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}yandere tag1+tag2`. + /// + public static string yandere_usage { + get { + return ResourceManager.GetString("yandere_usage", resourceCulture); + } + } /// /// Looks up a localized string similar to yomama ym. @@ -7753,32 +7807,5 @@ namespace NadekoBot.Resources { return ResourceManager.GetString("youtube_usage", resourceCulture); } } - - /// - /// Looks up a localized string similar to yandere. - /// - public static string yandere_cmd { - get { - return ResourceManager.GetString("yandere_cmd", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Shows a random image from yandere with a given tag. Tag is optional but preferred. (multiple tags are appended with +). - /// - public static string yandere_desc { - get { - return ResourceManager.GetString("yandere_desc", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to `{0}yandere tag1+tag2`. - /// - public static string yandere_usage { - get { - return ResourceManager.GetString("yandere_usage", resourceCulture); - } - } } } diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index f106bb15..34c40274 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2623,7 +2623,7 @@ hentaibomb - Shows a total 4 images (from gelbooru, danbooru, konachan and atfbooru). Tag is optional but preferred. + Shows a total 5 images (from gelbooru, danbooru, konachan, yandere and atfbooru). Tag is optional but preferred. `{0}hentaibomb yuri` @@ -2691,6 +2691,15 @@ `{0}bfu platform game user` + + safeyandere sy + + + Shows a safe random image from yandere with a given tag. Tag is optional but preferred. (multiple tags are appended with +) + + + `{0}sy tag1+tag2` or `{0}safeyandere tag1+tag2` + yandere From 96dd0b6096c6fb8ba7eb5dbf4412fa39090d2440 Mon Sep 17 00:00:00 2001 From: fkndean Date: Mon, 14 Nov 2016 16:36:05 -0500 Subject: [PATCH 3/4] updated desc for cmd --- src/NadekoBot/Resources/CommandStrings.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 34c40274..a288e948 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2110,7 +2110,7 @@ hentai - Shows a hentai image from a random website (gelbooru or danbooru or konachan or atfbooru) with a given tag. Tag is optional but preferred. Only 1 tag allowed. + Shows a hentai image from a random website (gelbooru or danbooru or konachan or atfbooru or yandere) with a given tag. Tag is optional but preferred. Only 1 tag allowed. `{0}hentai yuri` From 581ab1edeb87d1d1abdf57de0b7155dba0a65f42 Mon Sep 17 00:00:00 2001 From: fkndean Date: Mon, 14 Nov 2016 17:20:45 -0500 Subject: [PATCH 4/4] Remove safeyandere. --- src/NadekoBot/Modules/NSFW/NSFW.cs | 11 +---- src/NadekoBot/Modules/Searches/Searches.cs | 40 ------------------- .../Resources/CommandStrings.Designer.cs | 27 ------------- src/NadekoBot/Resources/CommandStrings.resx | 9 ----- 4 files changed, 2 insertions(+), 85 deletions(-) diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index e94a7f46..d5b1de03 100644 --- a/src/NadekoBot/Modules/NSFW/NSFW.cs +++ b/src/NadekoBot/Modules/NSFW/NSFW.cs @@ -111,17 +111,10 @@ namespace NadekoBot.Modules.NSFW { var webpage = await http.GetStringAsync(url).ConfigureAwait(false); var matches = Regex.Matches(webpage, "file_url=\"(?.*?)\""); - var rating = Regex.Matches(webpage, "rating=\"(?.*?)\""); + //var rating = Regex.Matches(webpage, "rating=\"(?.*?)\""); if (matches.Count == 0) return null; - if (string.Equals(rating[rng.Next(0, rating.Count)].Groups["rate"].Value.ToString(), "e") || string.Equals(rating[rng.Next(0, rating.Count)].Groups["rate"].Value.ToString(), "q")) - { - return matches[rng.Next(0, matches.Count)].Groups["url"].Value; - } - else - { - return null; - } + return matches[rng.Next(0, matches.Count)].Groups["url"].Value; } } diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 1dcb8f6e..19642917 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -385,20 +385,6 @@ $@"🌍 **Weather for** 【{obj["target"]}】 return; await channel.SendMessageAsync($"https://images.google.com/searchbyimage?image_url={imageLink}").ConfigureAwait(false); } - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - public async Task Safeyandere(IUserMessage umsg, [Remainder] string tag = null) - { - var channel = (ITextChannel)umsg.Channel; - - tag = tag?.Trim() ?? ""; - var link = await GetSafeYandereImageLink(tag).ConfigureAwait(false); - if (link == null) - await channel.SendMessageAsync("`No results.`"); - else - await channel.SendMessageAsync(link).ConfigureAwait(false); - } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] @@ -491,32 +477,6 @@ $@"🌍 **Weather for** 【{obj["target"]}】 } await channel.SendMessageAsync(await _google.ShortenUrl(usr.AvatarUrl).ConfigureAwait(false)).ConfigureAwait(false); } - - public static async Task GetSafeYandereImageLink(string tag) - { - var rng = new NadekoRandom(); - var url = - $"https://yande.re/post.xml?" + - $"limit=25" + - $"&page={rng.Next(0, 15)}" + - $"&tags={tag.Replace(" ", "_")}"; - using (var http = new HttpClient()) - { - var webpage = await http.GetStringAsync(url).ConfigureAwait(false); - var matches = Regex.Matches(webpage, "file_url=\"(?.*?)\""); - var rating = Regex.Matches(webpage, "rating=\"(?.*?)\""); - if (matches.Count == 0) - return null; - if (string.Equals(rating[rng.Next(0, rating.Count)].Groups["rate"].Value.ToString(), "s") || string.Equals(rating[rng.Next(0, rating.Count)].Groups["rate"].Value.ToString(), "q")) - { - return matches[rng.Next(0, matches.Count)].Groups["url"].Value; - } - else - { - return null; - } - } - } public static async Task GetSafebooruImageLink(string tag) { diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index b382641f..dec5bf12 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -6673,33 +6673,6 @@ namespace NadekoBot.Resources { return ResourceManager.GetString("stop_usage", resourceCulture); } } - - /// - /// Looks up a localized string similar to safeyandere sy. - /// - public static string safeyandere_cmd { - get { - return ResourceManager.GetString("sy_cmd", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Shows a safe random image from yandere with a given tag. Tag is optional but preferred. (multiple tags are appended with +). - /// - public static string safeyandere_desc { - get { - return ResourceManager.GetString("sy_desc", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to `{0}sy tag1+tag2` or `{0}safeyandere tag1+tag2`. - /// - public static string safeyandere_usage { - get { - return ResourceManager.GetString("sy_usage", resourceCulture); - } - } /// /// Looks up a localized string similar to take. diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index a288e948..aa936b7d 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2691,15 +2691,6 @@ `{0}bfu platform game user` - - safeyandere sy - - - Shows a safe random image from yandere with a given tag. Tag is optional but preferred. (multiple tags are appended with +) - - - `{0}sy tag1+tag2` or `{0}safeyandere tag1+tag2` - yandere