diff options
| author | Fuwn <[email protected]> | 2025-10-15 01:04:50 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-10-15 01:04:50 -0700 |
| commit | ac5ee441dbbf7066c27290a393df92c39d527faf (patch) | |
| tree | deb4726fa68c430df783c7ecfc2948c9dcd57f3a | |
| parent | feat(gateway:messageCreate): Refine welcome constants (diff) | |
| download | umabotdiscord-ac5ee441dbbf7066c27290a393df92c39d527faf.tar.xz umabotdiscord-ac5ee441dbbf7066c27290a393df92c39d527faf.zip | |
feat(gateway:react): Support multiple emoji at once
| -rw-r--r-- | packages/gateway/src/commands/react.ts | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/packages/gateway/src/commands/react.ts b/packages/gateway/src/commands/react.ts index 8e8e5b3..08e5822 100644 --- a/packages/gateway/src/commands/react.ts +++ b/packages/gateway/src/commands/react.ts @@ -16,7 +16,7 @@ export const handleReactCommand = async (message: Message) => { if (parameters.length < 3) { await replyWithCleanup( message, - "❌ Usage: `uma!react <message_id> <emoji>` or `uma!react <channel_id> <message_id> <emoji>`\nExamples:\n- `uma!react 1234567890123456789 👍` (current channel)\n- `uma!react #general 1234567890123456789 👍` (specific channel)\n- `uma!react 9876543210987654321 1234567890123456789 👍` (channel by ID)", + "❌ Usage: `uma!react <message_id> <emoji1> [emoji2] [emoji3] ...` or `uma!react <channel_id> <message_id> <emoji1> [emoji2] [emoji3] ...`\nExamples:\n- `uma!react 1234567890123456789 👍` (current channel)\n- `uma!react 1234567890123456789 👍 ❤️ 🎉` (multiple emojis)\n- `uma!react 1234567890123456789 🇭 🇪 🇱 🇵` (spell out word)\n- `uma!react #general 1234567890123456789 👍` (specific channel)\n- `uma!react 9876543210987654321 1234567890123456789 👍` (channel by ID)", ); return; @@ -24,7 +24,7 @@ export const handleReactCommand = async (message: Message) => { let targetChannel: any; let messageId: string; - let emoji: string; + let emojis: string[]; const channelMatch = parameters[1].match(/<#(\d+)>/); const channelIdMatch = parameters[1].match(/^\d{17,19}$/); @@ -32,7 +32,7 @@ export const handleReactCommand = async (message: Message) => { if (parameters.length < 4) { await replyWithCleanup( message, - "❌ Usage: `uma!react <channel_id> <message_id> <emoji>`", + "❌ Usage: `uma!react <channel_id> <message_id> <emoji1> [emoji2] [emoji3] ...`", ); return; @@ -41,7 +41,7 @@ export const handleReactCommand = async (message: Message) => { const channelId = channelMatch ? channelMatch[1] : parameters[1]; messageId = parameters[2]; - emoji = parameters[3]; + emojis = parameters.slice(3); try { targetChannel = await message.client.channels.fetch(channelId); @@ -56,7 +56,7 @@ export const handleReactCommand = async (message: Message) => { } else { targetChannel = message.channel; messageId = parameters[1]; - emoji = parameters[2]; + emojis = parameters.slice(2); } if (!targetChannel || !targetChannel.isTextBased()) { @@ -74,31 +74,44 @@ export const handleReactCommand = async (message: Message) => { return; } - const existingReaction = targetMessage.reactions.cache.get(emoji); - const botReacted = existingReaction?.users.cache.has( - message.client.user?.id || "", - ); - - if (botReacted) { - await targetMessage.reactions.cache - .get(emoji) - ?.users.remove(message.client.user?.id); - await replyWithCleanup( - message, - `✅ Removed reaction ${emoji} from message in ${targetChannel}`, - ); - } else { - await targetMessage.react(emoji); - await replyWithCleanup( - message, - `✅ Reacted with ${emoji} to message in ${targetChannel}`, - ); + const results: string[] = []; + const errors: string[] = []; + + for (const emoji of emojis) { + try { + const existingReaction = targetMessage.reactions.cache.get(emoji); + const botReacted = existingReaction?.users.cache.has( + message.client.user?.id || "", + ); + + if (botReacted) { + await targetMessage.reactions.cache + .get(emoji) + ?.users.remove(message.client.user?.id); + results.push(`Removed ${emoji}`); + } else { + await targetMessage.react(emoji); + results.push(`Added ${emoji}`); + } + } catch (error) { + console.error(`Error processing emoji ${emoji}:`, error); + errors.push(emoji); + } } + + let resultMessage = `✅ Processed ${emojis.length} emoji(s) in ${targetChannel}:\n`; + + if (results.length > 0) resultMessage += results.join(", ") + "\n"; + + if (errors.length > 0) + resultMessage += `❌ Failed to process: ${errors.join(", ")}`; + + await replyWithCleanup(message, resultMessage); } catch (error) { - console.error("Error toggling reaction:", error); + console.error("Error toggling reactions:", error); await replyWithCleanup( message, - "❌ Failed to toggle reaction on the message.", + "❌ Failed to toggle reactions on the message.", ); } }; |