diff --git a/commands/help.js b/commands/help.js index 91d971d..2948f9a 100644 --- a/commands/help.js +++ b/commands/help.js @@ -16,6 +16,7 @@ module.exports = { **!random** - Selects a random article: *!random* **!random category** - Selects a random article by category: *!random sports* **!answer** - Instant Live Search: *!answer salesforce* + **!slang** - Urban Dictionary Search: *!answer slang* ` ); } diff --git a/commands/slang.js b/commands/slang.js new file mode 100644 index 0000000..e8e52b9 --- /dev/null +++ b/commands/slang.js @@ -0,0 +1,17 @@ +var libFlayer = require("../libFlayer.js"); + +module.exports = { + name: 'slang', + description: 'Slang', + async execute(message,args) { + + if (args.length < 1) { + message.reply(`Please use in !slang [question] format`); + return; + } + var question = encodeURIComponent(args.join(" ")); + + var slangData = await libFlayer.getSlang(question); + message.reply(`${slangData.definition} - ${slangData.example}`); + } +}; \ No newline at end of file diff --git a/libFlayer.js b/libFlayer.js index a6a3660..e44fd44 100644 --- a/libFlayer.js +++ b/libFlayer.js @@ -239,6 +239,33 @@ exports.getAnswer = async function (question) { return answerData; } +exports.getSlang = async function (question) { + + var answerURL = `https://api.urbandictionary.com/v0/define?term=${question}`; + console.log(answerURL); + slangData = { + definition: `No answer found try using a simpler search term`, + example: `` + } + await axios.get(answerURL) + .then(response => { + console.log(response.data.list[0]); + + slangData = { + definition: `${unescape(response.data.list[0].definition)}`, + example: `${unescape(response.data.list[0].example)}`, + thumbs_down: `${unescape(response.data.list[0].thumbs_down)}`, + thumbs_up: `${unescape(response.data.list[0].thumbs_up)}` + } + + return slangData; + }) + .catch(error => { + console.log(error); + }); + return slangData; +} + /** * getSources - Returns libFlayer feed sources * @constructor