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