|
| 1 | +import { BOT_COLOR } from "../../config.ts"; |
| 2 | +import { |
| 3 | + ApplicationCommandOptionTypes, |
| 4 | + ApplicationCommandTypes, |
| 5 | + InteractionResponseTypes, |
| 6 | +} from "../../deps.ts"; |
| 7 | +import * as docsUtils from "../utils/docs.ts"; |
| 8 | +import { Embeds } from "../utils/embed.ts"; |
| 9 | +import { createCommand } from "./mod.ts"; |
| 10 | + |
| 11 | +const docs = docsUtils; |
| 12 | + |
| 13 | +createCommand({ |
| 14 | + name: "eval", |
| 15 | + description: "Evaluate code", |
| 16 | + type: ApplicationCommandTypes.ChatInput, |
| 17 | + scope: "Global", |
| 18 | + options: [ |
| 19 | + { |
| 20 | + name: "code", |
| 21 | + description: "Code", |
| 22 | + type: ApplicationCommandOptionTypes.String, |
| 23 | + required: true, |
| 24 | + }, |
| 25 | + ], |
| 26 | + execute: async (bot, interaction) => { |
| 27 | + if (interaction.user.id !== 709674034798788617n) { |
| 28 | + return bot.helpers.sendInteractionResponse( |
| 29 | + interaction.id, |
| 30 | + interaction.token, |
| 31 | + { |
| 32 | + type: InteractionResponseTypes.ChannelMessageWithSource, |
| 33 | + data: { |
| 34 | + flags: 1 << 6, |
| 35 | + content: "Sorry, you are not allowed to use this command", |
| 36 | + }, |
| 37 | + }, |
| 38 | + ); |
| 39 | + } |
| 40 | + const inputCode = interaction.data?.options?.find( |
| 41 | + (x) => x.name === "code", |
| 42 | + )?.value as string; |
| 43 | + try { |
| 44 | + docs; // to be used |
| 45 | + let result = eval(inputCode); |
| 46 | + if (result instanceof Promise) { |
| 47 | + result = await result; |
| 48 | + } |
| 49 | + const embed = new Embeds(bot) |
| 50 | + .setTitle("Eval") |
| 51 | + .setColor(BOT_COLOR) |
| 52 | + .addField("Output", `\`\`\`ts\n${Deno.inspect(result)}\`\`\``); |
| 53 | + return bot.helpers.sendInteractionResponse( |
| 54 | + interaction.id, |
| 55 | + interaction.token, |
| 56 | + { |
| 57 | + type: InteractionResponseTypes.ChannelMessageWithSource, |
| 58 | + data: { |
| 59 | + embeds: embed, |
| 60 | + }, |
| 61 | + }, |
| 62 | + ); |
| 63 | + } catch (error) { |
| 64 | + const embed = new Embeds(bot) |
| 65 | + .setTitle("Eval") |
| 66 | + .setColor(BOT_COLOR) |
| 67 | + .addField("Output", `\`\`\`ts\n${error}\`\`\``); |
| 68 | + return bot.helpers.sendInteractionResponse( |
| 69 | + interaction.id, |
| 70 | + interaction.token, |
| 71 | + { |
| 72 | + type: InteractionResponseTypes.ChannelMessageWithSource, |
| 73 | + data: { |
| 74 | + embeds: embed, |
| 75 | + }, |
| 76 | + }, |
| 77 | + ); |
| 78 | + } |
| 79 | + }, |
| 80 | +}); |
0 commit comments