diff --git a/NadekoBot/Classes/Music/StreamRequest.cs b/NadekoBot/Classes/Music/StreamRequest.cs index c396cab1..46b671f5 100644 --- a/NadekoBot/Classes/Music/StreamRequest.cs +++ b/NadekoBot/Classes/Music/StreamRequest.cs @@ -155,7 +155,6 @@ namespace NadekoBot.Classes.Music { Console.WriteLine("Canceling buffer token"); } } catch (Exception ex) { Console.WriteLine($"Canceling buffer token failed {ex}"); } - Console.WriteLine("Waiting"); await Task.Delay(1000); } diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index 436b6dd5..d7f4a23a 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -371,6 +371,7 @@ namespace NadekoBot.Modules .Description("Sets a user for through-bot communication. Only works if server is set.**Owner only**.") .Parameter("name", ParameterType.Unparsed) .Do(async e => { + if (e.User.Id != NadekoBot.OwnerID) return; commsUser = commsServer?.FindUsers(e.GetArg("name")).FirstOrDefault(); if (commsUser != null) await e.Send("User for comms set."); @@ -382,6 +383,7 @@ namespace NadekoBot.Modules .Description("Sets a server for through-bot communication.**Owner only**.") .Parameter("server", ParameterType.Unparsed) .Do(async e => { + if (e.User.Id != NadekoBot.OwnerID) return; commsServer = client.FindServers(e.GetArg("server")).FirstOrDefault(); if (commsServer != null) await e.Send("Server for comms set."); diff --git a/NadekoBot/Modules/Searches.cs b/NadekoBot/Modules/Searches.cs index 77094f9e..7849e3f3 100644 --- a/NadekoBot/Modules/Searches.cs +++ b/NadekoBot/Modules/Searches.cs @@ -105,25 +105,33 @@ namespace NadekoBot.Modules }); cgb.CreateCommand("~hentai") - .Description("Shows a random image from danbooru with a given tag. Tag is optional but preffered.\n**Usage**: ~hentai yuri") + .Description("Shows a random NSFW hentai image from gelbooru and 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 ;("); - } + string tag = e.GetArg("tag"); + if (tag == null) + tag = ""; + await e.Send(":heart: Gelbooru: " + GetGelbooruImageLink(tag)); + await e.Send(":heart: Danbooru: " + GetDanbooruImageLink(tag)); + }); + cgb.CreateCommand("~danbooru") + .Description("Shows a random hentai image from danbooru with a given tag. Tag is optional but preffered.\n**Usage**: ~hentai yuri") + .Parameter("tag", ParameterType.Unparsed) + .Do(async e => { + string tag = e.GetArg("tag"); + if (tag == null) + tag = ""; + await e.Send(GetDanbooruImageLink(tag)); + }); + cgb.CreateCommand("~gelbooru") + .Description("Shows a random hentai image from gelbooru with a given tag. Tag is optional but preffered.\n**Usage**: ~hentai yuri") + .Parameter("tag", ParameterType.Unparsed) + .Do(async e => { + string tag = e.GetArg("tag"); + if (tag == null) + tag = ""; + await e.Send(GetGelbooruImageLink(tag)); }); - cgb.CreateCommand("lmgtfy") .Description("Google something for an idiot.") .Parameter("ffs", ParameterType.Unparsed) @@ -226,6 +234,38 @@ namespace NadekoBot.Modules return toReturn; } + public string GetDanbooruImageLink(string tag) { + try { + var rng = new Random(); + + 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.Replace(" ","_") }"); + var matches = Regex.Matches(webpage, "data-large-file-url=\"(?.*?)\""); + + return $"http://danbooru.donmai.us{ matches[rng.Next(0, matches.Count)].Groups["id"].Value }".ShortenUrl(); + } catch (Exception) { + return null; + } + } + + public string 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 webpage = MakeRequestAndGetResponse(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 }"; + webpage = MakeRequestAndGetResponse(postLink); + //now extract the image from post page + var match = Regex.Match(webpage, "\"(?http://simg4.gelbooru.com//images.*?)\""); + return match.Groups["url"].Value; + } catch (Exception) { + return null; + } + } + public static string ShortenUrl(string url) { if (NadekoBot.GoogleAPIKey == null || NadekoBot.GoogleAPIKey == "") return url;