fix up wolframalpha

This commit is contained in:
reality 2014-02-20 20:19:44 +00:00
parent 03f2ac16b5
commit 721ed55598
4 changed files with 36 additions and 40 deletions

View File

@ -19,7 +19,7 @@ appID has to be added into config.json. It can be obtained at
http://products.wolframalpha.com/developers/ for free. http://products.wolframalpha.com/developers/ for free.
`{ `{
"ignorable": true, "ignorable": true,
"appID": "APP_ID_HERE" "api_key": "APP_ID_HERE"
}` }`
### Commands ### Commands
@ -30,4 +30,4 @@ Example:
+ ~calculate (2+2) + ~calculate (2+2)
+ ~calculate (x^2+2x+4) + ~calculate (x^2+2x+4)
### TODO ### TODO

View File

@ -1,4 +1,4 @@
{ {
"ignorable": true, "ignorable": true,
"appID": "blah" "api_key": "blah"
} }

View File

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

View File

@ -5,42 +5,38 @@
*/ */
var _ = require('underscore')._, var _ = require('underscore')._,
Client = require('node-wolfram'); Client = require('node-wolfram');
var wolframalpha = function(dbot) { var wolframalpha = function(dbot) {
this.commands = { this.commands = {
'~calculate': function(event) { '~calculate': function(event) {
var wolfram = new Client(this.config.appID); var wolfram = new Client(this.config.api_key),
var query = event.input[1]; query = event.params[1];
wolfram.query(event.input[1], function(err, result) { wolfram.query(query, function(err, result) {
if(err) if(err) {
event.reply(dbot.t('error')); event.reply(dbot.t('wolf_error'));
else console.log(err);
{ } else {
var out = ""; var out = "";
for(var a=0; a<result.queryresult.pod.length; a++) for(var a=0; a<result.queryresult.pod.length; a++) {
{ var pod = result.queryresult.pod[a];
var pod = result.queryresult.pod[a]; out += pod.$.title;
out += pod.$.title; out +=": ";
out +=": "; for(var b=0; b<pod.subpod.length; b++) {
for(var b=0; b<pod.subpod.length; b++) var subpod = pod.subpod[b];
{ for(var c=0; c<subpod.plaintext.length; c++) {
var subpod = pod.subpod[b]; var text = subpod.plaintext[c];
for(var c=0; c<subpod.plaintext.length; c++) console.log('\t', text);
{ out += text;
var text = subpod.plaintext[c]; out += " ; ";
console.log('\t', text); }
out += text; }
out += " ; "; }
} event.reply(dbot.t('wolf_result',{'output':out}));
} }
} });
event.reply(dbot.t('result',{'output':out})); }
} };
});
}
};
}; };
exports.fetch = function(dbot) { exports.fetch = function(dbot) {