eval/index.ts

96 lines
3.6 KiB
TypeScript
Raw Normal View History

2024-12-18 07:51:46 -05:00
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) {
2024-12-19 07:31:54 -05:00
// thank you vee
2024-12-18 07:51:46 -05:00
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, {
2024-12-23 14:45:54 -05:00
content: "```\n" + args[0].value + "\n```\n\n```js\n" + `${result}\n\n${console._lines.join("\n")}` + "\n```"
2024-12-18 07:51:46 -05:00
});
}
else {
sendBotMessage(getCurrentChannel()!.id, {
2024-12-23 14:45:54 -05:00
content: "```\n" + args[0].value + "\n```\n```js\n" + `${result}\n\n${console._lines.join("\n")}` + "\n```"
2024-12-18 07:51:46 -05:00
});
}
},
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
}]
2024-12-19 07:31:54 -05:00
}, {
name: "native-eval",
description: "Evaluate JavaScript from a NodeJS context (USE WITH EXTREME CAUTION)",
async execute(args, ctx) {
try {
var result = await VencordNative.pluginHelpers.Eval.evalCode(args[0].value);
} catch (e: any) {
var result = e;
}
if (args[1] && args[1].value) {
sendMessage(getCurrentChannel()!.id, {
2024-12-23 14:45:54 -05:00
content: "```\n" + args[0].value + "\n```\n\n```js\n" + result + "\n```"
2024-12-19 07:31:54 -05:00
});
}
else {
sendBotMessage(getCurrentChannel()!.id, {
2024-12-23 14:45:54 -05:00
content: "```\n" + args[0].value + "\n```\n\n```js\n" + result + "\n```"
2024-12-19 07:31:54 -05:00
});
}
},
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
}]
2024-12-18 07:51:46 -05:00
}]
});