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,22 +184,51 @@ namespace NadekoBot.Modules {
}
});
//todo when moved from parse
/*
cgb.CreateCommand("~osubind")
.Description("Bind discord user to osu name\n**Usage**: ~osubind My osu name")
.Parameter("osu_name", ParameterType.Unparsed)
.Do(async e => {
var userName = e.GetArg("user_name");
var osuName = e.GetArg("osu_name");
var usr = e.Server.FindUsers(userName).FirstOrDefault();
if (usr == null) {
await e.Send("Cannot find that discord user.");
return;
}
});
*/
});
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")
.Description("Bind discord user to osu name\n**Usage**: ~osubind My osu name")
.Parameter("osu_name", ParameterType.Unparsed)
.Do(async e => {
var userName = e.GetArg("user_name");
var osuName = e.GetArg("osu_name");
var usr = e.Server.FindUsers(userName).FirstOrDefault();
if (usr == null) {
await e.Send("Cannot find that discord user.");
return;
}
});
*/
});
}
}
}