Added Wolfram Alpha module

This commit is contained in:
thoso 2014-02-20 00:52:42 +01:00
parent b43be1f900
commit 8f8636c509
4 changed files with 84 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,8 @@
{
"result": {
"en": "{output}"
},
"error": {
"en": "Something went wrong :( Example:'~calculate (2+2)'"
}
}

View File

@ -0,0 +1,3 @@
{
"~calculate": "~calculate [(whatever)]"
}

View File

@ -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<result.queryresult.pod.length; a++)
{
var pod = result.queryresult.pod[a];
out += pod.$.title;
out +=": ";
for(var b=0; b<pod.subpod.length; b++)
{
var subpod = pod.subpod[b];
for(var c=0; c<subpod.plaintext.length; c++)
{
var text = subpod.plaintext[c];
console.log('\t', text);
out += text;
out += " ; ";
}
}
}
event.reply(dbot.t('result',{'output':out}));
}
});
}
};
};
exports.fetch = function(dbot) {
return new wolframalpha(dbot);
};