Skip to content

Commit

Permalink
add possibility of deleting a bm with a button
Browse files Browse the repository at this point in the history
  • Loading branch information
Amrou Bellalouna authored and Amrou Bellalouna committed Jan 29, 2023
1 parent ca76688 commit bdc0a29
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions bot/exts/utilities/bookmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,29 @@


class LinkTargetMessage(discord.ui.View):
"""The button that relays the user to the bookmarked message."""
"""
The button that relays the user to the bookmarked message.
Attributes
__________
dm_message: discord.Message
The message that will be sent to the bookmark's requester DMs
"""

dm_message: discord.Message | None

def __init__(self, target_message: discord.Message):
super().__init__()
self.dm_message = None
self.add_item(discord.ui.Button(label="View Message", url=target_message.jump_url))

@discord.ui.button(label="Delete bookmark", style=discord.ButtonStyle.red)
async def button_callback(self, interaction: discord.Interaction, button: discord.Button) -> None:
"""The button callback."""
if self.dm_message:
await self.dm_message.delete()


class SendBookmark(discord.ui.View):
"""The button that sends the bookmark to other users."""
Expand Down Expand Up @@ -110,7 +127,9 @@ async def action_bookmark(
"""
embed = self.build_bookmark_dm(target_message, title)
try:
await member.send(embed=embed, view=LinkTargetMessage(target_message))
view = LinkTargetMessage(target_message)
dm_message = await member.send(embed=embed, view=view)
view.dm_message = dm_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)
Expand Down

0 comments on commit bdc0a29

Please sign in to comment.