Example #1
0
 function evalAndPrintExpression(expr, indent, suppress) {
   var context = session.view(data.current.identifiers.native);
   try {
     var result = safeEval(expr, context);
     var formatted = formatValue(result, indent);
     config.logger.log(formatted);
     config.logger.log();
   } catch (e) {
     // HACK: safeEval edits the expression to capture the result, which
     // produces really weird output when there are errors. e.g.,
     //
     //   evalmachine.<anonymous>:1
     //   SAFE_EVAL_857712=a
     //   ^
     //
     //   ReferenceError: a is not defined
     //     at evalmachine.<anonymous>:1:1
     //     at ContextifyScript.Script.runInContext (vm.js:59:29)
     //
     // We want to hide this from the user if there's an error.
     e.stack = e.stack.replace(/SAFE_EVAL_\d+=/,"");
     if (!suppress) {
       config.logger.log(e);
     } else {
       config.logger.log(formatValue(undefined))
     }
   }
 }
Example #2
0
        return got(url).then(function (res) {
            var result = {
                text: '',
                from: {
                    language: {
                        didYouMean: false,
                        iso: ''
                    },
                    text: {
                        autoCorrected: false,
                        value: '',
                        didYouMean: false
                    }
                },
                raw: ''
            };

            if (opts.raw) {
                result.raw = res.body;
            }

            var body = safeEval(res.body);
            body[0].forEach(function (obj) {
                if (obj[0]) {
                    result.text += obj[0];
                }
            });

            if (body[2] === body[8][0][0]) {
                result.from.language.iso = body[2];
            } else {
                result.from.language.didYouMean = true;
                result.from.language.iso = body[8][0][0];
            }

            if (body[7] && body[7][0]) {
                var str = body[7][0];

                str = str.replace(/<b><i>/g, '[');
                str = str.replace(/<\/i><\/b>/g, ']');

                result.from.text.value = str;

                if (body[7][5] === true) {
                    result.from.text.autoCorrected = true;
                } else {
                    result.from.text.didYouMean = true;
                }
            }

            return result;
        }).catch(function (err) {
Example #3
0
  return new Promise((resolve, reject) => {
    let result;
    try {
      result = safeEval(event.message.text);
    } catch (error) {
      result = error.toString();
    }

    console.log(`Evaluated ${event.message.text} to ${result}.`);
    resolve({
      messageText: result,
      senderId: event.sender.id
    });
  });
Example #4
0
    "eval": function(query, text) {

        try {
            var resp = safeEval(query, context.sandbox);

            if (resp!==hide)
                client.say(to,
                    typeof resp == "string" ? context.sandbox.colour("yellow", resp) :
                    typeof resp == "function" ? irc.colors.wrap('light_magenta', resp) :
                    irc.colors.wrap('light_red', resp)
                );
        }
        catch (e) {client.say(to, irc.colors.wrap('light_red', e))}

    },
Example #5
0
let evaluate = (bot, message) => {
  if (message.text.split(" ")[0].toLowerCase() === "!eval") {
    try {
      const strToEval = message.text
          .replace(/(!eval\b)/g, "")
          .replace(/&lt;/g, "<")
          .replace(/&gt;/g, ">")
          .replace(/&amp;/g, "&")
          .replace(/‘/g, "'")
          .replace(/“/g, '"'),
        response = safeEval(strToEval);

      bot.reply(message, `${response}`);
    } catch (error) {
      bot.reply(message, `${error}`);
    }
  }
};
Example #6
0
app.post('/', jsonParser, function(req, res) {
  messaging_events = req.body.entry[0].messaging;
  for (i = 0; i < messaging_events.length; i++) {
    event = req.body.entry[0].messaging[i];
    sender = event.sender.id;
    if (event.message && event.message.text) {
      text = event.message.text;
      // Handle a text message from this sender
      var evaluated;
      try {
        evaluated = safeEval(text);
      } catch (error) {
        evaluated = error.toString();
      }
      sendTextMessage(sender, evaluated);
    }
  }
  res.sendStatus(200);
});
Example #7
0
        db.get('select command from commands where name = ?', name, (e,r) => {
            if(r) {
                try {

                    var loopNuke = loopProtect(r.command);

                    var response, command = safeEval(loopNuke, context.sandbox)

                    if(typeof command == "function"){
                        response = command.call(context.sandbox, input, params, {from, to, text, message});
                    }
                    else {
                        response = command;
                    }

                    if(response!=hide) client.say(to, response);

                }
                catch (e) {client.say(to, irc.colors.wrap('light_red', e))}
            }
        })
Example #8
0
                db.get('select locked from commands where name = ?', name, (e,r) => {

                    if(r && r.locked == "true") {
                        client.say(to, irc.colors.wrap('light_red', '~' + name + ' is locked'))
                    }
                    else {
                        if (r) { // exists
                            db.run("UPDATE commands SET command = ? WHERE name = ?", [command, name]);
                        }
                        else {
                            db.run("INSERT INTO commands(name,command) VALUES (?,?)", [name, command]);
                        }

                        try {
                            var response = typeof safeEval(command, context.sandbox) + ' ~' + name + ' added';

                            client.say(to, irc.colors.wrap('light_magenta', response));
                        }
                        catch (e) {client.say(to, irc.colors.wrap('light_red', e))}
                    }

                });