Huge Modification to Code

This commit is contained in:
Daniel Odendahl Jr
2017-03-21 19:20:47 +00:00
parent 65bf037068
commit d49fe32bf6
100 changed files with 1541 additions and 2049 deletions
+19 -26
View File
@@ -1,12 +1,18 @@
const commando = require('discord.js-commando');
const Discord = require('discord.js');
const request = require('request-promise');
const request = require('superagent');
const config = require('../../config.json');
class DefineCommand extends commando.Command {
module.exports = class DefineCommand extends commando.Command {
constructor(Client){
super(Client, {
name: 'define',
name: 'define',
aliases: [
'definition',
'defineword',
'dictionary',
'wordnik'
],
group: 'search',
memberName: 'define',
description: 'Defines a word. (;define Cat)',
@@ -14,36 +20,23 @@ class DefineCommand extends commando.Command {
});
}
async run(message, args) {
async run(message) {
if(message.channel.type !== 'dm') {
if(!message.channel.permissionsFor(this.client.user).hasPermission('SEND_MESSAGES')) return;
if(!message.channel.permissionsFor(this.client.user).hasPermission('READ_MESSAGES')) return;
if(!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return;
if(!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return;
}
console.log("[Command] " + message.content);
let definethis = message.content.toLowerCase().split(" ").slice(1).join("%20");
const options = {
method: 'GET',
uri: 'http://api.wordnik.com:80/v4/word.json/' + definethis + '/definitions',
qs: {
limit: 1,
includeRelated: false,
useCanonical: false,
includeTags: false,
api_key: config.wordnikkey
},
json: true
}
request(options).then(function (response) {
let defineThis = message.content.toLowerCase().split(" ").slice(1).join("%20");
request
.get('http://api.wordnik.com:80/v4/word.json/' + defineThis + '/definitions')
.query({ limit: 1, includeRelated: false, useCanonical: false, includeTags: false, api_key: config.wordnikkey })
.then(function (response) {
const embed = new Discord.RichEmbed()
.setColor(0x9797FF)
.setTitle(response[0].word)
.setDescription(response[0].text);
.setTitle(response.body[0].word)
.setDescription(response.body[0].text);
message.channel.sendEmbed(embed).catch(console.error);
}).catch(function (err) {
message.channel.send(":x: Error! Word not Found!");
});
}
}
module.exports = DefineCommand;
};