diff options
| author | Fuwn <[email protected]> | 2025-10-06 19:44:53 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-10-06 19:44:53 -0700 |
| commit | c2db15535965aca8943f0c213a685abdd6bcf318 (patch) | |
| tree | b370169525b41607e207ef52809a95e7c89d4a84 /packages/gateway/src/commands | |
| parent | feat(gateway:randomEyesReaction): Decrease odds (diff) | |
| download | umabotdiscord-c2db15535965aca8943f0c213a685abdd6bcf318.tar.xz umabotdiscord-c2db15535965aca8943f0c213a685abdd6bcf318.zip | |
feat(gateway:react): Cross-guild support
Diffstat (limited to 'packages/gateway/src/commands')
| -rw-r--r-- | packages/gateway/src/commands/react.ts | 65 |
1 files changed, 57 insertions, 8 deletions
diff --git a/packages/gateway/src/commands/react.ts b/packages/gateway/src/commands/react.ts index 84dce37..d31cc90 100644 --- a/packages/gateway/src/commands/react.ts +++ b/packages/gateway/src/commands/react.ts @@ -6,24 +6,64 @@ export const handleReactCommand = async (message: Message) => { if (!message.content.startsWith("uma!react")) return; - if (!message.guild || message.author.id !== message.guild.ownerId) return; + const application = await message.client.application?.fetch(); + const ownerId = application?.owner?.id; + + if (message.author.id !== ownerId) return; const parameters = message.content.split(" "); if (parameters.length < 3) { await replyWithCleanup( message, - "❌ Usage: `uma!react <message_id> <emoji>`", + "❌ 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)", ); return; } - const messageId = parameters[1]; - const emoji = parameters[2]; + let targetChannel: any; + let messageId: string; + let emoji: string; + const channelMatch = parameters[1].match(/<#(\d+)>/); + const channelIdMatch = parameters[1].match(/^\d{17,19}$/); + + if (channelMatch || channelIdMatch) { + if (parameters.length < 4) { + await replyWithCleanup( + message, + "❌ Usage: `uma!react <channel_id> <message_id> <emoji>`", + ); + + return; + } + + const channelId = channelMatch ? channelMatch[1] : parameters[1]; + + messageId = parameters[2]; + emoji = parameters[3]; + + try { + targetChannel = await message.client.channels.fetch(channelId); + } catch (error) { + await replyWithCleanup(message, "❌ Channel not found or not accessible."); + + return; + } + } else { + targetChannel = message.channel; + messageId = parameters[1]; + emoji = parameters[2]; + } + + if (!targetChannel || !targetChannel.isTextBased()) { + await replyWithCleanup(message, "❌ Target channel is not a text channel."); + + return; + } try { - const targetMessage = await message.channel.messages.fetch(messageId); + const targetMessage = await targetChannel.messages.fetch(messageId); if (!targetMessage) { await replyWithCleanup(message, "❌ Message not found."); @@ -31,9 +71,18 @@ export const handleReactCommand = async (message: Message) => { return; } - await targetMessage.react(emoji); + 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}`); + } } catch (error) { - console.error("Error reacting to message:", error); - await replyWithCleanup(message, "❌ Failed to react to the message."); + console.error("Error toggling reaction:", error); + await replyWithCleanup(message, "❌ Failed to toggle reaction on the message."); } }; |