Last active
January 24, 2017 23:27
-
-
Save appellation/5406eba6d4a64ae3e17222d3f62c6998 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Eval(msg, args) { | |
const input = ':arrow_right: **Input:**\n```js\n' + args.join(' ') + '\n```'; | |
return new Promise((resolve, reject) => { | |
let ev; | |
try { | |
ev = eval(args.join(' ')); | |
if(ev && ev instanceof Promise) { | |
ev.then(resolve).catch(reject); | |
return; | |
} | |
resolve(ev); | |
} catch(err) { | |
reject(err); | |
} | |
}).then(res => { | |
let out; | |
if(typeof res === 'object' && typeof res !== 'string') { | |
out = require('util').inspect(res); | |
if(typeof out == 'string' && out.length > 1900) { | |
out = res.toString(); | |
} | |
} else { | |
out = res; | |
} | |
return msg.edit(input + ':white_check_mark: **Output:**\n```js\n' + out + '\n```'); | |
}).catch(err => { | |
return msg.edit(input + ':x: **Error:**\n```js\n' + (err.message || err) + '\n```'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment