summaryrefslogtreecommitdiff
path: root/packages/gateway/src/commands
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-10-01 17:54:02 -0700
committerFuwn <[email protected]>2025-10-01 17:54:02 -0700
commit4fb9f67c1ee39d7f4016bc22cf66928a388eddb1 (patch)
tree3e7cd7fc04db050bf5eab5df26adeba396d6bc22 /packages/gateway/src/commands
parentfeat(listeners:mediaModeration): Update match requirements (diff)
downloadumabotdiscord-4fb9f67c1ee39d7f4016bc22cf66928a388eddb1.tar.xz
umabotdiscord-4fb9f67c1ee39d7f4016bc22cf66928a388eddb1.zip
feat(commands:delete): Update command handling
Diffstat (limited to 'packages/gateway/src/commands')
-rw-r--r--packages/gateway/src/commands/delete.ts80
1 files changed, 46 insertions, 34 deletions
diff --git a/packages/gateway/src/commands/delete.ts b/packages/gateway/src/commands/delete.ts
index 20d0881..773e72f 100644
--- a/packages/gateway/src/commands/delete.ts
+++ b/packages/gateway/src/commands/delete.ts
@@ -22,61 +22,73 @@ export const handleDeleteCommand = async (message: Message) => {
if (parameters.length < 1) {
await replyWithCleanup(
message,
- "❌ Usage: `uma!delete <message_id> [channel_id]`\nExamples:\n- `uma!delete 1234567890123456789` (current channel)\n- `uma!delete 1234567890123456789 9876543210987654321` (specific channel)",
+ "❌ Usage: `uma!delete <message_id> [channel_id] [message_id2] [message_id3] ...`\nExamples:\n- `uma!delete 1234567890123456789` (current channel)\n- `uma!delete 9876543210987654321 1234567890123456789 1111111111111111111` (specific channel, multiple messages)",
);
return;
}
- const messageId = parameters[0];
- const channelId = parameters[1];
+ let targetChannel = null;
+ let messageIds: string[] = [];
- if (!/^\d{17,19}$/.test(messageId)) {
- await message.reply(
- "❌ Invalid message ID format. Please provide a valid Discord message ID.",
- );
-
- return;
- }
+ if (parameters.length === 1) {
+ messageIds = [parameters[0]];
+ targetChannel = message.channel;
+ } else {
+ const channelId = parameters[0];
- if (channelId && !/^\d{17,19}$/.test(channelId)) {
- await message.reply(
- "❌ Invalid channel ID format. Please provide a valid Discord channel ID.",
- );
+ messageIds = parameters.slice(1);
- return;
- }
+ if (!/^\d{17,19}$/.test(channelId)) {
+ await message.reply(
+ "❌ Invalid channel ID format. Please provide a valid Discord channel ID.",
+ );
- try {
- let targetMessage = null;
- let targetChannel = null;
+ return;
+ }
- if (channelId) {
- targetChannel = message.client.channels.cache.get(channelId);
+ targetChannel = message.client.channels.cache.get(channelId);
- if (!targetChannel || !targetChannel.isTextBased()) {
- await message.reply("❌ Channel not found or is not a text channel.");
+ if (!targetChannel || !targetChannel.isTextBased()) {
+ await message.reply("❌ Channel not found or is not a text channel.");
- return;
- }
- } else {
- targetChannel = message.channel;
+ return;
}
+ }
- try {
- targetMessage = await targetChannel.messages.fetch(messageId);
- } catch {
- await message.reply("❌ Message not found in the specified channel.");
+ for (const messageId of messageIds)
+ if (!/^\d{17,19}$/.test(messageId)) {
+ await message.reply(
+ "❌ Invalid message ID format. Please provide valid Discord message IDs.",
+ );
return;
}
- await targetMessage.delete();
+ try {
+ let deletedCount = 0;
+ let failedCount = 0;
+
+ for (const messageId of messageIds) {
+ try {
+ const targetMessage = await targetChannel.messages.fetch(messageId);
+
+ await targetMessage.delete();
+
+ deletedCount += 1;
+ } catch {
+ failedCount += 1;
+ }
+ }
+
await message.delete();
+
+ if (failedCount > 0)
+ console.warn(`Failed to delete ${failedCount} out of ${messageIds.length} messages`);
} catch (error) {
- console.error("Error deleting message:", error);
+ console.error("Error deleting messages:", error);
await message.reply(
- "❌ Failed to delete the message. Check bot permissions and try again.",
+ "❌ Failed to delete messages. Check bot permissions and try again.",
);
}
}