3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-27 13:12:44 +01:00
dbot/modules/wolframalpha/wolframalpha.js

46 lines
1.6 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 = {
2014-02-20 21:42:09 +01:00
'~wr': function(event) {
2014-02-20 21:19:44 +01:00
var wolfram = new Client(this.config.api_key),
2014-02-20 21:42:59 +01:00
query = event.input[1];
2014-02-20 21:19:44 +01:00
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}));
}
});
}
};
this.commands['~wr'].regex = [/^wr (.*)/, 2];
2014-02-20 00:52:42 +01:00
};
exports.fetch = function(dbot) {
return new wolframalpha(dbot);
};