aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/utilities/bookmark.py
diff options
context:
space:
mode:
authorGravatar Amrou Bellalouna <[email protected]>2022-12-23 17:17:27 +0100
committerGravatar shtlrs <[email protected]>2023-02-19 14:42:20 +0100
commit0c10ceb5397eafadbe09a507aa40834670514bd7 (patch)
treee2eedcf2babfb59bc0eb694590e39363ee7aa83a /bot/exts/utilities/bookmark.py
parentsync commands upon cog load (diff)
move running permission checks in a static method
Diffstat (limited to 'bot/exts/utilities/bookmark.py')
-rw-r--r--bot/exts/utilities/bookmark.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py
index c86d3474..6a00ba57 100644
--- a/bot/exts/utilities/bookmark.py
+++ b/bot/exts/utilities/bookmark.py
@@ -121,6 +121,24 @@ class Bookmark(commands.Cog):
else:
log.info(f"{member} bookmarked {target_message.jump_url} with title '{title}'")
+ @staticmethod
+ async def run_permission_check(author: discord.Member | discord.User, channel: discord.TextChannel):
+ """Check if users have the right to bookmark a message in a particular channel.
+
+ This also notifies users in case they don't have the right to.
+ """
+ permissions = channel.permissions_for(author)
+ if not permissions.read_messages:
+ log.info(f"{author} tried to bookmark a message in #{channel} but has no permissions.")
+ embed = discord.Embed(
+ title=random.choice(ERROR_REPLIES),
+ color=Colours.soft_red,
+ description="You don't have permission to view this channel.",
+ )
+ await channel.send(embed=embed)
+ return False
+ return True
+
@commands.group(name="bookmark", aliases=("bm", "pin"), invoke_without_command=True)
@commands.guild_only()
@whitelist_override(roles=(Roles.everyone,))
@@ -142,16 +160,7 @@ class Bookmark(commands.Cog):
if target_message is None:
raise commands.UserInputError(MESSAGE_NOT_FOUND_ERROR)
- # Prevent users from bookmarking a message in a channel they don't have access to
- permissions = target_message.channel.permissions_for(ctx.author)
- if not permissions.read_messages:
- log.info(f"{ctx.author} tried to bookmark a message in #{target_message.channel} but has no permissions.")
- embed = discord.Embed(
- title=random.choice(ERROR_REPLIES),
- color=Colours.soft_red,
- description="You don't have permission to view this channel.",
- )
- await ctx.send(embed=embed)
+ if not await self.run_permission_check(ctx.author, target_message.channel):
return
await self.action_bookmark(ctx.channel, ctx.author, target_message, title)