aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Amrou Bellalouna <[email protected]>2022-12-26 12:46:45 +0100
committerGravatar shtlrs <[email protected]>2023-02-19 14:42:20 +0100
commit5a7db21fc71bbcd0026d8ecd0b340c5b24163eb3 (patch)
treeef24b705afe26b506fb57b47fcb2473ccb9bce47
parentkeep style consistency when forming embeds (diff)
use existing `build_error_embed` func to construct unauthorized message
This removes the need of the `user_is_permitted_to_bookmark` func, and keeps the code cleaner & more coherent It always relis on using interaction.response to reply instead of context, which might result in a failed interaction
-rw-r--r--bot/exts/utilities/bookmark.py35
1 files changed, 11 insertions, 24 deletions
diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py
index a4778ea0..c856d80c 100644
--- a/bot/exts/utilities/bookmark.py
+++ b/bot/exts/utilities/bookmark.py
@@ -134,31 +134,14 @@ class Bookmark(commands.Cog):
else:
log.info(f"{member} bookmarked {target_message.jump_url} with title '{title}'")
- @staticmethod
- async def user_is_permitted_to_bookmark(
- author: discord.Member | discord.User,
- channel: discord.TextChannel
- ) -> bool:
- """
- 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
-
async def _bookmark_context_menu_callback(self, interaction: discord.Interaction, message: discord.Message) -> None:
"""The callback that will be invoked upon using the bookmark's context menu command."""
- if not await self.user_is_permitted_to_bookmark(interaction.user, message.channel):
+ permissions = interaction.channel.channel.permissions_for(interaction.user)
+ if not permissions.read_messages:
+ log.info(f"{interaction.user.author} tried to bookmark a message in #{interaction.channel}"
+ f"but has no permissions.")
+ embed = Bookmark.build_error_embed("You don't have permission to view this channel.")
+ await interaction.response.send_message(embed=embed)
return
title = "Bookmark"
@@ -189,7 +172,11 @@ class Bookmark(commands.Cog):
if target_message is None:
raise commands.UserInputError(MESSAGE_NOT_FOUND_ERROR)
- if not await self.user_is_permitted_to_bookmark(ctx.author, target_message.channel):
+ permissions = ctx.channel.permissions_for(ctx.author)
+ if not permissions.read_messages:
+ log.info(f"{ctx.author} tried to bookmark a message in #{ctx.channel} but has no permissions.")
+ embed = Bookmark.build_error_embed("You don't have permission to view this channel.")
+ await ctx.send(embed=embed)
return
await self.action_bookmark(ctx.channel, ctx.author, target_message, title)