From 8f8636c50972c2826010e7f6242a0ceb9686d8c8 Mon Sep 17 00:00:00 2001 From: thoso Date: Thu, 20 Feb 2014 00:52:42 +0100 Subject: [PATCH] Added Wolfram Alpha module --- modules/wolframalpha/README.md | 25 +++++++++++++++ modules/wolframalpha/strings.json | 8 +++++ modules/wolframalpha/usage.json | 3 ++ modules/wolframalpha/wolframalpha.js | 48 ++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 modules/wolframalpha/README.md create mode 100644 modules/wolframalpha/strings.json create mode 100644 modules/wolframalpha/usage.json create mode 100644 modules/wolframalpha/wolframalpha.js diff --git a/modules/wolframalpha/README.md b/modules/wolframalpha/README.md new file mode 100644 index 0000000..f2acdd9 --- /dev/null +++ b/modules/wolframalpha/README.md @@ -0,0 +1,25 @@ +## Wolfram Alpha Calculator + +Calculates whatever you want. + +### Description + +This module provides a command which allows users to calculate whatever they want. + +It has following dependencies: +node-wolfram : https://github.com/strax/node-wolfram + +### appID + +appID has to be added into config.json. It can be obtained at +http://products.wolframalpha.com/developers/ for free. + +### Commands + +#### ~calculate [(whatever)] + +Example: +~calculate (2+2) +~calculate (x^2+2x+4) + +### TODO \ No newline at end of file diff --git a/modules/wolframalpha/strings.json b/modules/wolframalpha/strings.json new file mode 100644 index 0000000..2f1ab84 --- /dev/null +++ b/modules/wolframalpha/strings.json @@ -0,0 +1,8 @@ +{ + "result": { + "en": "{output}" + }, + "error": { + "en": "Something went wrong :( Example:'~calculate (2+2)'" + } +} diff --git a/modules/wolframalpha/usage.json b/modules/wolframalpha/usage.json new file mode 100644 index 0000000..b50d0fb --- /dev/null +++ b/modules/wolframalpha/usage.json @@ -0,0 +1,3 @@ +{ + "~calculate": "~calculate [(whatever)]" +} \ No newline at end of file diff --git a/modules/wolframalpha/wolframalpha.js b/modules/wolframalpha/wolframalpha.js new file mode 100644 index 0000000..ef8674e --- /dev/null +++ b/modules/wolframalpha/wolframalpha.js @@ -0,0 +1,48 @@ +/** + * Module Name: wolframalpha + * Description: Calculates all kinds of stuff through Wolfram Alpha. + * Requires: node-wolfram [https://github.com/strax/node-wolfram] + */ + +var _ = require('underscore')._, + Client = require('node-wolfram'); + +var wolframalpha = function(dbot) { + this.commands = { + '~calculate': function(event) { + var wolfram = new Client(this.config.appID); + var query = event.input[1]; + wolfram.query(event.input[1], function(err, result) { + if(err) + event.reply(dbot.t('error')); + else + { + var out = ""; + for(var a=0; a