added ~hentai search by tag

This commit is contained in:
Master Kwoth 2016-01-25 11:24:58 +01:00
parent 920858a46a
commit 63bf61cdd7
2 changed files with 26 additions and 1 deletions

View File

@ -486,9 +486,10 @@ namespace NadekoBot.Modules
}); });
cgb.CreateCommand("dump") 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 => .Do(async e =>
{ {
if (NadekoBot.OwnerID != e.User.Id) return;
int i = 0; int i = 0;
int j = 0; int j = 0;
string invites = ""; string invites = "";

View File

@ -103,6 +103,27 @@ namespace NadekoBot.Modules
await e.Send("This feature is being reconstructed."); 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=\"(?<id>.*)\"");
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") cgb.CreateCommand("lmgtfy")
.Description("Google something for an idiot.") .Description("Google something for an idiot.")
.Parameter("ffs", ParameterType.Unparsed) .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 string token = "";
private AnimeResult GetAnimeQueryResultLink(string query) private AnimeResult GetAnimeQueryResultLink(string query)
{ {