From 8dfa7ee1c1f4d89007fbd4cdc5c1f5c4232483ac Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 6 Nov 2016 00:59:21 +0100 Subject: [PATCH] ~hentai changed, ~hentaibomb added (buffed ~hentai) --- src/NadekoBot/Modules/NSFW/NSFW.cs | 58 ++++++++++++++++--- .../Resources/CommandStrings.Designer.cs | 58 ++++++++++++++++++- src/NadekoBot/Resources/CommandStrings.resx | 17 ++++-- .../Services/Impl/GoogleApiService.cs | 4 ++ 4 files changed, 122 insertions(+), 15 deletions(-) diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index bd3dac2f..2ae6a96e 100644 --- a/src/NadekoBot/Modules/NSFW/NSFW.cs +++ b/src/NadekoBot/Modules/NSFW/NSFW.cs @@ -30,11 +30,51 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; - var links = await Task.WhenAll(GetGelbooruImageLink("rating%3Aexplicit+" + tag), GetDanbooruImageLink("rating%3Aexplicit+" + tag)).ConfigureAwait(false); + tag = "rating%3Aexplicit+" + tag; + + var rng = new NadekoRandom(); + Task provider = Task.FromResult(""); + switch (rng.Next(0,4)) + { + case 0: + provider = GetDanbooruImageLink(tag); + break; + case 1: + provider = GetGelbooruImageLink(tag); + break; + case 2: + provider = GetATFbooruImageLink(tag); + break; + case 3: + provider = GetKonachanImageLink(tag); + break; + default: + break; + } + var link = await provider.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)] + public async Task HentaiBomb(IUserMessage umsg, [Remainder] string tag = null) + { + var channel = (ITextChannel)umsg.Channel; + + tag = tag?.Trim() ?? ""; + tag = "rating%3Aexplicit+" + tag; + + var links = await Task.WhenAll(GetGelbooruImageLink(tag), + GetDanbooruImageLink(tag), + GetKonachanImageLink(tag), + GetATFbooruImageLink(tag)).ConfigureAwait(false); if (links.All(l => l == null)) { - await channel.SendMessageAsync("`No results.`"); + await channel.SendMessageAsync("`No results.`").ConfigureAwait(false); return; } @@ -50,7 +90,7 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; var link = await GetATFbooruImageLink(tag).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(link)) - await channel.SendMessageAsync("Search yielded no results ;("); + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); else await channel.SendMessageAsync(link).ConfigureAwait(false); } @@ -64,7 +104,7 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; var link = await GetDanbooruImageLink(tag).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(link)) - await channel.SendMessageAsync("Search yielded no results ;("); + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); else await channel.SendMessageAsync(link).ConfigureAwait(false); } @@ -78,7 +118,7 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; var link = await GetKonachanImageLink(tag).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(link)) - await channel.SendMessageAsync("Search yielded no results ;("); + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); else await channel.SendMessageAsync(link).ConfigureAwait(false); } @@ -92,7 +132,7 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; var link = await GetGelbooruImageLink(tag).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(link)) - await channel.SendMessageAsync("Search yielded no results ;("); + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); else await channel.SendMessageAsync(link).ConfigureAwait(false); } @@ -106,7 +146,7 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; var link = await GetRule34ImageLink(tag).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(link)) - await channel.SendMessageAsync("Search yielded no results ;("); + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); else await channel.SendMessageAsync(link).ConfigureAwait(false); } @@ -120,7 +160,7 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; var link = await GetE621ImageLink(tag).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(link)) - await channel.SendMessageAsync("Search yielded no results ;("); + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); else await channel.SendMessageAsync(link).ConfigureAwait(false); } @@ -190,7 +230,7 @@ namespace NadekoBot.Modules.NSFW if (matches.Count == 0) return null; - return await NadekoBot.Google.ShortenUrl(matches[rng.Next(0, matches.Count)].Groups["ll"].Value).ConfigureAwait(false); + return matches[rng.Next(0, matches.Count)].Groups["ll"].Value; } } diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index a0eec5a2..b34b06f9 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -464,6 +464,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to atfbooru atf. + /// + public static string atfbooru_cmd { + get { + return ResourceManager.GetString("atfbooru_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shows a random hentai image from atfbooru with a given tag. Tag is optional but preferred.. + /// + public static string atfbooru_desc { + get { + return ResourceManager.GetString("atfbooru_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}atfbooru yuri+kissing`. + /// + public static string atfbooru_usage { + get { + return ResourceManager.GetString("atfbooru_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to autoassignrole aar. /// @@ -2823,7 +2850,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Shows a 2 random images (from gelbooru and danbooru) 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) with a given tag. Tag is optional but preferred. Only 1 tag allowed.. /// public static string hentai_desc { get { @@ -2840,6 +2867,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to hentaibomb. + /// + public static string hentaibomb_cmd { + get { + return ResourceManager.GetString("hentaibomb_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shows a total 4 images (from gelbooru, danbooru, konachan and atfbooru). Tag is optional but preferred.. + /// + public static string hentaibomb_desc { + get { + return ResourceManager.GetString("hentaibomb_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}hentaibomb yuri`. + /// + public static string hentaibomb_usage { + get { + return ResourceManager.GetString("hentaibomb_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to hgit. /// @@ -3147,7 +3201,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Shows a random hentai image from konachan with a given tag. Tag is optional but preferred. (multiple tags are appended with +). + /// Looks up a localized string similar to Shows a random hentai image from konachan with a given tag. Tag is optional but preferred.. /// public static string konachan_desc { get { diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index a9d42d0d..e414ffe5 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2101,7 +2101,7 @@ hentai - Shows a 2 random images (from gelbooru and danbooru) 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) with a given tag. Tag is optional but preferred. Only 1 tag allowed. `{0}hentai yuri` @@ -2115,7 +2115,7 @@ `{0}danbooru yuri+kissing` - + atfbooru atf @@ -2123,7 +2123,7 @@ `{0}atfbooru yuri+kissing` - + gelbooru @@ -2461,7 +2461,7 @@ konachan - Shows a random hentai image from konachan with a given tag. Tag is optional but preferred. (multiple tags are appended with +) + Shows a random hentai image from konachan with a given tag. Tag is optional but preferred. `{0}konachan yuri` @@ -2610,4 +2610,13 @@ `{0}listservers 3` + + hentaibomb + + + Shows a total 4 images (from gelbooru, danbooru, konachan and atfbooru). Tag is optional but preferred. + + + `{0}hentaibomb yuri` + \ No newline at end of file diff --git a/src/NadekoBot/Services/Impl/GoogleApiService.cs b/src/NadekoBot/Services/Impl/GoogleApiService.cs index 5d578dc1..860a379c 100644 --- a/src/NadekoBot/Services/Impl/GoogleApiService.cs +++ b/src/NadekoBot/Services/Impl/GoogleApiService.cs @@ -91,6 +91,10 @@ namespace NadekoBot.Services.Impl { if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + + if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.GoogleApiKey)) + return url; + try { var response = await sh.Url.Insert(new Url { LongUrl = url }).ExecuteAsync();