more error avoidance to nsfw

This commit is contained in:
Master Kwoth 2016-05-03 07:16:45 +02:00
parent 1922c10b21
commit 6fce1dd35c
3 changed files with 12 additions and 4 deletions

View File

@ -252,7 +252,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 match = matches[rng.Next(0, matches.Count)];
return matches[rng.Next(0, matches.Count)].Groups["url"].Value;
}
@ -265,7 +265,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 match = matches[rng.Next(0, matches.Count)];
return "http:" + matches[rng.Next(0, matches.Count)].Groups["url"].Value;
}

View File

@ -69,7 +69,11 @@ namespace NadekoBot.Modules.NSFW
.Do(async e =>
{
var tag = e.GetArg("tag")?.Trim() ?? "";
await e.Channel.SendMessage(await SearchHelper.GetRule34ImageLink(tag).ConfigureAwait(false)).ConfigureAwait(false);
var link = await SearchHelper.GetRule34ImageLink(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 + "e621")
.Description("Shows a random hentai image from e621.net with a given tag. Tag is optional but preffered. Use spaces for multiple tags.\n**Usage**: ~e621 yuri+kissing")

View File

@ -433,7 +433,11 @@ $@"🌍 **Weather for** 【{obj["target"]}】
.Do(async e =>
{
var tag = e.GetArg("tag")?.Trim() ?? "";
await e.Channel.SendMessage(await SearchHelper.GetSafebooruImageLink(tag).ConfigureAwait(false)).ConfigureAwait(false);
var link = await SearchHelper.GetSafebooruImageLink(tag).ConfigureAwait(false);
if (link == null)
await e.Channel.SendMessage("`No results.`");
else
await e.Channel.SendMessage(link).ConfigureAwait(false);
});
});
}