From 37e986b3948a8b1010ea9f05dcc82a8e06f1eeff Mon Sep 17 00:00:00 2001 From: dragonfire535 Date: Wed, 8 Mar 2017 11:12:10 -0500 Subject: [PATCH] Added Math Command --- commands/botinfo/info.js | 2 +- commands/random/math.js | 31 +++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 commands/random/math.js diff --git a/commands/botinfo/info.js b/commands/botinfo/info.js index 73048d8f..dc9ba580 100644 --- a/commands/botinfo/info.js +++ b/commands/botinfo/info.js @@ -59,7 +59,7 @@ class InfoCommand extends commando.Command { .addField('Lib', "[discord.js](https://discord.js.org/#/) (master)", true) .addField('Modules', - "[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), [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)") + "[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), [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), [mathjs](http://mathjs.org/) (3.10.0)") .addField('Other Credit', "[Cleverbot API](https://www.cleverbot.com/api/), [Wattpad API](https://developer.wattpad.com/docs/api), [Wordnik API](http://developer.wordnik.com/docs.html), [osu! API](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link/), [Yugioh Prices API](http://docs.yugiohprices.apiary.io/#)") .addField('My Server', diff --git a/commands/random/math.js b/commands/random/math.js new file mode 100644 index 00000000..ceb12116 --- /dev/null +++ b/commands/random/math.js @@ -0,0 +1,31 @@ +const commando = require('discord.js-commando'); +const math = require('mathjs'); + +class MathCommand extends commando.Command { + constructor(Client){ + super(Client, { + name: 'math', + group: 'random', + memberName: 'math', + description: 'Does Math (;math 2 + 2)', + examples: [';math 2 + 2'] + }); + } + + 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; + } + console.log("[Command] " + message.content); + let messagecontent = message.content.split(" ").slice(1).join(" "); + try { + let solved = math.eval(messagecontent); + message.channel.sendMessage(solved).catch(error => message.channel.sendMessage(":x: Error! Invalid statment!")); + } catch(err) { + message.channel.sendMessage(":x: Error! Invalid statement!"); + } + } +} + +module.exports = MathCommand; \ No newline at end of file diff --git a/package.json b/package.json index 9b762e34..f83ce34b 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "hepburn": "^1.0.0", "imdb-api": "^2.2.1", "jimp": "^0.2.27", + "mathjs": "^3.10.0", "pirate-speak": "^1.0.1", "request-promise": "^4.1.1", "urban": "^0.3.1",