From a33806f15b90d6a766e01155de772ae87cf6b6d2 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Fri, 23 Dec 2022 16:18:18 +0100 Subject: sync commands upon cog load --- bot/exts/utilities/bookmark.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 138284c2..c86d3474 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -72,6 +72,10 @@ class Bookmark(commands.Cog): def __init__(self, bot: Bot): self.bot = bot + async def cog_load(self) -> None: + """Carry out cog asynchronous initialisation.""" + await self.bot.tree.sync() + @staticmethod def build_bookmark_dm(target_message: discord.Message, title: str) -> discord.Embed: """Build the embed to DM the bookmark requester.""" -- cgit v1.2.3 From 0c10ceb5397eafadbe09a507aa40834670514bd7 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Fri, 23 Dec 2022 17:17:27 +0100 Subject: move running permission checks in a static method --- bot/exts/utilities/bookmark.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'bot') 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) -- cgit v1.2.3 From 7c711ece4168bddb6e491bc268ac3603ab6c7c07 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Fri, 23 Dec 2022 17:18:26 +0100 Subject: delegate building bm embed --- bot/exts/utilities/bookmark.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 6a00ba57..f0aa26de 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -76,6 +76,16 @@ class Bookmark(commands.Cog): """Carry out cog asynchronous initialisation.""" await self.bot.tree.sync() + @staticmethod + def build_bookmark_embed(target_message: discord.Message): + return discord.Embed( + description=( + f"Click the button to be sent your very own bookmark to " + f"[this message]({target_message.jump_url})." + ), + colour=Colours.soft_green, + ) + @staticmethod def build_bookmark_dm(target_message: discord.Message, title: str) -> discord.Embed: """Build the embed to DM the bookmark requester.""" @@ -166,14 +176,8 @@ class Bookmark(commands.Cog): await self.action_bookmark(ctx.channel, ctx.author, target_message, title) view = SendBookmark(self.action_bookmark, ctx.author, ctx.channel, target_message, title) + embed = self.build_bookmark_embed(target_message) - embed = discord.Embed( - description=( - f"Click the button to be sent your very own bookmark to " - f"[this message]({target_message.jump_url})." - ), - colour=Colours.soft_green, - ) await ctx.send(embed=embed, view=view) @bookmark.command(name="delete", aliases=("del", "rm"), root_aliases=("unbm", "unbookmark", "dmdelete", "dmdel")) -- cgit v1.2.3 From ff9085fba34aa4d0331bb8ad39c740848a173957 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Fri, 23 Dec 2022 17:19:06 +0100 Subject: add bm context menu --- bot/exts/utilities/bookmark.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index f0aa26de..6ceeb333 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -71,6 +71,11 @@ class Bookmark(commands.Cog): def __init__(self, bot: Bot): self.bot = bot + self.book_mark_context_menu = discord.app_commands.ContextMenu( + name="Bookmark", + callback=self.book_mark_context_menu_callback + ) + self.bot.tree.add_command(self.book_mark_context_menu) async def cog_load(self) -> None: """Carry out cog asynchronous initialisation.""" @@ -149,6 +154,18 @@ class Bookmark(commands.Cog): return False return True + async def book_mark_context_menu_callback(self, interaction: discord.Interaction, message: discord.Message): + if not await self.run_permission_check(interaction.user, message.channel): + return + + title = "Bookmark" + await self.action_bookmark(message.channel, interaction.user, message, title) + + view = SendBookmark(self.action_bookmark, interaction.user, message.channel, message, title) + embed = self.build_bookmark_embed(message) + await interaction.response.send_message(embed=embed, view=view, ephemeral=True) + + @commands.group(name="bookmark", aliases=("bm", "pin"), invoke_without_command=True) @commands.guild_only() @whitelist_override(roles=(Roles.everyone,)) -- cgit v1.2.3 From 701018a93d768a255ddda0422d137630210adf26 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Fri, 23 Dec 2022 17:24:20 +0100 Subject: appease linter --- bot/exts/utilities/bookmark.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 6ceeb333..69eb1d49 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -82,7 +82,8 @@ class Bookmark(commands.Cog): await self.bot.tree.sync() @staticmethod - def build_bookmark_embed(target_message: discord.Message): + def build_bookmark_embed(target_message: discord.Message) -> discord.Embed: + """Build the channel embed to the bookmark requester.""" return discord.Embed( description=( f"Click the button to be sent your very own bookmark to " @@ -137,8 +138,9 @@ class Bookmark(commands.Cog): 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. + async def run_permission_check(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. """ @@ -154,7 +156,8 @@ class Bookmark(commands.Cog): return False return True - async def book_mark_context_menu_callback(self, interaction: discord.Interaction, message: discord.Message): + async def book_mark_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.run_permission_check(interaction.user, message.channel): return @@ -165,7 +168,6 @@ class Bookmark(commands.Cog): embed = self.build_bookmark_embed(message) await interaction.response.send_message(embed=embed, view=view, ephemeral=True) - @commands.group(name="bookmark", aliases=("bm", "pin"), invoke_without_command=True) @commands.guild_only() @whitelist_override(roles=(Roles.everyone,)) -- cgit v1.2.3 From 409209b9169c619dc96b21b05f68e6bfa3bc9fac Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Fri, 23 Dec 2022 17:34:52 +0100 Subject: rename run_permission_check to user_is_permitted_to_bookmark --- bot/exts/utilities/bookmark.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 69eb1d49..4a6e4d0c 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -138,7 +138,10 @@ class Bookmark(commands.Cog): 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) -> bool: + 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. @@ -158,7 +161,7 @@ class Bookmark(commands.Cog): async def book_mark_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.run_permission_check(interaction.user, message.channel): + if not await self.user_is_permitted_to_bookmark(interaction.user, message.channel): return title = "Bookmark" @@ -189,7 +192,7 @@ class Bookmark(commands.Cog): if target_message is None: raise commands.UserInputError(MESSAGE_NOT_FOUND_ERROR) - if not await self.run_permission_check(ctx.author, target_message.channel): + if not await self.user_is_permitted_to_bookmark(ctx.author, target_message.channel): return await self.action_bookmark(ctx.channel, ctx.author, target_message, title) -- cgit v1.2.3 From cab71fbcdfe140f9821d6d373ce75856eb2bbf88 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Fri, 23 Dec 2022 17:35:53 +0100 Subject: make bookmark_context_menu_callback protected --- bot/exts/utilities/bookmark.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 4a6e4d0c..23c84fe2 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -73,7 +73,7 @@ class Bookmark(commands.Cog): self.bot = bot self.book_mark_context_menu = discord.app_commands.ContextMenu( name="Bookmark", - callback=self.book_mark_context_menu_callback + callback=self._bookmark_context_menu_callback ) self.bot.tree.add_command(self.book_mark_context_menu) @@ -159,7 +159,7 @@ class Bookmark(commands.Cog): return False return True - async def book_mark_context_menu_callback(self, interaction: discord.Interaction, message: discord.Message) -> None: + 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): return -- cgit v1.2.3 From 89973f8878c0bdc2d13e6c4a9bfa61440dde0215 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Mon, 26 Dec 2022 12:38:25 +0100 Subject: keep style consistency when forming embeds --- bot/exts/utilities/bookmark.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 23c84fe2..a4778ea0 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -77,20 +77,17 @@ class Bookmark(commands.Cog): ) self.bot.tree.add_command(self.book_mark_context_menu) - async def cog_load(self) -> None: - """Carry out cog asynchronous initialisation.""" - await self.bot.tree.sync() - @staticmethod def build_bookmark_embed(target_message: discord.Message) -> discord.Embed: """Build the channel embed to the bookmark requester.""" - return discord.Embed( + embed = discord.Embed( description=( f"Click the button to be sent your very own bookmark to " f"[this message]({target_message.jump_url})." ), colour=Colours.soft_green, ) + return embed @staticmethod def build_bookmark_dm(target_message: discord.Message, title: str) -> discord.Embed: -- cgit v1.2.3 From 5a7db21fc71bbcd0026d8ecd0b340c5b24163eb3 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Mon, 26 Dec 2022 12:46:45 +0100 Subject: 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 --- bot/exts/utilities/bookmark.py | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'bot') 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) -- cgit v1.2.3 From 74e2ba8b3f661cd09a072877cc8ec017c24098d7 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Mon, 26 Dec 2022 13:04:18 +0100 Subject: fix `AttributeError` on interaction.channel This bus was introduced upon refactoring the perms check, and it calls channel from within a channel. --- bot/exts/utilities/bookmark.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index c856d80c..47db9a0b 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -136,7 +136,7 @@ class Bookmark(commands.Cog): 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.""" - permissions = interaction.channel.channel.permissions_for(interaction.user) + permissions = interaction.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.") -- cgit v1.2.3 From 2794ed8af347e556277ecf80b7b1eef4332cb03f Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Mon, 26 Dec 2022 13:05:47 +0100 Subject: fix `AttributeError` on interaction.user This bus was introduced upon refactoring the perms check. It tries to access an author property from within a user, which doesn't exist. --- bot/exts/utilities/bookmark.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 47db9a0b..aa809014 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -138,7 +138,7 @@ class Bookmark(commands.Cog): """The callback that will be invoked upon using the bookmark's context menu command.""" permissions = interaction.channel.permissions_for(interaction.user) if not permissions.read_messages: - log.info(f"{interaction.user.author} tried to bookmark a message in #{interaction.channel}" + log.info(f"{interaction.user} 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) -- cgit v1.2.3 From accd319b2724bed430cc964bd2c9643768ba5017 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Tue, 27 Dec 2022 11:07:30 +0100 Subject: add a bookmark selection form This prompts the user for a custom title for their input. This has been added to not lose the functionality of adding a custom title for a bookmark for those who need it. --- bot/exts/utilities/bookmark.py | 45 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index aa809014..57ac267f 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -23,6 +23,40 @@ MESSAGE_NOT_FOUND_ERROR = ( ) +class BookmarkTitleSelectionForm(discord.ui.Modal): + """ + The form where a user can fill in a custom title for their bookmark & submit it. + + This form is only available when the command is invoked from a context menu. + """ + + def __init__( + self, + message: discord.Message, + action_bookmark_function: Callable[[discord.TextChannel, discord.Member, discord.Message, str], None], + ): + super().__init__(timeout=1000, title="Name your bookmark") + self.message = message + self.action_bookmark = action_bookmark_function + + bookmark_title = discord.ui.TextInput( + label="Choose a title for you bookmark", + placeholder="Type your bookmark title here", + default="Bookmark", + max_length=50, + min_length=0, + required=False + ) + + async def on_submit(self, interaction: discord.Interaction) -> None: + """Sends the bookmark embed to the user with the newly chosen title.""" + title = self.bookmark_title.value or self.bookmark_title.default + await self.action_bookmark(interaction.channel, interaction.user, self.message, title) + view = SendBookmark(self.action_bookmark, interaction.user, interaction.channel, self.message, title) + embed = Bookmark.build_bookmark_embed(self.message) + await interaction.response.send_message(embed=embed, view=view, ephemeral=True) + + class LinkTargetMessage(discord.ui.View): """The button that relays the user to the bookmarked message.""" @@ -144,12 +178,11 @@ class Bookmark(commands.Cog): await interaction.response.send_message(embed=embed) return - title = "Bookmark" - await self.action_bookmark(message.channel, interaction.user, message, title) - - view = SendBookmark(self.action_bookmark, interaction.user, message.channel, message, title) - embed = self.build_bookmark_embed(message) - await interaction.response.send_message(embed=embed, view=view, ephemeral=True) + bookmark_title_form = BookmarkTitleSelectionForm( + message=message, + action_bookmark_function=self.action_bookmark + ) + await interaction.response.send_modal(bookmark_title_form) @commands.group(name="bookmark", aliases=("bm", "pin"), invoke_without_command=True) @commands.guild_only() -- cgit v1.2.3 From cdb3ed5b015aa012eeb377d67e3ea81728450c5d Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Tue, 27 Dec 2022 11:23:26 +0100 Subject: return embed directly from build_bookmark_embed --- bot/exts/utilities/bookmark.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 57ac267f..75317708 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -114,14 +114,13 @@ class Bookmark(commands.Cog): @staticmethod def build_bookmark_embed(target_message: discord.Message) -> discord.Embed: """Build the channel embed to the bookmark requester.""" - embed = discord.Embed( + return discord.Embed( description=( f"Click the button to be sent your very own bookmark to " f"[this message]({target_message.jump_url})." ), colour=Colours.soft_green, ) - return embed @staticmethod def build_bookmark_dm(target_message: discord.Message, title: str) -> discord.Embed: -- cgit v1.2.3 From 09476fdce4a894162bd84d3d7dbd6a5f2b82bb28 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Wed, 28 Dec 2022 09:07:31 +0100 Subject: move class var before ctor --- bot/exts/utilities/bookmark.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 75317708..c67d1baf 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -30,15 +30,6 @@ class BookmarkTitleSelectionForm(discord.ui.Modal): This form is only available when the command is invoked from a context menu. """ - def __init__( - self, - message: discord.Message, - action_bookmark_function: Callable[[discord.TextChannel, discord.Member, discord.Message, str], None], - ): - super().__init__(timeout=1000, title="Name your bookmark") - self.message = message - self.action_bookmark = action_bookmark_function - bookmark_title = discord.ui.TextInput( label="Choose a title for you bookmark", placeholder="Type your bookmark title here", @@ -48,6 +39,15 @@ class BookmarkTitleSelectionForm(discord.ui.Modal): required=False ) + def __init__( + self, + message: discord.Message, + action_bookmark_function: Callable[[discord.TextChannel, discord.Member, discord.Message, str], None], + ): + super().__init__(timeout=1000, title="Name your bookmark") + self.message = message + self.action_bookmark = action_bookmark_function + async def on_submit(self, interaction: discord.Interaction) -> None: """Sends the bookmark embed to the user with the newly chosen title.""" title = self.bookmark_title.value or self.bookmark_title.default -- cgit v1.2.3 From a9bc84985291c04e006837eea67564b9cbc07d67 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Wed, 28 Dec 2022 09:11:09 +0100 Subject: mark label as optional --- bot/exts/utilities/bookmark.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index c67d1baf..ee5d8645 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -31,7 +31,7 @@ class BookmarkTitleSelectionForm(discord.ui.Modal): """ bookmark_title = discord.ui.TextInput( - label="Choose a title for you bookmark", + label="Choose a title for you bookmark (optional)", placeholder="Type your bookmark title here", default="Bookmark", max_length=50, -- cgit v1.2.3 From d6183d739a67e3baa0404f9096325763d73dfbff Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Sat, 14 Jan 2023 10:37:35 +0100 Subject: build a new bookmark embed for the context menu command This will be sent along the ephemeral message --- bot/exts/utilities/bookmark.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index ee5d8645..c8002b7e 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -52,9 +52,8 @@ class BookmarkTitleSelectionForm(discord.ui.Modal): """Sends the bookmark embed to the user with the newly chosen title.""" title = self.bookmark_title.value or self.bookmark_title.default await self.action_bookmark(interaction.channel, interaction.user, self.message, title) - view = SendBookmark(self.action_bookmark, interaction.user, interaction.channel, self.message, title) - embed = Bookmark.build_bookmark_embed(self.message) - await interaction.response.send_message(embed=embed, view=view, ephemeral=True) + embed = Bookmark.build_ephemeral_bookmark_embed(self.message) + await interaction.response.send_message(embed=embed, ephemeral=True) class LinkTargetMessage(discord.ui.View): @@ -122,6 +121,18 @@ class Bookmark(commands.Cog): colour=Colours.soft_green, ) + @staticmethod + def build_ephemeral_bookmark_embed(target_message: discord.Message) -> discord.Embed: + """Build the ephemeral embed to the bookmark requester.""" + return discord.Embed( + description=( + f"A bookmark for [this message]({target_message.jump_url})" + f"has been successfully sent your way" + f"Please check your DMs to retrieve it." + ), + colour=Colours.soft_green, + ) + @staticmethod def build_bookmark_dm(target_message: discord.Message, title: str) -> discord.Embed: """Build the embed to DM the bookmark requester.""" -- cgit v1.2.3 From 05c1d9d96c1154f365e75eefdd3df4995488e1c6 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Sat, 14 Jan 2023 10:42:20 +0100 Subject: add formatting to the ephemeral embed --- bot/exts/utilities/bookmark.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index c8002b7e..092d6215 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -126,8 +126,8 @@ class Bookmark(commands.Cog): """Build the ephemeral embed to the bookmark requester.""" return discord.Embed( description=( - f"A bookmark for [this message]({target_message.jump_url})" - f"has been successfully sent your way" + f"A bookmark for [this message]({target_message.jump_url}) " + f"has been successfully sent your way.\n" f"Please check your DMs to retrieve it." ), colour=Colours.soft_green, -- cgit v1.2.3 From 329514bdafa6bb3f436d93b0e478b69f2d0d59c3 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Sun, 15 Jan 2023 12:06:12 +0100 Subject: remove the call to action to check DMS for the bm --- bot/exts/utilities/bookmark.py | 1 - 1 file changed, 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 092d6215..473ecedc 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -128,7 +128,6 @@ class Bookmark(commands.Cog): description=( f"A bookmark for [this message]({target_message.jump_url}) " f"has been successfully sent your way.\n" - f"Please check your DMs to retrieve it." ), colour=Colours.soft_green, ) -- cgit v1.2.3 From 0dae917e3d02b46296c2087edd2b7ec108ab55f4 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Sun, 15 Jan 2023 13:00:47 +0100 Subject: disallow usage of the context menu command in DMs --- bot/exts/utilities/bookmark.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'bot') diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 473ecedc..e2988dca 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -180,6 +180,11 @@ class Bookmark(commands.Cog): 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.""" permissions = interaction.channel.permissions_for(interaction.user) + if not interaction.channel.guild: + embed = Bookmark.build_error_embed("This command cannot be used in DMs.") + await interaction.response.send_message(embed=embed) + return + if not permissions.read_messages: log.info(f"{interaction.user} tried to bookmark a message in #{interaction.channel}" f"but has no permissions.") -- cgit v1.2.3