const ESMCommand = require("../esm_command"); const jsUtil = require('util'); module.exports = class ESMCommand_Eval extends ESMCommand { constructor(bot) { super(bot); this.permissions = { dev_only: true }; this.commandParams = { code: { regex: /[\s\S]+/, preserve_case: true } }; } async fromDiscord() { let response = "Failed to evaluate code"; let code = this.params.code.trim(); let output = `Input:\n\`\`\`js\n${code}\`\`\``; try { response = eval(code); if (this.util.isObject(response)) { response = jsUtil.inspect(response); } if (this.util.isNull(response)) throw "<null>"; } catch (err) { response = err; } if (response.length > 1650) { output += `\nOutput:\n\`\`\`js\n${response.substring(0, 1650)}\n\`\`\``; await this.ESMBot.send(this.message.channel, output); let newResponse = response.substring(1650); for (let i = 0; i < (newResponse.length / 1650); i++) { let messageToSend = newResponse.substring(i * 1650, (i + 1) * 1650); await this.ESMBot.send(this.message.channel, `\`\`\`js\n${messageToSend}\`\`\``); } } else { output += `\nOutput:\n\`\`\`js\n${response}\n\`\`\``; this.ESMBot.send(this.message.channel, output); } } }