Skip to content

Commit

Permalink
Hacky fix for math module crash
Browse files Browse the repository at this point in the history
  • Loading branch information
euank committed Jun 13, 2014
1 parent f8d8ee0 commit 75195a1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions modules/onMath/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ var mathKeys = Object.keys(mathItems);
var mathSymbols = ".,*+-/()%=";

function MathScopeEval(str) {
return (new Function("with(this) { return "+str+"; }")).call(mathItems);
try {
return (new Function("with(this) { return "+str+"; }")).call(mathItems);
} catch(ex) {
return null;
}
}

function constructMathRe() {
Expand All @@ -52,6 +56,9 @@ module.exports.msg = function(text, from, reply, raw) {
return;
}
if(mathRe.test(text)) {
reply(MathScopeEval(text));
var res = MathScopeEval(text);
if(res !== null) {
reply(res);
}
}
};

0 comments on commit 75195a1

Please sign in to comment.