diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index 2ae6a96e..d5b1de03 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,39 @@ 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; + return matches[rng.Next(0, matches.Count)].Groups["url"].Value; + } + } + + [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/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index ebfe4e3c..dec5bf12 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 { @@ -7699,6 +7699,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. diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index b2a09d58..aa936b7d 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` @@ -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,4 +2691,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