init
This commit is contained in:
commit
ce27fc9be9
1 changed files with 60 additions and 0 deletions
60
index.ts
Normal file
60
index.ts
Normal file
|
@ -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
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
});
|
Loading…
Reference in a new issue