aboutsummaryrefslogtreecommitdiff
path: root/bot/src/commands
diff options
context:
space:
mode:
authorAndrew Lee <andrew@alee14.me>2025-03-20 23:10:25 -0400
committerAndrew Lee <andrew@alee14.me>2025-03-20 23:10:25 -0400
commitdc4a767772dc824c67324cacbac4897bdf6c028c (patch)
treed462808c6ba7d2184ebe76db669b3c88be680015 /bot/src/commands
parent0f55f5f52e84fd5cdedb448d408dfa3c69c5fe5f (diff)
downloadAleeBot-dc4a767772dc824c67324cacbac4897bdf6c028c.tar.gz
AleeBot-dc4a767772dc824c67324cacbac4897bdf6c028c.tar.bz2
AleeBot-dc4a767772dc824c67324cacbac4897bdf6c028c.zip
Eval is now an interaction command instead; Readme changes
Diffstat (limited to 'bot/src/commands')
-rw-r--r--bot/src/commands/eval.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/bot/src/commands/eval.js b/bot/src/commands/eval.js
new file mode 100644
index 0000000..598c7fd
--- /dev/null
+++ b/bot/src/commands/eval.js
@@ -0,0 +1,58 @@
+import { SlashCommandBuilder } from 'discord.js';
+import { inspect } from 'util';
+import { userWhitelist } from '../storage/consts.js';
+
+
+export default {
+ data: new SlashCommandBuilder()
+ .setName('eval')
+ .setDescription('Evaluates code'),
+ async execute(interaction) {
+ if (!userWhitelist.includes(interaction.user.id)) return await interaction.reply('Nope! You don\'t have permission to use this command.');
+ await interaction.reply('You have entered evaluation mode. Enter the code for AleeBot to evaluate.\nType in `exit` to exit evaluation mode.');
+
+ let evaled;
+ let remove;
+
+ const filter = (i) => i.author.id === interaction.user.id;
+
+ const collector = interaction.channel.createMessageCollector({
+ filter,
+ time: 1000 * 600
+ });
+
+ collector.on('collect', async (msg) => {
+ if (msg.content.toLowerCase() === 'exit') return collector.stop();
+
+ try {
+ remove = (text) => {
+ if (typeof(text) === 'string') {
+ return text.replace(/`/g, '`' + String.fromCharCode(8203)).replace(/@/g, '@' + String.fromCharCode(8203));
+ } else {
+ return text;
+ }
+ };
+
+ evaled = await eval(msg.content);
+
+ if (typeof evaled !== 'string') {
+ evaled = inspect(evaled);
+ }
+
+ } catch (err) {
+ return await msg.reply(`**Error:**\n\`\`\`\n${err.stack}\n\`\`\``);
+ }
+
+ try {
+ return await msg.reply(`**Output:**\n\`\`\`js\n${remove(evaled)}\n\`\`\``);
+ } catch (err) {
+ return await msg.reply(`**Error:**\n\`\`\`\n${err.stack}\n\`\`\``);
+ }
+
+ });
+
+ collector.on('end', async () => {
+ return await interaction.followUp('Exiting evaluation mode.');
+ });
+ }
+};