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.
`{
"ignorable": true,
"appID": "APP_ID_HERE"
"api_key": "APP_ID_HERE"
}`
### Commands
@ -30,4 +30,4 @@ Example:
+ ~calculate (2+2)
+ ~calculate (x^2+2x+4)
### TODO
### TODO

View File

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

View File

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

View File

@ -5,42 +5,38 @@
*/
var _ = require('underscore')._,
Client = require('node-wolfram');
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}));
}
});
}
};
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}));
}
});
}
};
};
exports.fetch = function(dbot) {