From 086ef3d2f94238c9ca526be6c74fb86ffac2b14c Mon Sep 17 00:00:00 2001 From: bignutty <3515180-bignutty@users.noreply.gitlab.com> Date: Sun, 23 Feb 2025 12:44:05 +0100 Subject: [PATCH] fix command delete logic for non-commands --- labscore/client.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/labscore/client.js b/labscore/client.js index 8b5efbe..7a29beb 100644 --- a/labscore/client.js +++ b/labscore/client.js @@ -85,7 +85,7 @@ const interactionClient = new InteractionCommandClient(cluster, { useClusterClient: true }) -const { maintower, basecamp, ingest, formatErrorMessage } = require('#logging'); +const { maintower, basecamp, formatErrorMessage } = require('#logging'); const { createEmbed } = require('#utils/embed'); const { icon, highlight } = require('#utils/markdown'); @@ -119,8 +119,17 @@ commandClient.on('commandDelete', async ({context, reply}) => { if(context.message?.deleted) return reply.delete(); let hasPrefix = false; - for(const p of commandPrefixes) if(context.message.content.toLowerCase().startsWith(p)) hasPrefix = true; - if(context.message.content.startsWith(context.client.user.mention)) hasPrefix = true; + for(const p of [...commandPrefixes, context.client.user.mention]) if(context.message.content.toLowerCase().startsWith(p)) hasPrefix = true; + + // TODO: there has to be a better way to do this, see if the command + // client exposes a parser or whatever + if(hasPrefix){ + // Extract command + let command = context.message.content.toLowerCase() + for(const p of [...commandPrefixes, context.client.user.mention]) if(command.startsWith(p)) command = command.replace(p, ""); + while(command.startsWith(" ") && command.length) command = command.substring(1,command.length) + if(!context.client.commandClient.commands.map((c)=>[c.name, ...c.aliases]).flat().includes(command.split(" ")[0])) hasPrefix=false; + } if(!reply.deleted && !hasPrefix) reply.delete(); })