From d07005876cc2c8d46c680a6ce8a5a7b70fbcac7b Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sun, 14 Feb 2016 16:07:19 +0100 Subject: [PATCH] added ~e621 nsfw command (at the request of kongslien) --- NadekoBot/Classes/SearchHelper.cs | 16 ++++++++++++++-- NadekoBot/Modules/Administration.cs | 5 +++-- NadekoBot/Modules/NSFW.cs | 9 +++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/NadekoBot/Classes/SearchHelper.cs b/NadekoBot/Classes/SearchHelper.cs index 12197f55..2a003e12 100644 --- a/NadekoBot/Classes/SearchHelper.cs +++ b/NadekoBot/Classes/SearchHelper.cs @@ -170,7 +170,7 @@ namespace NadekoBot.Classes { if (tag == "loli") //loli doesn't work for some reason atm tag = "flat_chest"; - var webpage = await GetResponseAsync($"http://danbooru.donmai.us/posts?page={ rng.Next(0, 30) }&tags={ tag.Replace(" ", "_") }"); + var webpage = await GetResponseAsync($"http://danbooru.donmai.us/posts?page={ rng.Next(0, 15) }&tags={ tag.Replace(" ", "_") }"); var matches = Regex.Matches(webpage, "data-large-file-url=\"(?.*?)\""); return await $"http://danbooru.donmai.us{ matches[rng.Next(0, matches.Count)].Groups["id"].Value }".ShortenUrl(); @@ -182,7 +182,7 @@ namespace NadekoBot.Classes { public static async Task GetGelbooruImageLink(string tag) { try { var rng = new Random(); - var url = $"http://gelbooru.com/index.php?page=post&s=list&pid={ rng.Next(0, 15) * 42 }&tags={ tag.Replace(" ", "_") }"; + var url = $"http://gelbooru.com/index.php?page=post&s=list&pid={ rng.Next(0, 10) * 42 }&tags={ tag.Replace(" ", "_") }"; var webpage = await GetResponseAsync(url); // first extract the post id and go to that posts page var matches = Regex.Matches(webpage, "span id=\"s(?\\d*)\""); var postLink = $"http://gelbooru.com/index.php?page=post&s=view&id={ matches[rng.Next(0, matches.Count)].Groups["id"].Value }"; @@ -195,6 +195,18 @@ namespace NadekoBot.Classes { } } + internal static async Task GetE621ImageLink(string tags) { + try { + var rng = new Random(); + var url = $"https://e621.net/post/index/{rng.Next(0, 5)}/{Uri.EscapeUriString(tags)}"; + var webpage = await GetResponseAsync(url); // first extract the post id and go to that posts page + var matches = Regex.Matches(webpage, "\"file_url\":\"(?.*?)\""); + return matches[rng.Next(0,matches.Count)].Groups["url"].Value; + } catch { + return null; + } + } + public static async Task ShortenUrl(string url) { if (NadekoBot.GoogleAPIKey == null || NadekoBot.GoogleAPIKey == "") return url; try { diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index 2f81f25a..ce78d356 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -141,6 +141,7 @@ namespace NadekoBot.Modules { } }); + cgb.CreateCommand(".roles") .Description("List all roles on this server or a single user if specified.") .Parameter("user", ParameterType.Unparsed) @@ -597,10 +598,10 @@ namespace NadekoBot.Modules { .Do(async e => { await Task.Run(async () => { var rows = Classes.DBHandler.Instance.GetAllRows(); - var donatorsOrdered = rows.OrderBy(d => d.Amount); + var donatorsOrdered = rows.OrderByDescending(d => d.Amount); string str = $"`Total number of people who donated is {donatorsOrdered.Count()}`\n"; - await e.Channel.SendMessage(string.Join(", ", donatorsOrdered.Select(d => d.UserName))); + await e.Channel.SendMessage(str + string.Join(", ", donatorsOrdered.Select(d => d.UserName))); }); }); diff --git a/NadekoBot/Modules/NSFW.cs b/NadekoBot/Modules/NSFW.cs index 92a936e2..7ce45158 100644 --- a/NadekoBot/Modules/NSFW.cs +++ b/NadekoBot/Modules/NSFW.cs @@ -47,6 +47,15 @@ namespace NadekoBot.Modules { tag = ""; await e.Send(await SearchHelper.GetGelbooruImageLink(tag)); }); + cgb.CreateCommand("~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") + .Parameter("tag", ParameterType.Unparsed) + .Do(async e => { + string tag = e.GetArg("tag"); + if (tag == null) + tag = ""; + await e.Send(await SearchHelper.GetE621ImageLink(tag)); + }); cgb.CreateCommand("~cp") .Description("We all know where this will lead you to.") .Parameter("anything", ParameterType.Unparsed)