dbot/modules/wolframalpha/wolframalpha.js

45 lines
1.5 KiB
JavaScript
Raw Normal View History

2014-02-20 00:52:42 +01:00
/**
* Module Name: wolframalpha
* Description: Calculates all kinds of stuff through Wolfram Alpha.
* Requires: node-wolfram [https://github.com/strax/node-wolfram]
*/
var _ = require('underscore')._,
2014-02-20 21:19:44 +01:00
Client = require('node-wolfram');
2014-02-20 00:52:42 +01:00
var wolframalpha = function(dbot) {
2014-02-20 21:19:44 +01:00
this.commands = {
'~calculate': function(event) {
var wolfram = new Client(this.config.api_key),
query = event.params[1];
wolfram.query(query, function(err, result) {
if(err) {
event.reply(dbot.t('wolf_error'));
console.log(err);
} 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('wolf_result',{'output':out}));
}
});
}
};
2014-02-20 00:52:42 +01:00
};
exports.fetch = function(dbot) {
return new wolframalpha(dbot);
};