mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-06 14:20:51 +02:00
Change Urban to superagent
This commit is contained in:
+16
-19
@@ -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!');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user