Merge pull request #23 from cuken/master

Added Urban Dictionary Search Function
This commit is contained in:
Master Kwoth 2016-02-16 04:17:06 +01:00
commit b1ac645b1f

View File

@ -184,6 +184,35 @@ namespace NadekoBot.Modules {
} }
}); });
cgb.CreateCommand("~ud")
.Description("Searches Urban Dictionary for a word\n**Usage**:~ud Pineapple")
.Parameter("query", ParameterType.Unparsed)
.Do(async e => {
var arg = e.GetArg("query");
if (string.IsNullOrWhiteSpace(arg))
{
await e.Send("💢 Please enter a search term.");
return;
}
await e.Channel.SendIsTyping();
var res = await SearchHelper.GetResponseAsync($"https://mashape-community-urban-dictionary.p.mashape.com/define?term={Uri.EscapeUriString(arg)}",
new Tuple<string, string>[] {
new Tuple<string, string>("X-Mashape-Key", NadekoBot.creds.MashapeKey)
});
try
{
var items = JObject.Parse(res);
await e.Send($"`Term:` {items["list"][0]["word"].ToString()}\n");
await e.Send($"`Definition:` {items["list"][0]["definition"].ToString()}\n");
await e.Send($"`Link:` <{await items["list"][0]["permalink"].ToString().ShortenUrl()}>");
}
catch (Exception ex)
{
await e.Channel.SendMessage("💢 Exception: " + ex.Message);
}
});
//todo when moved from parse //todo when moved from parse
/* /*
cgb.CreateCommand("~osubind") cgb.CreateCommand("~osubind")