~konachan added :D

This commit is contained in:
Kwoth 2016-10-19 06:22:18 +02:00
parent eff92b3328
commit 3859e00e88
3 changed files with 74 additions and 5 deletions

View File

@ -55,6 +55,20 @@ namespace NadekoBot.Modules.NSFW
await channel.SendMessageAsync(link).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Konachan(IUserMessage umsg, [Remainder] string tag = null)
{
var channel = (ITextChannel)umsg.Channel;
tag = tag?.Trim() ?? "";
var link = await GetKonachanImageLink(tag).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(link))
await channel.SendMessageAsync("Search yielded no results ;(");
else
await channel.SendMessageAsync(link).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Gelbooru(IUserMessage umsg, [Remainder] string tag = null)
@ -147,6 +161,25 @@ namespace NadekoBot.Modules.NSFW
}
}
public static async Task<string> GetKonachanImageLink(string tag)
{
var rng = new NadekoRandom();
var link = $"http://konachan.com/post?" +
$"page={rng.Next(0, 5)}";
if (!string.IsNullOrWhiteSpace(tag))
link += $"&tags={tag.Replace(" ", "_")}";
using (var http = new HttpClient())
{
var webpage = await http.GetStringAsync(link).ConfigureAwait(false);
var matches = Regex.Matches(webpage, "<a class=\"directlink largeimg\" href=\"(?<ll>.*?)\">");
if (matches.Count == 0)
return null;
return await NadekoBot.Google.ShortenUrl(matches[rng.Next(0, matches.Count)].Groups["ll"].Value).ConfigureAwait(false);
}
}
public static async Task<string> GetDanbooruImageLink(string tag)
{
var rng = new NadekoRandom();

View File

@ -3326,6 +3326,33 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to konachan.
/// </summary>
public static string konachan_cmd {
get {
return ResourceManager.GetString("konachan_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Shows a random hentai image from konachan with a given tag. Tag is optional but preffered. (multiple tags are appended with +).
/// </summary>
public static string konachan_desc {
get {
return ResourceManager.GetString("konachan_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `~konachan yuri`.
/// </summary>
public static string konachan_usage {
get {
return ResourceManager.GetString("konachan_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to lcsc.
/// </summary>

View File

@ -2209,7 +2209,7 @@
<value>safebooru</value>
</data>
<data name="safebooru_desc" xml:space="preserve">
<value>Shows a random image from safebooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +)</value>
<value>Shows a random image from safebooru with a given tag. Tag is optional but preferred. (multiple tags are appended with +)</value>
</data>
<data name="safebooru_usage" xml:space="preserve">
<value>`~safebooru yuri+kissing`</value>
@ -2263,7 +2263,7 @@
<value>danbooru</value>
</data>
<data name="danbooru_desc" xml:space="preserve">
<value>Shows a random hentai image from danbooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +)</value>
<value>Shows a random hentai image from danbooru with a given tag. Tag is optional but preferred. (multiple tags are appended with +)</value>
</data>
<data name="danbooru_usage" xml:space="preserve">
<value>`~danbooru yuri+kissing`</value>
@ -2272,7 +2272,7 @@
<value>gelbooru</value>
</data>
<data name="gelbooru_desc" xml:space="preserve">
<value>Shows a random hentai image from gelbooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +)</value>
<value>Shows a random hentai image from gelbooru with a given tag. Tag is optional but preferred. (multiple tags are appended with +)</value>
</data>
<data name="gelbooru_usage" xml:space="preserve">
<value>`~gelbooru yuri+kissing`</value>
@ -2281,7 +2281,7 @@
<value>rule34</value>
</data>
<data name="rule34_desc" xml:space="preserve">
<value>Shows a random image from rule34.xx with a given tag. Tag is optional but preffered. (multiple tags are appended with +)</value>
<value>Shows a random image from rule34.xx with a given tag. Tag is optional but preferred. (multiple tags are appended with +)</value>
</data>
<data name="rule34_usage" xml:space="preserve">
<value>`~rule34 yuri+kissing`</value>
@ -2290,7 +2290,7 @@
<value>e621</value>
</data>
<data name="e621_desc" xml:space="preserve">
<value>Shows a random hentai image from e621.net with a given tag. Tag is optional but preffered. Use spaces for multiple tags.</value>
<value>Shows a random hentai image from e621.net with a given tag. Tag is optional but preferred. Use spaces for multiple tags.</value>
</data>
<data name="e621_usage" xml:space="preserve">
<value>`~e621 yuri kissing`</value>
@ -2682,4 +2682,13 @@
<data name="voicemute_usage" xml:space="preserve">
<value>`.voicemute @Someone`</value>
</data>
<data name="konachan_cmd" xml:space="preserve">
<value>konachan</value>
</data>
<data name="konachan_desc" xml:space="preserve">
<value>Shows a random hentai image from konachan with a given tag. Tag is optional but preferred. (multiple tags are appended with +)</value>
</data>
<data name="konachan_usage" xml:space="preserve">
<value>`~konachan yuri`</value>
</data>
</root>