Added Urban Dictionary Search Function
This commit is contained in:
parent
2851217baa
commit
ee0e450e5a
@ -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
|
||||
/*
|
||||
cgb.CreateCommand("~osubind")
|
||||
|
Loading…
Reference in New Issue
Block a user