From e5df5c172c21e4c80858fb90745b127a11e07f6f Mon Sep 17 00:00:00 2001 From: John Facey Date: Fri, 17 Jun 2022 14:14:55 -0500 Subject: [PATCH] updated for UD --- commands/help.js | 1 + commands/slang.js | 17 +++++++++++++++++ libFlayer.js | 27 +++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 commands/slang.js 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