Less errors in nsfw (danbooru and gelbooru)
This commit is contained in:
parent
374d302a41
commit
1922c10b21
@ -225,6 +225,8 @@ namespace NadekoBot.Classes
|
||||
var webpage = await GetResponseStringAsync(link).ConfigureAwait(false);
|
||||
var matches = Regex.Matches(webpage, "data-large-file-url=\"(?<id>.*?)\"");
|
||||
|
||||
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=\"(?<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;
|
||||
|
@ -120,7 +120,6 @@ namespace NadekoBot.Classes
|
||||
|
||||
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
Console.WriteLine("property changed");
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user