commit ce27fc9be9e16cb7c4442c1aaf846aac789c0bb1 Author: nin0dev Date: Wed Dec 18 07:51:46 2024 -0500 init diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..fbc7746 --- /dev/null +++ b/index.ts @@ -0,0 +1,60 @@ +import { ApplicationCommandInputType, ApplicationCommandOptionType, ApplicationCommandType, sendBotMessage } from "@api/Commands"; +import { Devs } from "@utils/constants"; +import { getCurrentChannel, sendMessage } from "@utils/discord"; +import definePlugin from "@utils/types"; + +export default definePlugin({ + name: "Eval", + description: "Adds a / command to evaluate JavaScript on your client", + authors: [Devs.nin0dev], + commands: [{ + name: "eval", + description: "Evaluate JavaScript in your client (USE WITH EXTREME CAUTION)", + async execute(args, ctx) { + const console: any = { + _lines: [] as string[], + _log(...things: string[]) { + this._lines.push( + ...things + .join(" ") + .split("\n") + ); + } + }; + console.log = console.error = console.warn = console.info = console._log.bind(console); + + let script = args[0].value.replace(/(^`{3}(js|javascript)?|`{3}$)/g, ""); + if (script.includes("await")) script = `(async () => { ${script} })()`; + + try { + var result = await eval(script); + } catch (e: any) { + var result = e; + } + + if (args[1] && args[1].value) { + sendMessage(getCurrentChannel()!.id, { + content: "```js\n" + result + "\n```" + }); + } + else { + sendBotMessage(getCurrentChannel()!.id, { + content: "```js\n" + result + "\n```" + }); + } + }, + type: ApplicationCommandType.CHAT_INPUT, + inputType: ApplicationCommandInputType.BUILT_IN, + options: [{ + name: "code", + description: "The code to run", + required: true, + type: ApplicationCommandOptionType.STRING + }, { + name: "send", + description: "Send the output in chat (default to false)", + type: ApplicationCommandOptionType.BOOLEAN, + required: false + }] + }] +});