diff --git a/NadekoBot/Classes/IMDB/ImdbMovie.cs b/NadekoBot/Classes/IMDB/ImdbMovie.cs new file mode 100644 index 00000000..a1930554 --- /dev/null +++ b/NadekoBot/Classes/IMDB/ImdbMovie.cs @@ -0,0 +1,54 @@ +ο»Ώusing System.Collections; +using System.Collections.Generic; + +namespace NadekoBot.Classes.IMDB +{ + public class ImdbMovie + { + public bool status { get; set; } + public string Id { get; set; } + public string Title { get; set; } + public string OriginalTitle { get; set; } + public string Year { get; set; } + public string Rating { get; set; } + public List Genres { get; set; } + public ArrayList Directors { get; set; } + public ArrayList Writers { get; set; } + public ArrayList Cast { get; set; } + public ArrayList Producers { get; set; } + public ArrayList Musicians { get; set; } + public ArrayList Cinematographers { get; set; } + public ArrayList Editors { get; set; } + public string MpaaRating { get; set; } + public string ReleaseDate { get; set; } + public string Plot { get; set; } + public ArrayList PlotKeywords { get; set; } + public string Poster { get; set; } + public string PosterLarge { get; set; } + public string PosterFull { get; set; } + public string Runtime { get; set; } + public string Top250 { get; set; } + public string Oscars { get; set; } + public string Awards { get; set; } + public string Nominations { get; set; } + public string Storyline { get; set; } + public string Tagline { get; set; } + public string Votes { get; set; } + public ArrayList Languages { get; set; } + public ArrayList Countries { get; set; } + public Dictionary ReleaseDates { get; set; } + public ArrayList MediaImages { get; set; } + public ArrayList RecommendedTitles { get; set; } + public string ImdbURL { get; set; } + + public Dictionary Aka { get; set; } + + public string ToString + { + get + { + return ImdbURL + "\n" + OriginalTitle + " (" + Year + ") - " + Rating; + } + } + } +} \ No newline at end of file diff --git a/NadekoBot/Classes/IMDB/ImdbScraper.cs b/NadekoBot/Classes/IMDB/ImdbScraper.cs new file mode 100644 index 00000000..12ab9bf2 --- /dev/null +++ b/NadekoBot/Classes/IMDB/ImdbScraper.cs @@ -0,0 +1,232 @@ +ο»Ώusing System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Text.RegularExpressions; + +/******************************************************************************* +* Free ASP.net IMDb Scraper API for the new IMDb Template. +* Author: Abhinay Rathore +* Website: http://www.AbhinayRathore.com +* Blog: http://web3o.blogspot.com +* More Info: http://web3o.blogspot.com/2010/11/aspnetc-imdb-scraping-api.html + +* Updated By: Gergo Torcsvari +* Last Updated: Feb, 2016 +*******************************************************************************/ + + + +namespace NadekoBot.Classes.IMDB +{ + public static class ImdbScraper + { + + + + //Search Engine URLs + private static string GoogleSearch = "https://www.google.com/search?q=imdb+"; + private static string BingSearch = "http://www.bing.com/search?q=imdb+"; + private static string AskSearch = "http://www.ask.com/web?q=imdb+"; + //Constructor + public static ImdbMovie ImdbScrape(string MovieName, bool GetExtraInfo = true) + { + ImdbMovie mov = new ImdbMovie(); + string imdbUrl = getIMDbUrl(System.Uri.EscapeUriString(MovieName)); + mov.status = false; + if (!string.IsNullOrEmpty(imdbUrl)) + { + parseIMDbPage(imdbUrl, GetExtraInfo, mov); + } + + return mov; + } + + public static ImdbMovie ImdbScrapeFromId(string imdbId, bool GetExtraInfo = true) + { + ImdbMovie mov = new ImdbMovie(); + string imdbUrl = "http://www.imdb.com/title/" + imdbId + "/"; + mov.status = false; + if (!string.IsNullOrEmpty(imdbUrl)) + { + parseIMDbPage(imdbUrl, GetExtraInfo, mov); + } + + return mov; + } + + public static string GetIMDBId(string MovieName) + { + string imdbUrl = getIMDbUrl(System.Uri.EscapeUriString(MovieName)); + return match(@"http://www.imdb.com/title/(tt\d{7})", imdbUrl); + } + //Get IMDb URL from search results + private static string getIMDbUrl(string MovieName, string searchEngine = "google") + { + string url = GoogleSearch + MovieName; //default to Google search + if (searchEngine.ToLower().Equals("bing")) url = BingSearch + MovieName; + if (searchEngine.ToLower().Equals("ask")) url = AskSearch + MovieName; + string html = getUrlData(url); + ArrayList imdbUrls = matchAll(@".*?", html); + if (imdbUrls.Count > 0) + return (string)imdbUrls[0]; //return first IMDb result + else if (searchEngine.ToLower().Equals("google")) //if Google search fails + return getIMDbUrl(MovieName, "bing"); //search using Bing + else if (searchEngine.ToLower().Equals("bing")) //if Bing search fails + return getIMDbUrl(MovieName, "ask"); //search using Ask + else //search fails + return string.Empty; + } + //Parse IMDb page data + private static void parseIMDbPage(string imdbUrl, bool GetExtraInfo, ImdbMovie mov) + { + string html = getUrlData(imdbUrl + "combined"); + mov.Id = match(@"", html); + if (!string.IsNullOrEmpty(mov.Id)) + { + mov.status = true; + mov.Title = match(@"(IMDb \- )*(.*?) \(.*?", html, 2); + mov.OriginalTitle = match(@"title-extra"">(.*?)<", html); + mov.Year = match(@".*?\(.*?(\d{4}).*?\).*?", match(@"(.*?)", html)); + mov.Rating = match(@"(\d.\d)/10", html); + mov.Genres = matchAll(@"(.*?)", match(@"Genre.?:(.*?)(|See more)", html)).Cast().ToList(); ; + mov.Directors = matchAll(@"(.*?)", match(@"Directed by(.*?)", html)); + mov.Writers = matchAll(@"(.*?)", match(@"Writing credits(.*?)", html)); + mov.Producers = matchAll(@"(.*?)", match(@"Produced by(.*?)", html)); + mov.Musicians = matchAll(@"(.*?)", match(@"Original Music by(.*?)", html)); + mov.Cinematographers = matchAll(@"(.*?)", match(@"Cinematography by(.*?)", html)); + mov.Editors = matchAll(@"(.*?)", match(@"Film Editing by(.*?)", html)); + mov.Cast = matchAll(@"(.*?)", match(@"

Cast

(.*?)", html)); + mov.Plot = match(@"Plot:.*?
(.*?)((.*?)", match(@"Plot Keywords:.*?
(.*?).*?
.*?(\d{1,2} (January|February|March|April|May|June|July|August|September|October|November|December) (19|20)\d{2})", html); + mov.Runtime = match(@"Runtime:
(\d{1,4}) min[\s]*.*?
", html); + mov.Top250 = match(@"Top 250: #(\d{1,3})<", html); + mov.Oscars = match(@"Won (\d+) Oscars?\.", html); + if (string.IsNullOrEmpty(mov.Oscars) && "Won Oscar.".Equals(match(@"(Won Oscar\.)", html))) mov.Oscars = "1"; + mov.Awards = match(@"(\d{1,4}) wins", html); + mov.Nominations = match(@"(\d{1,4}) nominations", html); + mov.Tagline = match(@"Tagline:.*?
(.*?)(:
Rated (G|PG|PG-13|PG-14|R|NC-17|X) ", html); + mov.Votes = match(@">(\d+,?\d*) votes<", html); + mov.Languages = matchAll(@"(.*?)", match(@"Language.?:(.*?)(
|>.?and )", html)); + mov.Countries = matchAll(@"(.*?)", match(@"Country:(.*?)(
|>.?and )", html)); + mov.Poster = match(@"
.*?", html); + if (!string.IsNullOrEmpty(mov.Poster) && mov.Poster.IndexOf("media-imdb.com") > 0) + { + mov.Poster = Regex.Replace(mov.Poster, @"_V1.*?.jpg", "_V1._SY200.jpg"); + mov.PosterLarge = Regex.Replace(mov.Poster, @"_V1.*?.jpg", "_V1._SY500.jpg"); + mov.PosterFull = Regex.Replace(mov.Poster, @"_V1.*?.jpg", "_V1._SY0.jpg"); + } + else + { + mov.Poster = string.Empty; + mov.PosterLarge = string.Empty; + mov.PosterFull = string.Empty; + } + mov.ImdbURL = "http://www.imdb.com/title/" + mov.Id + "/"; + if (GetExtraInfo) + { + string plotHtml = getUrlData(imdbUrl + "plotsummary"); + mov.Storyline = match(@"

(.*?)(|

)", plotHtml); + getReleaseDatesAndAka(mov); + mov.MediaImages = getMediaImages(mov); + //mov.RecommendedTitles = getRecommendedTitles(mov); + } + } + } + //Get all release dates and aka-s + private static void getReleaseDatesAndAka(ImdbMovie mov) + { + Dictionary release = new Dictionary(); + string releasehtml = getUrlData("http://www.imdb.com/title/" + mov.Id + "/releaseinfo"); + foreach (string r in matchAll(@"(.*?)", match(@"\n*?(.*?)
", releasehtml))) + { + Match rd = new Regex(@"(.*?)\n*?.*?(.*?)", RegexOptions.Multiline).Match(r); + release[StripHTML(rd.Groups[1].Value.Trim())] = StripHTML(rd.Groups[2].Value.Trim()); + } + mov.ReleaseDates = release; + + Dictionary aka = new Dictionary(); + ArrayList list = matchAll(@".*?(.*?)", match(@"\n*?(.*?)
", releasehtml)); + foreach (string r in list) + { + Match rd = new Regex(@"\n*?.*?(.*?)\n*?.*?(.*?)", RegexOptions.Multiline).Match(r); + aka[StripHTML(rd.Groups[1].Value.Trim())] = StripHTML(rd.Groups[2].Value.Trim()); + } + mov.Aka = aka; + + + + } + //Get all media images + private static ArrayList getMediaImages(ImdbMovie mov) + { + ArrayList list = new ArrayList(); + string mediaurl = "http://www.imdb.com/title/" + mov.Id + "/mediaindex"; + string mediahtml = getUrlData(mediaurl); + int pagecount = matchAll(@"
", match(@"(.*?)", mediahtml)).Count; + for (int p = 1; p <= pagecount + 1; p++) + { + mediahtml = getUrlData(mediaurl + "?page=" + p); + foreach (Match m in new Regex(@"src=""(.*?)""", RegexOptions.Multiline).Matches(match(@"
(.*?)
", mediahtml))) + { + String image = m.Groups[1].Value; + list.Add(Regex.Replace(image, @"_V1\..*?.jpg", "_V1._SY0.jpg")); + } + } + return list; + } + //Get Recommended Titles + private static ArrayList getRecommendedTitles(ImdbMovie mov) + { + ArrayList list = new ArrayList(); + string recUrl = "http://www.imdb.com/widget/recommendations/_ajax/get_more_recs?specs=p13nsims%3A" + mov.Id; + string json = getUrlData(recUrl); + list = matchAll(@"title=\\""(.*?)\\""", json); + HashSet set = new HashSet(); + foreach (String rec in list) set.Add(rec); + return new ArrayList(set.ToList()); + } + /*******************************[ Helper Methods ]********************************/ + //Match single instance + private static string match(string regex, string html, int i = 1) + { + return new Regex(regex, RegexOptions.Multiline).Match(html).Groups[i].Value.Trim(); + } + //Match all instances and return as ArrayList + private static ArrayList matchAll(string regex, string html, int i = 1) + { + ArrayList list = new ArrayList(); + foreach (Match m in new Regex(regex, RegexOptions.Multiline).Matches(html)) + list.Add(m.Groups[i].Value.Trim()); + return list; + } + //Strip HTML Tags + private static string StripHTML(string inputString) + { + return Regex.Replace(inputString, @"<.*?>", string.Empty); + } + //Get URL Data + private static string getUrlData(string url) + { + WebClient client = new WebClient(); + Random r = new Random(); + //Random IP Address + //client.Headers["X-Forwarded-For"] = r.Next(0, 255) + "." + r.Next(0, 255) + "." + r.Next(0, 255) + "." + r.Next(0, 255); + //Random User-Agent + client.Headers["User-Agent"] = "Mozilla/" + r.Next(3, 5) + ".0 (Windows NT " + r.Next(3, 5) + "." + r.Next(0, 2) + "; rv:37.0) Gecko/20100101 Firefox/" + r.Next(30, 37) + "." + r.Next(0, 5); + Stream datastream = client.OpenRead(url); + StreamReader reader = new StreamReader(datastream); + StringBuilder sb = new StringBuilder(); + + //TODO: Coud be reader error must catch and drop!!! + while (!reader.EndOfStream) + sb.Append(reader.ReadLine()); + return sb.ToString(); + } + } +} \ No newline at end of file diff --git a/NadekoBot/Modules/Searches.cs b/NadekoBot/Modules/Searches.cs index 14f41cd3..9ae5f271 100644 --- a/NadekoBot/Modules/Searches.cs +++ b/NadekoBot/Modules/Searches.cs @@ -1,20 +1,24 @@ -ο»Ώusing System; +ο»Ώusing Discord.Commands; using Discord.Modules; -using System.Net; -using System.IO; -using Newtonsoft.Json.Linq; -using Discord.Commands; +using NadekoBot.Classes; +using NadekoBot.Classes.IMDB; +using NadekoBot.Commands; using NadekoBot.Extensions; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; using System.Drawing; +using System.IO; using System.Linq; -using NadekoBot.Classes; -using NadekoBot.Commands; +using System.Net; -namespace NadekoBot.Modules { - internal class Searches : DiscordModule { +namespace NadekoBot.Modules +{ + internal class Searches : DiscordModule + { private readonly Random rng; - public Searches() { + public Searches() + { commands.Add(new LoLCommands(this)); commands.Add(new StreamNotifications(this)); rng = new Random(); @@ -22,8 +26,10 @@ namespace NadekoBot.Modules { public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Searches; - public override void Install(ModuleManager manager) { - manager.CreateCommands("", cgb => { + public override void Install(ModuleManager manager) + { + manager.CreateCommands("", cgb => + { cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance); @@ -33,7 +39,8 @@ namespace NadekoBot.Modules { .Description("Shows weather data for a specified city and a country BOTH ARE REQUIRED. Weather api is very random if you make a mistake.") .Parameter("city", ParameterType.Required) .Parameter("country", ParameterType.Required) - .Do(async e => { + .Do(async e => + { var city = e.GetArg("city").Replace(" ", ""); var country = e.GetArg("country").Replace(" ", ""); var response = await SearchHelper.GetResponseStringAsync($"http://api.lawlypopzz.xyz/nadekobot/weather/?city={city}&country={country}"); @@ -51,7 +58,8 @@ $@"🌍 **Weather for** 【{obj["target"]}】 cgb.CreateCommand(Prefix + "yt") .Parameter("query", ParameterType.Unparsed) .Description("Searches youtubes and shows the first result") - .Do(async e => { + .Do(async e => + { if (!(await SearchHelper.ValidateQuery(e.Channel, e.GetArg("query")))) return; var shortUrl = await SearchHelper.ShortenUrl(await SearchHelper.FindYoutubeUrlByKeywords(e.GetArg("query"))); @@ -62,12 +70,16 @@ $@"🌍 **Weather for** 【{obj["target"]}】 .Alias(Prefix + "anime", Prefix + "aq") .Parameter("query", ParameterType.Unparsed) .Description("Queries anilist for an anime and shows the first result.") - .Do(async e => { + .Do(async e => + { if (!(await SearchHelper.ValidateQuery(e.Channel, e.GetArg("query")))) return; string result; - try { + try + { result = (await SearchHelper.GetAnimeData(e.GetArg("query"))).ToString(); - } catch { + } + catch + { await e.Channel.SendMessage("Failed to find that anime."); return; } @@ -75,16 +87,40 @@ $@"🌍 **Weather for** 【{obj["target"]}】 await e.Channel.SendMessage(result.ToString()); }); + cgb.CreateCommand(Prefix + "imdb") + .Parameter("query", ParameterType.Unparsed) + .Description("Queries imdb for movies or series, show first result.") + .Do(async e => + { + if (!(await SearchHelper.ValidateQuery(e.Channel, e.GetArg("query")))) return; + string result; + try + { + result = ImdbScraper.ImdbScrape(e.GetArg("query"), false).ToString; + } + catch + { + await e.Channel.SendMessage("Failed to find that movie."); + return; + } + + await e.Channel.SendMessage(result.ToString()); + }); + cgb.CreateCommand(Prefix + "mang") .Alias(Prefix + "manga").Alias(Prefix + "mq") .Parameter("query", ParameterType.Unparsed) .Description("Queries anilist for a manga and shows the first result.") - .Do(async e => { + .Do(async e => + { if (!(await SearchHelper.ValidateQuery(e.Channel, e.GetArg("query")))) return; string result; - try { + try + { result = (await SearchHelper.GetMangaData(e.GetArg("query"))).ToString(); - } catch { + } + catch + { await e.Channel.SendMessage("Failed to find that anime."); return; } @@ -93,7 +129,8 @@ $@"🌍 **Weather for** 【{obj["target"]}】 cgb.CreateCommand(Prefix + "randomcat") .Description("Shows a random cat image.") - .Do(async e => { + .Do(async e => + { await e.Channel.SendMessage(JObject.Parse( await SearchHelper.GetResponseStringAsync("http://www.random.cat/meow"))["file"].ToString()); }); @@ -101,14 +138,18 @@ $@"🌍 **Weather for** 【{obj["target"]}】 cgb.CreateCommand(Prefix + "i") .Description("Pulls the first image found using a search parameter. Use ~ir for different results.\n**Usage**: ~i cute kitten") .Parameter("query", ParameterType.Unparsed) - .Do(async e => { + .Do(async e => + { if (string.IsNullOrWhiteSpace(e.GetArg("query"))) return; - try { + try + { var reqString = $"https://www.googleapis.com/customsearch/v1?q={Uri.EscapeDataString(e.GetArg("query"))}&cx=018084019232060951019%3Ahs5piey28-e&num=1&searchType=image&fields=items%2Flink&key={NadekoBot.Creds.GoogleAPIKey}"; var obj = JObject.Parse(await SearchHelper.GetResponseStringAsync(reqString)); await e.Channel.SendMessage(obj["items"][0]["link"].ToString()); - } catch (Exception ex) { + } + catch (Exception ex) + { await e.Channel.SendMessage($"πŸ’’ {ex.Message}"); } }); @@ -116,21 +157,26 @@ $@"🌍 **Weather for** 【{obj["target"]}】 cgb.CreateCommand(Prefix + "ir") .Description("Pulls a random image using a search parameter.\n**Usage**: ~ir cute kitten") .Parameter("query", ParameterType.Unparsed) - .Do(async e => { + .Do(async e => + { if (string.IsNullOrWhiteSpace(e.GetArg("query"))) return; - try { + try + { var reqString = $"https://www.googleapis.com/customsearch/v1?q={Uri.EscapeDataString(e.GetArg("query"))}&cx=018084019232060951019%3Ahs5piey28-e&num=1&searchType=image&start={ rng.Next(1, 150) }&fields=items%2Flink&key={NadekoBot.Creds.GoogleAPIKey}"; var obj = JObject.Parse(await SearchHelper.GetResponseStringAsync(reqString)); await e.Channel.SendMessage(obj["items"][0]["link"].ToString()); - } catch (Exception ex) { + } + catch (Exception ex) + { await e.Channel.SendMessage($"πŸ’’ {ex.Message}"); } }); cgb.CreateCommand(Prefix + "lmgtfy") .Description("Google something for an idiot.") .Parameter("ffs", ParameterType.Unparsed) - .Do(async e => { + .Do(async e => + { if (e.GetArg("ffs") == null || e.GetArg("ffs").Length < 1) return; await e.Channel.SendMessage(await $"http://lmgtfy.com/?q={ Uri.EscapeUriString(e.GetArg("ffs").ToString()) }".ShortenUrl()); }); @@ -138,31 +184,38 @@ $@"🌍 **Weather for** 【{obj["target"]}】 cgb.CreateCommand(Prefix + "hs") .Description("Searches for a Hearthstone card and shows its image. Takes a while to complete.\n**Usage**:~hs Ysera") .Parameter("name", ParameterType.Unparsed) - .Do(async e => { + .Do(async e => + { var arg = e.GetArg("name"); - if (string.IsNullOrWhiteSpace(arg)) { + if (string.IsNullOrWhiteSpace(arg)) + { await e.Channel.SendMessage("πŸ’’ Please enter a card name to search for."); return; } await e.Channel.SendIsTyping(); var headers = new Dictionary { { "X-Mashape-Key", NadekoBot.Creds.MashapeKey } }; var res = await SearchHelper.GetResponseStringAsync($"https://omgvamp-hearthstone-v1.p.mashape.com/cards/search/{Uri.EscapeUriString(arg)}", headers); - try { + try + { var items = JArray.Parse(res); var images = new List(); if (items == null) throw new KeyNotFoundException("Cannot find a card by that name"); var cnt = 0; items.Shuffle(); - foreach (var item in items.TakeWhile(item => cnt++ < 4).Where(item => item.HasValues && item["img"] != null)) { + foreach (var item in items.TakeWhile(item => cnt++ < 4).Where(item => item.HasValues && item["img"] != null)) + { images.Add( Image.FromStream(await SearchHelper.GetResponseStreamAsync(item["img"].ToString()))); } - if (items.Count > 4) { + if (items.Count > 4) + { await e.Channel.SendMessage("⚠ Found over 4 images. Showing random 4."); } await e.Channel.SendFile(arg + ".png", (await images.MergeAsync()).ToStream(System.Drawing.Imaging.ImageFormat.Png)); - } catch (Exception ex) { + } + catch (Exception ex) + { await e.Channel.SendMessage($"πŸ’’ Error {ex.Message}"); } }); @@ -170,22 +223,30 @@ $@"🌍 **Weather for** 【{obj["target"]}】 cgb.CreateCommand(Prefix + "osu") .Description("Shows osu stats for a player.\n**Usage**:~osu Name") .Parameter("usr", ParameterType.Unparsed) - .Do(async e => { + .Do(async e => + { if (string.IsNullOrWhiteSpace(e.GetArg("usr"))) return; - using (WebClient cl = new WebClient()) { - try { + using (WebClient cl = new WebClient()) + { + try + { cl.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); cl.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.2; Win64; x64)"); cl.DownloadDataAsync(new Uri($"http://lemmmy.pw/osusig/sig.php?uname={ e.GetArg("usr") }&flagshadow&xpbar&xpbarhex&pp=2")); - cl.DownloadDataCompleted += async (s, cle) => { - try { + cl.DownloadDataCompleted += async (s, cle) => + { + try + { await e.Channel.SendFile($"{e.GetArg("usr")}.png", new MemoryStream(cle.Result)); await e.Channel.SendMessage($"`Profile Link:`https://osu.ppy.sh/u/{Uri.EscapeDataString(e.GetArg("usr"))}\n`Image provided by https://lemmmy.pw/osusig`"); - } catch { } + } + catch { } }; - } catch { + } + catch + { await e.Channel.SendMessage("πŸ’’ Failed retrieving osu signature :\\"); } } @@ -194,23 +255,28 @@ $@"🌍 **Weather for** 【{obj["target"]}】 cgb.CreateCommand(Prefix + "ud") .Description("Searches Urban Dictionary for a word.\n**Usage**:~ud Pineapple") .Parameter("query", ParameterType.Unparsed) - .Do(async e => { + .Do(async e => + { var arg = e.GetArg("query"); - if (string.IsNullOrWhiteSpace(arg)) { + if (string.IsNullOrWhiteSpace(arg)) + { await e.Channel.SendMessage("πŸ’’ Please enter a search term."); return; } await e.Channel.SendIsTyping(); var headers = new Dictionary { { "X-Mashape-Key", NadekoBot.Creds.MashapeKey } }; var res = await SearchHelper.GetResponseStringAsync($"https://mashape-community-urban-dictionary.p.mashape.com/define?term={Uri.EscapeUriString(arg)}", headers); - try { + try + { var items = JObject.Parse(res); var sb = new System.Text.StringBuilder(); sb.AppendLine($"`Term:` {items["list"][0]["word"].ToString()}"); sb.AppendLine($"`Definition:` {items["list"][0]["definition"].ToString()}"); sb.Append($"`Link:` <{await items["list"][0]["permalink"].ToString().ShortenUrl()}>"); await e.Channel.SendMessage(sb.ToString()); - } catch { + } + catch + { await e.Channel.SendMessage("πŸ’’ Failed finding a definition for that term."); } }); @@ -218,30 +284,36 @@ $@"🌍 **Weather for** 【{obj["target"]}】 cgb.CreateCommand(Prefix + "#") .Description("Searches Tagdef.com for a hashtag.\n**Usage**:~# ff") .Parameter("query", ParameterType.Unparsed) - .Do(async e => { + .Do(async e => + { var arg = e.GetArg("query"); - if (string.IsNullOrWhiteSpace(arg)) { + if (string.IsNullOrWhiteSpace(arg)) + { await e.Channel.SendMessage("πŸ’’ Please enter a search term."); return; } await e.Channel.SendIsTyping(); var headers = new Dictionary { { "X-Mashape-Key", NadekoBot.Creds.MashapeKey } }; var res = await SearchHelper.GetResponseStringAsync($"https://tagdef.p.mashape.com/one.{Uri.EscapeUriString(arg)}.json", headers); - try { + try + { var items = JObject.Parse(res); var sb = new System.Text.StringBuilder(); sb.AppendLine($"`Hashtag:` {items["defs"]["def"]["hashtag"].ToString()}"); sb.AppendLine($"`Definition:` {items["defs"]["def"]["text"].ToString()}"); sb.Append($"`Link:` <{await items["defs"]["def"]["uri"].ToString().ShortenUrl()}>"); await e.Channel.SendMessage(sb.ToString()); - } catch { + } + catch + { await e.Channel.SendMessage("πŸ’’ Failed finidng a definition for that tag."); } }); cgb.CreateCommand(Prefix + "quote") .Description("Shows a random quote.") - .Do(async e => { + .Do(async e => + { await e.Channel.SendMessage( NadekoBot.Config.Quotes[new Random().Next(0, NadekoBot.Config.Quotes.Count)].ToString()); diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index b0db5876..186da0d0 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -118,6 +118,8 @@ + +