aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2023-02-19 14:47:41 +0000
committerGravatar Chris Lovering <[email protected]>2023-02-19 19:19:35 +0000
commiteac0bafb3c7b6b036ec2e72d9b87a0a9a4826f11 (patch)
tree619795e3cb43dc8d598c3357fe9ee35c45886f28
parentMove action_bookmark to inside the ContextMenu form class (diff)
Only successfully reply to bookmark if bookmark was sent
-rw-r--r--bot/exts/utilities/bookmark.py38
1 files changed, 20 insertions, 18 deletions
diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py
index bedaca80..22fa2dbb 100644
--- a/bot/exts/utilities/bookmark.py
+++ b/bot/exts/utilities/bookmark.py
@@ -31,32 +31,34 @@ class BookmarkForm(discord.ui.Modal):
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)
- embed = Bookmark.build_success_reply_embed(self.message)
- await interaction.response.send_message(embed=embed, ephemeral=True)
+ try:
+ await self.dm_bookmark(interaction, self.message, title)
+ except discord.Forbidden:
+ await interaction.response.send_message(
+ embed=Bookmark.build_error_embed("Enable your DMs to receive the bookmark."),
+ ephemeral=True,
+ )
+ return
- async def action_bookmark(
+ await interaction.response.send_message(
+ embed=Bookmark.build_success_reply_embed(self.message),
+ ephemeral=True,
+ )
+
+ async def dm_bookmark(
self,
- channel: discord.TextChannel,
- member: discord.Member,
+ interaction: discord.Interaction,
target_message: discord.Message,
- title: str
+ title: str,
) -> None:
"""
- Sends the given target_message as a bookmark to the member in DMs to the user.
+ Sends the target_message as a bookmark to the interaction user's DMs.
- Send an error embed instead if the member has DMs disabled.
+ Raises ``discord.Forbidden`` if the user's DMs are closed.
"""
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}'")
+ await interaction.user.send(embed=embed, view=LinkTargetMessage(target_message))
+ log.info(f"{interaction.user} bookmarked {target_message.jump_url} with title {title!r}")
class LinkTargetMessage(discord.ui.View):