From cd695efbaa096c18d5b1a8448530eea2af23911a Mon Sep 17 00:00:00 2001 From: dragonfire535 Date: Fri, 3 Mar 2017 07:01:06 -0500 Subject: [PATCH] Urban Dictionary Command Added --- commands/response/urban.js | 52 ++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 commands/response/urban.js diff --git a/commands/response/urban.js b/commands/response/urban.js new file mode 100644 index 00000000..ea4f4016 --- /dev/null +++ b/commands/response/urban.js @@ -0,0 +1,52 @@ +const commando = require('discord.js-commando'); +const Discord = require('discord.js'); +const urban = require('urban'); + +class UrbanDictionary extends commando.Command { + constructor(Client){ + super(Client, { + name: 'urban', + group: 'response', + memberName: 'urban', + description: 'Searches Urban Dictionary. (;urban Cat)', + examples: [';urban Cat'] + }); + } + + async run(message, args) { + 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; + } + console.log("[Command] " + message.content); + let wordtodefine = message.content.split(" ").slice(1).join(" "); + urban(wordtodefine).first(function(json) { + if(json === undefined) { + message.reply(":x: Error! Word not found!"); + } else if(json.definition === '') { + message.reply(":x: Error! Word has no definition!"); + } else if(json.example === '') { + const embed = new Discord.RichEmbed() + .setColor(0x0000FF) + .setAuthor('Urban Dictionary', 'https://lh3.googleusercontent.com/4hpSJ4pAfwRUg-RElZ2QXNh_pV01Z96iJGT2BFuk_RRsNc-AVY7cZhbN2g1zWII9PBQ=w170', json.permalink) + .setDescription(json.word) + .addField('Definition:', + json.definition); + message.channel.sendEmbed(embed).catch(console.error); + } else { + const embed = new Discord.RichEmbed() + .setColor(0x0000FF) + .setAuthor('Urban Dictionary', 'https://lh3.googleusercontent.com/4hpSJ4pAfwRUg-RElZ2QXNh_pV01Z96iJGT2BFuk_RRsNc-AVY7cZhbN2g1zWII9PBQ=w170', json.permalink) + .setDescription(json.word) + .addField('Definition:', + json.definition) + .addField('Example:', + json.example); + message.channel.sendEmbed(embed).catch(console.error); + } + }); + } +} + +module.exports = UrbanDictionary; \ No newline at end of file diff --git a/package.json b/package.json index d8c648f4..a5e7ea0c 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "discord.js-commando": "^0.9.0", "google-translate-api": "^2.2.2", "jimp": "^0.2.27", - "pirate-speak": "^1.0.1" + "pirate-speak": "^1.0.1", + "urban": "^0.3.1" } }