var safeEval = require('safe-eval');

module.exports = (lib) => {
  lib.trigger.add({
    name: 'sandbox',
    call: /^\!js (.*)/i,
    level: 100,
    active: 1,
    func: (e) => {
      var args = e.message.match(/^\!js (.*)/i)[1];
      var context = {
        bot: lib.bot,
        e: e
      }
      try {
        var output = safeEval(args, context);
        if(typeof(output) != undefined && output !== 'undefined' && output)
          e.reply(output);
      }
      catch(err) {
        e.reply(err.message);
      }
    },
    desc: 'sandbox'
  });
};