diff options
author | 2023-02-19 14:46:45 +0000 | |
---|---|---|
committer | 2023-02-19 19:19:35 +0000 | |
commit | 079e03116e214f2c5c6546dd06e54baafa7e3c98 (patch) | |
tree | 244cf95d1de28a8a288e02c268a087281ff873d6 | |
parent | Update docstrings and error messages in Bookmark command (diff) |
Move action_bookmark to inside the ContextMenu form class
-rw-r--r-- | bot/exts/utilities/bookmark.py | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 7675edc3..bedaca80 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -24,14 +24,9 @@ class BookmarkForm(discord.ui.Modal): required=False, ) - def __init__( - self, - message: discord.Message, - action_bookmark_function: Callable[[discord.TextChannel, discord.Member, discord.Message, str], None], - ): + def __init__(self, message: discord.Message): 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.""" @@ -40,6 +35,29 @@ class BookmarkForm(discord.ui.Modal): embed = Bookmark.build_success_reply_embed(self.message) await interaction.response.send_message(embed=embed, ephemeral=True) + async def action_bookmark( + self, + channel: discord.TextChannel, + member: discord.Member, + target_message: discord.Message, + title: str + ) -> None: + """ + Sends the given target_message as a bookmark to the member in DMs to the user. + + Send an error embed instead if the member has DMs disabled. + """ + embed = Bookmark.build_bookmark_dm(target_message, title) + try: + await member.send(embed=embed, view=LinkTargetMessage(target_message)) + except discord.Forbidden: + await channel.send( + embed=Bookmark.build_error_embed("Enable your DMs to receive the bookmark."), + ephemeral=True, + ) + else: + log.info(f"{member} bookmarked {target_message.jump_url} with title '{title}'") + class LinkTargetMessage(discord.ui.View): """The button that relays the user to the bookmarked message.""" @@ -90,27 +108,6 @@ class Bookmark(commands.Cog): colour=Colours.soft_red, ) - async def action_bookmark( - self, - channel: discord.TextChannel, - member: discord.Member, - target_message: discord.Message, - title: str - ) -> None: - """ - Sends the given target_message as a bookmark to the member in DMs to the user. - - Send an error embed instead if the member has DMs disabled. - """ - embed = self.build_bookmark_dm(target_message, title) - try: - await member.send(embed=embed, view=LinkTargetMessage(target_message)) - except discord.Forbidden: - error_embed = self.build_error_embed(f"{member.mention}, please enable your DMs to receive the bookmark.") - await channel.send(embed=error_embed) - else: - log.info(f"{member} bookmarked {target_message.jump_url} with title '{title}'") - 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) |