Skip to content

5.15.0 #1771

New issue

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

By clicking “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? Sign in to your account

Open
wants to merge 12 commits into
base: stable
Choose a base branch
from
Open

5.15.0 #1771

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
108 changes: 65 additions & 43 deletions interactions/__init__.py

Large diffs are not rendered by default.

51 changes: 45 additions & 6 deletions interactions/api/events/processors/reaction_events.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING

import interactions.api.events as events
from interactions.models import PartialEmoji, Reaction
from interactions.models import PartialEmoji, Reaction, Message, Permissions

from ._template import EventMixinTemplate, Processor

Expand All @@ -12,6 +12,29 @@


class ReactionEvents(EventMixinTemplate):
async def _check_message_fetch_permissions(self, channel_id: str, guild_id: str | None) -> bool:
"""
Check if the bot has permissions to fetch a message in the given channel.

Args:
channel_id: The ID of the channel to check
guild_id: The ID of the guild, if any

Returns:
bool: True if the bot has permission to fetch messages, False otherwise

"""
if not guild_id: # DMs always have permission
return True

channel = await self.cache.fetch_channel(channel_id)
if not channel:
return False

bot_member = channel.guild.me
ctx_perms = channel.permissions_for(bot_member)
return Permissions.READ_MESSAGE_HISTORY in ctx_perms

async def _handle_message_reaction_change(self, event: "RawGatewayEvent", add: bool) -> None:
if member := event.data.get("member"):
author = self.cache.place_member_data(event.data.get("guild_id"), member)
Expand Down Expand Up @@ -53,11 +76,27 @@ async def _handle_message_reaction_change(self, event: "RawGatewayEvent", add: b
message.reactions.append(reaction)

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

if await self._check_message_fetch_permissions(channel_id, guild_id):
message = await self.cache.fetch_message(channel_id, event.data.get("message_id"))
for r in message.reactions:
if r.emoji == emoji:
reaction = r
break

if not message: # otherwise construct skeleton message with no reactions
message = Message.from_dict(
{
"id": event.data.get("message_id"),
"channel_id": channel_id,
"guild_id": guild_id,
"reactions": [],
},
self,
)

if add:
self.dispatch(events.MessageReactionAdd(message=message, emoji=emoji, author=author, reaction=reaction))
else:
Expand Down
4 changes: 2 additions & 2 deletions interactions/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,8 +1216,8 @@ async def wait_for_component(
messages: Optional[Union[Message, int, list]] = None,
components: Optional[
Union[
List[List[Union["BaseComponent", dict]]],
List[Union["BaseComponent", dict]],
Sequence[Sequence[Union["BaseComponent", dict]]],
Sequence[Union["BaseComponent", dict]],
"BaseComponent",
dict,
]
Expand Down
1 change: 1 addition & 0 deletions interactions/client/smart_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ async def fetch_dm_channel_id(self, user_id: "Snowflake_Type", *, force: bool =
data = await self._client.http.create_dm(user_id)
channel = self.place_channel_data(data)
channel_id = channel.id
self.place_dm_channel_id(user_id, channel_id)
return channel_id

async def fetch_dm_channel(self, user_id: "Snowflake_Type", *, force: bool = False) -> "DM":
Expand Down
4 changes: 3 additions & 1 deletion interactions/client/utils/deserialise_app_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def deserialize_app_cmds(data: list[dict]) -> list["InteractionCommand"]:
cmd_dict["scopes"] = [cmd_dict.pop("guild_id", const.GLOBAL_SCOPE)]

del cmd_dict["version"]
del cmd_dict["default_permission"]
if hasattr(cmd_dict, "default_permission"):
del cmd_dict["default_permission"]

cmd = command_mapping[cmd_type](**cmd_dict) # type: ignore

if options:
Expand Down
2 changes: 1 addition & 1 deletion interactions/ext/paginators.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Paginator:
)
"""The emoji to use for the next button"""
last_button_emoji: Optional[Union["PartialEmoji", dict, str]] = attrs.field(
repr=False, default="", metadata=export_converter(process_emoji)
repr=False, default="⏭️", metadata=export_converter(process_emoji)
)
"""The emoji to use for the last button"""
callback_button_emoji: Optional[Union["PartialEmoji", dict, str]] = attrs.field(
Expand Down
Loading
Loading