From fb0c39b5c827fc14ae54ad19ac92bc83a029faa3 Mon Sep 17 00:00:00 2001 From: Lamp Date: Mon, 3 Jan 2022 22:26:27 -0800 Subject: [PATCH] paste my eval/exec code --- config.js | 1 - eval-exec.js | 37 +++++++++++++++++++++++++++++++++++++ main.js | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 eval-exec.js diff --git a/config.js b/config.js index f4f3503..dd466b8 100644 --- a/config.js +++ b/config.js @@ -12,7 +12,6 @@ module.exports = { }, "opID": "707359017252683896", - "opIDs": ["707359017252683896", "330499035419115522"], //TODO i dont need multiple ops anymore "guildID": testmode ? "467473467634089985" : "321819041348190249", "channels": { // includes voice channels & category channels diff --git a/eval-exec.js b/eval-exec.js new file mode 100644 index 0000000..7a46eb8 --- /dev/null +++ b/eval-exec.js @@ -0,0 +1,37 @@ + +client.on("messageCreate", async function (message) { + if (message.author.id != config.opID) return; + if (message.content.startsWith("!>")) { + with (message) { + try { + var x = await eval(message.content.substr(2).trim()); + } catch(e) { + var x = e.message; + } + } + if (typeof x == "undefined") return void await message.react(config.eval_undefined_emoji); + let t = typeof x == 'string' ? 'txt' : 'js'; + if (typeof x != 'string' && typeof x != "function") x = require('util').inspect(x, {depth: 1}); + let cb = `\`\`\`${t}\n${x}\`\`\``; + if (cb.length <= 2000) + message.channel.send(cb); + else + message.channel.send({files:[{ + attachment: Buffer.from(x), + name: `output.${t}` + }]}); + } + else if (message.content.startsWith("!$")) { + let cp = require("child_process").spawn("bash", ["-c", message.content.substr(2).trim()]); + function ondat(a) { + try { + var split = Discord.Util.splitMessage(a.toString(), {split:{char:'\n',length:2000}}); + } catch(x) { + var split = Discord.Util.splitMessage(a.toString(), {split:{char:'',length:2000}}); + } + split.forEach(message.channel.send.bind(message.channel)); + } + cp.stdout.on("data", ondat); + cp.stderr.on("data", ondat); + } +}); \ No newline at end of file diff --git a/main.js b/main.js index 936a0fa..e5bd3aa 100644 --- a/main.js +++ b/main.js @@ -33,6 +33,7 @@ dClient.login(config.DISCORD_TOKEN); dClient.once('ready', () => { console.log('Discord Client Ready'); + require('./eval-exec'); require('./mppbridger'); require('./misc'); require('./ddpbridge');