From 49c3f8204f4b89f851be5dedf07b6fb8b7437a50 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sun, 2 Apr 2017 03:30:24 +0000 Subject: [PATCH] Change Urban to superagent --- commands/search/urban.js | 35 ++++++++++++++++------------------- package.json | 1 - 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/commands/search/urban.js b/commands/search/urban.js index 8f3d3266..fa3cb6bc 100644 --- a/commands/search/urban.js +++ b/commands/search/urban.js @@ -1,6 +1,6 @@ const commando = require('discord.js-commando'); const Discord = require('discord.js'); -const urban = require('urban'); +const request = require('superagent'); module.exports = class UrbanDictionary extends commando.Command { constructor(Client) { @@ -23,33 +23,30 @@ module.exports = class UrbanDictionary extends commando.Command { }); } - run(message, args) { + async run(message, args) { if (message.channel.type !== 'dm') { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return; } console.log(`[Command] ${message.content}`); let wordToDefine = args.word; - urban(wordToDefine).first(function(response) { - if (!response) return message.say(":x: Error! Word not found!"); - if (!response.definition) return message.say(":x: Error! Word has no definition!"); - if (!response.example) { - const embed = new Discord.RichEmbed() - .setColor(0x32a8f0) - .setAuthor('Urban Dictionary', 'http://a1.mzstatic.com/eu/r30/Purple71/v4/66/54/68/6654683f-cacd-4a55-1784-f14257f77874/icon175x175.png') - .setURL(response.permalink) - .setTitle(response.word) - .setDescription(`${response.definition.substr(0, 1900)} [Read the Rest Here!](${response.permalink})`); - return message.embed(embed); - } + try { + let response = await request + .get('http://api.urbandictionary.com/v0/define') + .query({ + term: wordToDefine + }); const embed = new Discord.RichEmbed() .setColor(0x32a8f0) .setAuthor('Urban Dictionary', 'http://a1.mzstatic.com/eu/r30/Purple71/v4/66/54/68/6654683f-cacd-4a55-1784-f14257f77874/icon175x175.png') - .setURL(response.permalink) - .setTitle(response.word) - .setDescription(`${response.definition.substr(0, 1900)} [Read the Rest Here!](${response.permalink})`) + .setURL(response.body.list[0].permalink) + .setTitle(response.body.list[0].word) + .setDescription(`${response.body.list[0].definition.substr(0, 1900)} [Read the Rest Here!](${response.body.list[0].permalink})`) .addField('**Example:**', - response.example.substr(0, 1900)); + response.body.list[0].example.substr(0, 1900)); return message.embed(embed); - }); + } + catch (err) { + return message.say(':x: Error! Word not found!'); + } } }; diff --git a/package.json b/package.json index f39d79f9..f5e5bc9e 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "roman-numeral-converter-mmxvi": "^1.0.5", "string-to-binary": "^0.1.2", "superagent": "^3.5.1", - "urban": "^0.3.1", "yahoo-weather": "^2.2.2", "zalgolize": "^1.2.4" }