From e64d1da00cc2ba718da5a4b0da141fe86a0e48d2 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Mon, 24 Jun 2024 22:56:14 +0700 Subject: [PATCH] feat(bots/discord/commands): add `eval` command --- bots/discord/src/commands/development/eval.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 bots/discord/src/commands/development/eval.ts diff --git a/bots/discord/src/commands/development/eval.ts b/bots/discord/src/commands/development/eval.ts new file mode 100644 index 0000000..f145a79 --- /dev/null +++ b/bots/discord/src/commands/development/eval.ts @@ -0,0 +1,33 @@ +import { inspect } from 'util' +import { SlashCommandBuilder } from 'discord.js' + +import { createSuccessEmbed } from '$/utils/discord/embeds' +import type { Command } from '..' + +export default { + data: new SlashCommandBuilder() + .setName('eval') + .setDescription('Evaluates something') + .addStringOption(option => option.setName('code').setDescription('The code to evaluate').setRequired(true)) + .setDMPermission(true) + .toJSON(), + + ownerOnly: true, + global: true, + + // @ts-expect-error: Needed for science + async execute(context, interaction) { + const code = interaction.options.getString('code', true) + + await interaction.reply({ + ephemeral: true, + embeds: [ + createSuccessEmbed('Evaluate', `\`\`\`js\n${code}\`\`\``).addFields({ + name: 'Result', + // biome-ignore lint/security/noGlobalEval: Deal with it + value: `\`\`\`js\n${inspect(eval(code), { depth: 1 })}\`\`\``, + }), + ], + }) + }, +} satisfies Command