Skip to content

Commit ed8b4f7

Browse files
committed
Edit reaction_check and wait_for_deletion to have an allowed_users and allowed_roles kwarg.
1 parent 7c4060e commit ed8b4f7

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

botcore/utils/messages.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,27 @@ def reaction_check(
2020
user: discord.abc.User,
2121
*,
2222
message_id: int,
23-
allowed_emoji: Sequence[str],
23+
allowed_emojis: Sequence[str],
2424
allowed_users: Sequence[int],
25-
mod_roles: Sequence[int],
26-
allow_mods: bool = True,
25+
allowed_roles: Sequence[int],
2726
) -> bool:
2827
"""
29-
Check if a reaction's emoji and author are allowed and the message is `message_id`.
28+
Checks if a reaction's emoji and author are allowed.
3029
31-
If the user is not allowed, remove the reaction. Ignore reactions made by the bot.
32-
If `allow_mods` is True, allow users with `mod_roles` even if they're not in `allowed_users`.
30+
A reaction's emoji is allowed when it's not by a bot, is on `message_id`, and in `allowed_emojis`.
31+
A user is allowed when their id is in `allowed_users`, or they have a role that's in `allowed_roles`.
32+
33+
If the user is not allowed, removes the reaction.
3334
"""
3435
right_reaction = (
3536
not user.bot
3637
and reaction.message.id == message_id
37-
and str(reaction.emoji) in allowed_emoji
38+
and str(reaction.emoji) in allowed_emojis
3839
)
3940
if not right_reaction:
4041
return False
4142

42-
is_moderator = (
43-
allow_mods
44-
and any(role.id in mod_roles for role in getattr(user, "roles", []))
45-
)
46-
47-
if user.id in allowed_users or is_moderator:
43+
if user.id in allowed_users or any(role.id in allowed_roles for role in getattr(user, "roles", [])):
4844
log.trace(f"Allowed reaction {reaction} by {user} on {reaction.message.id}.")
4945
return True
5046
else:
@@ -60,22 +56,21 @@ def reaction_check(
6056
async def wait_for_deletion(
6157
bot: commands.Bot,
6258
message: discord.Message,
63-
user_ids: Sequence[int],
64-
mod_roles: Sequence[int],
59+
*,
60+
allowed_users: Sequence[int],
61+
allowed_roles: Sequence[int],
6562
deletion_emojis: Sequence[str] = ("<:trashcan:675729438528503910>",),
6663
timeout: float = 60 * 5,
6764
attach_emojis: bool = True,
68-
allow_mods: bool = True
6965
) -> None:
7066
"""
71-
Wait for any of `user_ids` to react with one of the `deletion_emojis` within `timeout` seconds to delete `message`.
67+
Waits for an allowed user to react with one of the `deletion_emojis` within `timeout` seconds to delete `message`.
68+
69+
A user is defined as allowed if their id is in `allowed_users`, or they have a role that's in `allowed_roles`.
7270
7371
If `timeout` expires then reactions are cleared to indicate the option to delete has expired.
7472
75-
An `attach_emojis` bool may be specified to determine whether to attach the given
76-
`deletion_emojis` to the message in the given `context`.
77-
An `allow_mods` bool may also be specified to allow anyone with a role in `mod_roles` to delete
78-
the message.
73+
An `attach_emojis` bool may be provided to determine whether to attach the given `deletion_emojis` to the `message`.
7974
"""
8075
if message.guild is None:
8176
raise ValueError("Message must be sent on a guild")
@@ -92,9 +87,8 @@ async def wait_for_deletion(
9287
reaction_check,
9388
message_id=message.id,
9489
allowed_emoji=deletion_emojis,
95-
allowed_users=user_ids,
96-
mod_roles=mod_roles,
97-
allow_mods=allow_mods,
90+
allowed_users=allowed_users,
91+
allowed_roles=allowed_roles,
9892
)
9993

10094
try:

0 commit comments

Comments
 (0)