diff --git a/NadekoBot/Classes/SearchHelper.cs b/NadekoBot/Classes/SearchHelper.cs index 2b3ba0d8..7270a47b 100644 --- a/NadekoBot/Classes/SearchHelper.cs +++ b/NadekoBot/Classes/SearchHelper.cs @@ -225,6 +225,8 @@ namespace NadekoBot.Classes var webpage = await GetResponseStringAsync(link).ConfigureAwait(false); var matches = Regex.Matches(webpage, "data-large-file-url=\"(?.*?)\""); + if (matches.Count == 0) + return null; return $"http://danbooru.donmai.us" + $"{matches[rng.Next(0, matches.Count)].Groups["id"].Value}"; } @@ -236,7 +238,7 @@ namespace NadekoBot.Classes var webpage = await GetResponseStringAsync(url).ConfigureAwait(false); var matches = Regex.Matches(webpage, "file_url=\"(?.*?)\""); if (matches.Count == 0) - throw new FileNotFoundException(); + return null; var rng = new Random(); var match = matches[rng.Next(0, matches.Count)]; return matches[rng.Next(0, matches.Count)].Groups["url"].Value; diff --git a/NadekoBot/Classes/ServerSpecificConfig.cs b/NadekoBot/Classes/ServerSpecificConfig.cs index a7615b56..66f43fe1 100644 --- a/NadekoBot/Classes/ServerSpecificConfig.cs +++ b/NadekoBot/Classes/ServerSpecificConfig.cs @@ -120,7 +120,6 @@ namespace NadekoBot.Classes private void OnPropertyChanged([CallerMemberName] string propertyName = null) { - Console.WriteLine("property changed"); PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } diff --git a/NadekoBot/Modules/NSFW/NSFWModule.cs b/NadekoBot/Modules/NSFW/NSFWModule.cs index c18d6d09..8210e67d 100644 --- a/NadekoBot/Modules/NSFW/NSFWModule.cs +++ b/NadekoBot/Modules/NSFW/NSFWModule.cs @@ -27,10 +27,16 @@ namespace NadekoBot.Modules.NSFW .Do(async e => { var tag = e.GetArg("tag")?.Trim() ?? ""; - await e.Channel.SendMessage(":heart: Gelbooru: " + await SearchHelper.GetGelbooruImageLink("rating%3Aexplicit+" + tag).ConfigureAwait(false)) - .ConfigureAwait(false); - await e.Channel.SendMessage(":heart: Danbooru: " + await SearchHelper.GetDanbooruImageLink("rating%3Aexplicit+" + tag).ConfigureAwait(false)) - .ConfigureAwait(false); + var gel = await SearchHelper.GetGelbooruImageLink("rating%3Aexplicit+" + tag).ConfigureAwait(false); + if (gel != null) + await e.Channel.SendMessage(":heart: Gelbooru: " + gel) + .ConfigureAwait(false); + var dan = await SearchHelper.GetDanbooruImageLink("rating%3Aexplicit+" + tag).ConfigureAwait(false); + if (dan != null) + await e.Channel.SendMessage(":heart: Danbooru: " + dan) + .ConfigureAwait(false); + if (dan == null && gel == null) + await e.Channel.SendMessage("`No results.`"); }); cgb.CreateCommand(Prefix + "danbooru") .Description("Shows a random hentai image from danbooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +)\n**Usage**: ~danbooru yuri+kissing") @@ -38,7 +44,11 @@ namespace NadekoBot.Modules.NSFW .Do(async e => { var tag = e.GetArg("tag")?.Trim() ?? ""; - await e.Channel.SendMessage(await SearchHelper.GetDanbooruImageLink(tag).ConfigureAwait(false)).ConfigureAwait(false); + var link = await SearchHelper.GetDanbooruImageLink(tag).ConfigureAwait(false); + if (string.IsNullOrWhiteSpace(link)) + await e.Channel.SendMessage("Search yielded no results ;("); + else + await e.Channel.SendMessage(link).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "gelbooru") .Description("Shows a random hentai image from gelbooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +)\n**Usage**: ~gelbooru yuri+kissing") @@ -46,7 +56,11 @@ namespace NadekoBot.Modules.NSFW .Do(async e => { var tag = e.GetArg("tag")?.Trim() ?? ""; - await e.Channel.SendMessage(await SearchHelper.GetGelbooruImageLink(tag).ConfigureAwait(false)).ConfigureAwait(false); + var link = await SearchHelper.GetGelbooruImageLink(tag).ConfigureAwait(false); + if (string.IsNullOrWhiteSpace(link)) + await e.Channel.SendMessage("Search yielded no results ;("); + else + await e.Channel.SendMessage(link).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "rule34")