From 63bf61cdd7300cc9e8dacc7583abe77d7274a280 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Mon, 25 Jan 2016 11:24:58 +0100 Subject: [PATCH] added ~hentai search by tag --- NadekoBot/Modules/Conversations.cs | 3 ++- NadekoBot/Modules/Searches.cs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/NadekoBot/Modules/Conversations.cs b/NadekoBot/Modules/Conversations.cs index 1ca42db3..73aac74b 100644 --- a/NadekoBot/Modules/Conversations.cs +++ b/NadekoBot/Modules/Conversations.cs @@ -486,9 +486,10 @@ namespace NadekoBot.Modules }); cgb.CreateCommand("dump") - .Description("Dumps all of the invites it can to dump.txt") + .Description("Dumps all of the invites it can to dump.txt.** Owner Only.**") .Do(async e => { + if (NadekoBot.OwnerID != e.User.Id) return; int i = 0; int j = 0; string invites = ""; diff --git a/NadekoBot/Modules/Searches.cs b/NadekoBot/Modules/Searches.cs index 35d84a11..815ef6ce 100644 --- a/NadekoBot/Modules/Searches.cs +++ b/NadekoBot/Modules/Searches.cs @@ -103,6 +103,27 @@ namespace NadekoBot.Modules await e.Send("This feature is being reconstructed."); }); + + cgb.CreateCommand("~hentai") + .Description("Shows a random image from danbooru with a given tag. Tag is optional but preffered.\n**Usage**: ~hentai yuri") + .Parameter("tag", ParameterType.Unparsed) + .Do(async e => { + try { + var rng = new Random(); + var tag = e.GetArg("tag"); + + if (tag == "loli") //loli doesn't work for some reason atm + tag = "flat_chest"; + + var webpage = MakeRequestAndGetResponse($"http://danbooru.donmai.us/posts?page={ rng.Next(0, 30) }&tags={ tag }"); + var matches = Regex.Matches(webpage, "data-large-file-url=\"(?.*)\""); + + await e.Send($"http://danbooru.donmai.us{ matches[rng.Next(0, matches.Count)].Groups["id"].Value }".ShortenUrl()); + } catch (Exception) { + await e.Send("Error ;("); + } + }); + cgb.CreateCommand("lmgtfy") .Description("Google something for an idiot.") .Parameter("ffs", ParameterType.Unparsed) @@ -113,6 +134,9 @@ namespace NadekoBot.Modules }); } + public static string MakeRequestAndGetResponse(string v) => + new StreamReader(((HttpWebRequest)WebRequest.Create(v)).GetResponse().GetResponseStream()).ReadToEnd(); + private string token = ""; private AnimeResult GetAnimeQueryResultLink(string query) {