Skip to content

feat: add new reaction event #1640

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions interactions/api/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
MessageReactionAdd,
MessageReactionRemove,
MessageReactionRemoveAll,
MessageReactionRemoveEmoji,
MessageUpdate,
NewThreadCreate,
PresenceUpdate,
Expand Down Expand Up @@ -161,6 +162,7 @@
"MessageReactionAdd",
"MessageReactionRemove",
"MessageReactionRemoveAll",
"MessageReactionRemoveEmoji",
"MessageUpdate",
"ModalCompletion",
"ModalError",
Expand Down
11 changes: 11 additions & 0 deletions interactions/api/events/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async def an_event_handler(event: ChannelCreate):
"MessageReactionAdd",
"MessageReactionRemove",
"MessageReactionRemoveAll",
"MessageReactionRemoveEmoji",
"MessageUpdate",
"NewThreadCreate",
"PresenceUpdate",
Expand Down Expand Up @@ -577,6 +578,16 @@ class MessageReactionRemoveAll(GuildEvent):
"""The message that was reacted to"""


@attrs.define(eq=False, order=False, hash=False, kw_only=False)
class MessageReactionRemoveEmoji(MessageReactionRemoveAll):
"""Dispatched when all reactions of a specifc emoji are removed from a message."""

emoji: "PartialEmoji" = attrs.field(
repr=False,
)
"""The emoji that was removed"""


@attrs.define(eq=False, order=False, hash=False, kw_only=False)
class PresenceUpdate(BaseEvent):
"""A user's presence has changed."""
Expand Down
21 changes: 21 additions & 0 deletions interactions/api/events/processors/reaction_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,24 @@ async def _on_raw_message_reaction_remove_all(self, event: "RawGatewayEvent") ->
await self.cache.fetch_message(event.data["channel_id"], event.data["message_id"]),
)
)

@Processor.define()
async def _on_raw_message_reaction_remove_emoji(self, event: "RawGatewayEvent") -> None:
emoji = PartialEmoji.from_dict(event.data.get("emoji"))
message = self.cache.get_message(event.data.get("channel_id"), event.data.get("message_id"))

if message:
for i, reaction in enumerate(message.reactions):
if reaction.emoji == emoji:
message.reactions.pop(i)
break
else:
message = await self.cache.fetch_message(event.data.get("channel_id"), event.data.get("message_id"))

self.dispatch(
events.MessageReactionRemoveEmoji(
event.data.get("guild_id"),
message,
emoji,
)
)
5 changes: 5 additions & 0 deletions interactions/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@
Intents.DIRECT_MESSAGE_REACTIONS,
Intents.REACTIONS,
],
events.MessageReactionRemoveEmoji: [
Intents.GUILD_MESSAGE_REACTIONS,
Intents.DIRECT_MESSAGE_REACTIONS,
Intents.REACTIONS,
],
}


Expand Down
Loading