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