diff options
Diffstat (limited to 'packages/gateway/src/commands')
| -rw-r--r-- | packages/gateway/src/commands/delete.ts | 9 | ||||
| -rw-r--r-- | packages/gateway/src/commands/pin.ts | 32 | ||||
| -rw-r--r-- | packages/gateway/src/commands/react.ts | 11 | ||||
| -rw-r--r-- | packages/gateway/src/commands/say.ts | 21 |
4 files changed, 52 insertions, 21 deletions
diff --git a/packages/gateway/src/commands/delete.ts b/packages/gateway/src/commands/delete.ts index 8b36eb9..20d0881 100644 --- a/packages/gateway/src/commands/delete.ts +++ b/packages/gateway/src/commands/delete.ts @@ -1,4 +1,5 @@ import { Message } from "discord.js"; +import { replyWithCleanup } from "../utilities"; export const handleDeleteCommand = async (message: Message) => { if (message.author.bot) return; @@ -8,7 +9,10 @@ export const handleDeleteCommand = async (message: Message) => { const ownerId = application?.owner?.id; if (message.author.id !== ownerId) { - await message.reply("❌ Only the server owner can use this command."); + await replyWithCleanup( + message, + "❌ Only the server owner can use this command.", + ); return; } @@ -16,7 +20,8 @@ export const handleDeleteCommand = async (message: Message) => { const parameters = message.content.split(" ").slice(1); if (parameters.length < 1) { - await message.reply( + await replyWithCleanup( + message, "❌ Usage: `uma!delete <message_id> [channel_id]`\nExamples:\n- `uma!delete 1234567890123456789` (current channel)\n- `uma!delete 1234567890123456789 9876543210987654321` (specific channel)", ); diff --git a/packages/gateway/src/commands/pin.ts b/packages/gateway/src/commands/pin.ts index da89cf1..4980d43 100644 --- a/packages/gateway/src/commands/pin.ts +++ b/packages/gateway/src/commands/pin.ts @@ -1,4 +1,5 @@ import { Message } from "discord.js"; +import { replyWithCleanup } from "../utilities"; export const handlePinCommand = async (message: Message) => { if (message.author.bot) return; @@ -13,7 +14,7 @@ export const handlePinCommand = async (message: Message) => { const parameters = message.content.split(" "); if (parameters.length < 2) { - await message.reply("❌ Usage: `uma!pin <message_id>`"); + await replyWithCleanup(message, "❌ Usage: `uma!pin <message_id>`"); return; } @@ -24,13 +25,13 @@ export const handlePinCommand = async (message: Message) => { const targetMessage = await message.channel.messages.fetch(messageId); if (!targetMessage) { - await message.reply("❌ Message not found."); + await replyWithCleanup(message, "❌ Message not found."); return; } if (targetMessage.pinned) { - await message.reply("❌ Message is already pinned."); + await replyWithCleanup(message, "❌ Message is already pinned."); return; } @@ -40,12 +41,27 @@ export const handlePinCommand = async (message: Message) => { } catch (error) { console.error("Error pinning message:", error); - if (error instanceof Error && error.message.includes("Missing Permissions")) { - await message.reply("❌ Missing permissions to pin messages in this channel."); - } else if (error instanceof Error && error.message.includes("Maximum number of pins")) { - await message.reply("❌ Channel has reached maximum number of pinned messages (50). Unpin another message first."); + if ( + error instanceof Error && + error.message.includes("Missing Permissions") + ) { + await replyWithCleanup( + message, + "❌ Missing permissions to pin messages in this channel.", + ); + } else if ( + error instanceof Error && + error.message.includes("Maximum number of pins") + ) { + await replyWithCleanup( + message, + "❌ Channel has reached maximum number of pinned messages (50). Unpin another message first.", + ); } else { - await message.reply("❌ Failed to pin the message. Message ID may be invalid."); + await replyWithCleanup( + message, + "❌ Failed to pin the message. Message ID may be invalid.", + ); } } }; diff --git a/packages/gateway/src/commands/react.ts b/packages/gateway/src/commands/react.ts index d8a8021..84dce37 100644 --- a/packages/gateway/src/commands/react.ts +++ b/packages/gateway/src/commands/react.ts @@ -1,4 +1,5 @@ import { Message } from "discord.js"; +import { replyWithCleanup } from "../utilities"; export const handleReactCommand = async (message: Message) => { if (message.author.bot) return; @@ -10,7 +11,10 @@ export const handleReactCommand = async (message: Message) => { const parameters = message.content.split(" "); if (parameters.length < 3) { - await message.reply("Usage: `uma!react <message_id> <emoji>`"); + await replyWithCleanup( + message, + "❌ Usage: `uma!react <message_id> <emoji>`", + ); return; } @@ -22,7 +26,7 @@ export const handleReactCommand = async (message: Message) => { const targetMessage = await message.channel.messages.fetch(messageId); if (!targetMessage) { - await message.reply("Message not found."); + await replyWithCleanup(message, "❌ Message not found."); return; } @@ -30,7 +34,6 @@ export const handleReactCommand = async (message: Message) => { await targetMessage.react(emoji); } catch (error) { console.error("Error reacting to message:", error); - - await message.reply("Failed to react to the message."); + await replyWithCleanup(message, "❌ Failed to react to the message."); } }; diff --git a/packages/gateway/src/commands/say.ts b/packages/gateway/src/commands/say.ts index ec19a33..8a9ab5a 100644 --- a/packages/gateway/src/commands/say.ts +++ b/packages/gateway/src/commands/say.ts @@ -1,5 +1,6 @@ import { Message } from "discord.js"; import { GUILD_ID } from "../constants"; +import { replyWithCleanup } from "../utilities"; export const handleSayCommand = async (message: Message) => { if (message.author.bot) return; @@ -13,7 +14,8 @@ export const handleSayCommand = async (message: Message) => { const parameters = message.content.split(" ").slice(1); if (parameters.length < 2) { - await message.reply( + await replyWithCleanup( + message, "❌ Usage: `uma!say <channel_mention_or_message_id> <message>`\nExamples:\n- `uma!say #general Hello everyone!`\n- `uma!say 1234567890123456789 Thanks for the info!`", ); @@ -31,7 +33,7 @@ export const handleSayCommand = async (message: Message) => { const guild = message.client.guilds.cache.get(GUILD_ID); if (!guild) { - await message.reply("❌ Guild not found."); + await replyWithCleanup(message, "❌ Guild not found."); return; } @@ -56,12 +58,12 @@ export const handleSayCommand = async (message: Message) => { } if (!foundMessage) { - await message.reply("❌ Message not found."); + await replyWithCleanup(message, "❌ Message not found."); return; } } catch { - await message.reply("❌ Error finding message."); + await replyWithCleanup(message, "❌ Error finding message."); return; } @@ -69,7 +71,8 @@ export const handleSayCommand = async (message: Message) => { const channelMatch = firstParameter.match(/<#(\d+)>/); if (!channelMatch) { - await message.reply( + await replyWithCleanup( + message, "❌ Please mention a channel or provide a message ID. Example: `#general` or `1234567890123456789`", ); @@ -81,7 +84,10 @@ export const handleSayCommand = async (message: Message) => { targetChannel = message.client.channels.cache.get(channelId); if (!targetChannel || !targetChannel.isTextBased()) { - await message.reply("❌ Channel not found or is not a text channel."); + await replyWithCleanup( + message, + "❌ Channel not found or is not a text channel.", + ); return; } @@ -114,7 +120,8 @@ export const handleSayCommand = async (message: Message) => { console.error("Error executing say command:", error); try { - await message.reply( + await replyWithCleanup( + message, "❌ Failed to execute the say command. Please check permissions.", ); } catch (replyError) { |