Skip to content

Commit ff1f1d5

Browse files
committed
Release v5.15.0
2 parents 1ef4789 + 311c1e1 commit ff1f1d5

File tree

18 files changed

+651
-101
lines changed

18 files changed

+651
-101
lines changed

interactions/__init__.py

Lines changed: 65 additions & 43 deletions
Large diffs are not rendered by default.

interactions/api/events/processors/reaction_events.py

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import TYPE_CHECKING
22

33
import interactions.api.events as events
4-
from interactions.models import PartialEmoji, Reaction
4+
from interactions.models import PartialEmoji, Reaction, Message, Permissions
55

66
from ._template import EventMixinTemplate, Processor
77

@@ -12,6 +12,29 @@
1212

1313

1414
class ReactionEvents(EventMixinTemplate):
15+
async def _check_message_fetch_permissions(self, channel_id: str, guild_id: str | None) -> bool:
16+
"""
17+
Check if the bot has permissions to fetch a message in the given channel.
18+
19+
Args:
20+
channel_id: The ID of the channel to check
21+
guild_id: The ID of the guild, if any
22+
23+
Returns:
24+
bool: True if the bot has permission to fetch messages, False otherwise
25+
26+
"""
27+
if not guild_id: # DMs always have permission
28+
return True
29+
30+
channel = await self.cache.fetch_channel(channel_id)
31+
if not channel:
32+
return False
33+
34+
bot_member = channel.guild.me
35+
ctx_perms = channel.permissions_for(bot_member)
36+
return Permissions.READ_MESSAGE_HISTORY in ctx_perms
37+
1538
async def _handle_message_reaction_change(self, event: "RawGatewayEvent", add: bool) -> None:
1639
if member := event.data.get("member"):
1740
author = self.cache.place_member_data(event.data.get("guild_id"), member)
@@ -53,11 +76,27 @@ async def _handle_message_reaction_change(self, event: "RawGatewayEvent", add: b
5376
message.reactions.append(reaction)
5477

5578
else:
56-
message = await self.cache.fetch_message(event.data.get("channel_id"), event.data.get("message_id"))
57-
for r in message.reactions:
58-
if r.emoji == emoji:
59-
reaction = r
60-
break
79+
guild_id = event.data.get("guild_id")
80+
channel_id = event.data.get("channel_id")
81+
82+
if await self._check_message_fetch_permissions(channel_id, guild_id):
83+
message = await self.cache.fetch_message(channel_id, event.data.get("message_id"))
84+
for r in message.reactions:
85+
if r.emoji == emoji:
86+
reaction = r
87+
break
88+
89+
if not message: # otherwise construct skeleton message with no reactions
90+
message = Message.from_dict(
91+
{
92+
"id": event.data.get("message_id"),
93+
"channel_id": channel_id,
94+
"guild_id": guild_id,
95+
"reactions": [],
96+
},
97+
self,
98+
)
99+
61100
if add:
62101
self.dispatch(events.MessageReactionAdd(message=message, emoji=emoji, author=author, reaction=reaction))
63102
else:

interactions/client/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,8 @@ async def wait_for_component(
12161216
messages: Optional[Union[Message, int, list]] = None,
12171217
components: Optional[
12181218
Union[
1219-
List[List[Union["BaseComponent", dict]]],
1220-
List[Union["BaseComponent", dict]],
1219+
Sequence[Sequence[Union["BaseComponent", dict]]],
1220+
Sequence[Union["BaseComponent", dict]],
12211221
"BaseComponent",
12221222
dict,
12231223
]

interactions/client/smart_cache.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ async def fetch_dm_channel_id(self, user_id: "Snowflake_Type", *, force: bool =
550550
data = await self._client.http.create_dm(user_id)
551551
channel = self.place_channel_data(data)
552552
channel_id = channel.id
553+
self.place_dm_channel_id(user_id, channel_id)
553554
return channel_id
554555

555556
async def fetch_dm_channel(self, user_id: "Snowflake_Type", *, force: bool = False) -> "DM":

interactions/client/utils/deserialise_app_cmds.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def deserialize_app_cmds(data: list[dict]) -> list["InteractionCommand"]:
4141
cmd_dict["scopes"] = [cmd_dict.pop("guild_id", const.GLOBAL_SCOPE)]
4242

4343
del cmd_dict["version"]
44-
del cmd_dict["default_permission"]
44+
if hasattr(cmd_dict, "default_permission"):
45+
del cmd_dict["default_permission"]
46+
4547
cmd = command_mapping[cmd_type](**cmd_dict) # type: ignore
4648

4749
if options:

interactions/ext/paginators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Paginator:
122122
)
123123
"""The emoji to use for the next button"""
124124
last_button_emoji: Optional[Union["PartialEmoji", dict, str]] = attrs.field(
125-
repr=False, default="", metadata=export_converter(process_emoji)
125+
repr=False, default="⏭️", metadata=export_converter(process_emoji)
126126
)
127127
"""The emoji to use for the last button"""
128128
callback_button_emoji: Optional[Union["PartialEmoji", dict, str]] = attrs.field(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy