fix command delete logic for non-commands

This commit is contained in:
bignutty 2025-02-23 12:44:05 +01:00
parent d2dcde8ee2
commit 086ef3d2f9

View file

@ -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();
})