@@ -120,7 +120,12 @@ def __init__(self, bot: Bot):
120
120
name = "Bookmark" ,
121
121
callback = self ._bookmark_context_menu_callback ,
122
122
)
123
+ self .delete_bookmark_context_menu = discord .app_commands .ContextMenu (
124
+ name = "Delete bookmark" ,
125
+ callback = self ._delete_bookmark_context_menu_callback ,
126
+ )
123
127
self .bot .tree .add_command (self .book_mark_context_menu , guild = discord .Object (bot .guild_id ))
128
+ self .bot .tree .add_command (self .delete_bookmark_context_menu )
124
129
125
130
@staticmethod
126
131
def build_success_reply_embed (target_message : discord .Message ) -> discord .Embed :
@@ -177,6 +182,18 @@ async def _bookmark_context_menu_callback(self, interaction: discord.Interaction
177
182
bookmark_title_form = BookmarkForm (message = message )
178
183
await interaction .response .send_modal (bookmark_title_form )
179
184
185
+ async def _delete_bookmark_context_menu_callback (
186
+ self ,
187
+ interaction : discord .Interaction ,
188
+ message : discord .Message
189
+ ) -> None :
190
+ """The callback that will handle deleting a bookmark from a context menu command."""
191
+ await self ._delete_bookmark (message , interaction .channel )
192
+ await interaction .response .send_message (
193
+ embed = self ._build_success_embed ("Bookmark successfully deleted." ),
194
+ ephemeral = True ,
195
+ )
196
+
180
197
@commands .group (name = "bookmark" , aliases = ("bm" , "pin" ), invoke_without_command = True )
181
198
@commands .guild_only ()
182
199
@whitelist_override (roles = (Roles .everyone ,))
@@ -235,12 +252,23 @@ async def delete_bookmark(
235
252
The command invocation must be a reply to the message that is to be deleted.
236
253
"""
237
254
target_message : discord .Message | None = getattr (ctx .message .reference , "resolved" , None )
255
+ await self ._delete_bookmark (target_message , ctx .channel )
256
+ await ctx .send (embed = self ._build_success_embed ("Bookmark successfully deleted." ), delete_after = 10 )
257
+
258
+ @staticmethod
259
+ def _build_success_embed (message : str ) -> discord .Embed :
260
+ return discord .Embed (
261
+ description = message ,
262
+ colour = Colours .soft_green
263
+ )
264
+
265
+ async def _delete_bookmark (self , target_message : discord .Message | None , channel : discord .abc .Messageable ) -> None :
266
+ """Delete a bookmark."""
238
267
if target_message is None :
239
268
raise commands .UserInputError ("You must reply to the message from Sir-Lancebot you wish to delete." )
240
-
241
- if not isinstance (ctx .channel , discord .DMChannel ):
269
+ if not isinstance (channel , discord .DMChannel ):
242
270
raise commands .UserInputError ("You can only run this command your own DMs!" )
243
- if target_message .channel != ctx . channel :
271
+ if target_message .channel . id != channel . id :
244
272
raise commands .UserInputError ("You can only delete messages in your own DMs!" )
245
273
if target_message .author != self .bot .user :
246
274
raise commands .UserInputError ("You can only delete messages sent by Sir Lancebot!" )
0 commit comments