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

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

@ -10,24 +10,21 @@ var _ = require('underscore')._,
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]; var subpod = pod.subpod[b];
for(var c=0; c<subpod.plaintext.length; c++) for(var c=0; c<subpod.plaintext.length; c++) {
{
var text = subpod.plaintext[c]; var text = subpod.plaintext[c];
console.log('\t', text); console.log('\t', text);
out += text; out += text;
@ -35,12 +32,11 @@ var wolframalpha = function(dbot) {
} }
} }
} }
event.reply(dbot.t('result',{'output':out})); event.reply(dbot.t('wolf_result',{'output':out}));
} }
}); });
} }
}; };
}; };
exports.fetch = function(dbot) { exports.fetch = function(dbot) {