From 35e65ea43a49992b2577cf3c763546f4f261b157 Mon Sep 17 00:00:00 2001 From: dragonfire535 Date: Sun, 5 Mar 2017 21:47:11 -0500 Subject: [PATCH] Added Define Command --- commands/botinfo/info.js | 2 +- commands/search/define.js | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 commands/search/define.js diff --git a/commands/botinfo/info.js b/commands/botinfo/info.js index d7d51432..2e0aa18f 100644 --- a/commands/botinfo/info.js +++ b/commands/botinfo/info.js @@ -61,7 +61,7 @@ class InfoCommand extends commando.Command { .addField('Packages', "[Commando](https://github.com/Gawdl3y/discord.js-commando) (0.9.0), [cleverbot-node](https://github.com/fojas/cleverbot-node) (0.3.5), [pirate-speak](https://github.com/mikewesthad/pirate-speak) (1.0.1), [JIMP](https://github.com/oliver-moran/jimp) (0.2.27), [google-translate-api](https://github.com/matheuss/google-translate-api) (2.2.2), [urban](https://github.com/mvrilo/urban) (0.3.1), [zalgoize](https://github.com/clux/zalgolize) (1.2.4), [hepburn](https://github.com/lovell/hepburn) (1.0.0), [wikifakt](https://github.com/coffee-cup/wikifakt) (1.0.3), [osu](https://github.com/IOExceptionOsu/node-osu) (1.0.1), [yahoo-weather](https://github.com/mamal72/node-yahoo-weather) (2.2.2), [imdb-api](https://github.com/worr/node-imdb-api) (2.2.1), [request-promise](https://github.com/request/request-promise) (4.1.1)") .addField('Other Credit', - "[Cleverbot API](https://www.cleverbot.com/api/), [Wattpad API](https://developer.wattpad.com/docs/api)") + "[Cleverbot API](https://www.cleverbot.com/api/), [Wattpad API](https://developer.wattpad.com/docs/api), [OwlBot Defenition API](https://owlbot.info/api/v1/dictionary/owl)") .addField('My Server', "[Click Here to Join!](https://discord.gg/fqQF8mc)") .addField('Invite Link:', diff --git a/commands/search/define.js b/commands/search/define.js new file mode 100644 index 00000000..5508e60b --- /dev/null +++ b/commands/search/define.js @@ -0,0 +1,41 @@ +const commando = require('discord.js-commando'); +const Discord = require('discord.js'); +const request = require('request-promise'); + +class DefineCommand extends commando.Command { + constructor(Client){ + super(Client, { + name: 'define', + group: 'search', + memberName: 'define', + description: 'Defines the first word in your message. (;define Cat)', + examples: [';define 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 [definethis] = message.content.toLowerCase().split(" ").slice(1); + const options = { + method: 'GET', + uri: 'https://owlbot.info/api/v1/dictionary/' + definethis + '?format=json', + json: true + } + request(options).then(function (response) { + const embed = new Discord.RichEmbed() + .setColor(0xF89C34) + .setTitle(definethis) + .setDescription(response[0].defenition) + message.channel.sendEmbed(embed).catch(console.error); + }).catch(function (err) { + message.channel.sendMessage(":x: Error! Word not Found!"); + }); + } +} + +module.exports = DefineCommand; \ No newline at end of file