forked from GitHub/dbot
Added Wolfram Alpha module
This commit is contained in:
parent
b43be1f900
commit
8f8636c509
25
modules/wolframalpha/README.md
Normal file
25
modules/wolframalpha/README.md
Normal 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
|
8
modules/wolframalpha/strings.json
Normal file
8
modules/wolframalpha/strings.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"result": {
|
||||||
|
"en": "{output}"
|
||||||
|
},
|
||||||
|
"error": {
|
||||||
|
"en": "Something went wrong :( Example:'~calculate (2+2)'"
|
||||||
|
}
|
||||||
|
}
|
3
modules/wolframalpha/usage.json
Normal file
3
modules/wolframalpha/usage.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"~calculate": "~calculate [(whatever)]"
|
||||||
|
}
|
48
modules/wolframalpha/wolframalpha.js
Normal file
48
modules/wolframalpha/wolframalpha.js
Normal 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);
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user