Skip to content

Commit

Permalink
add delete bookmark context menu command
Browse files Browse the repository at this point in the history
  • Loading branch information
shtlrs committed Feb 22, 2023
1 parent 06e5a01 commit 422cb58
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion bot/exts/utilities/bookmark.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import random
from typing import Optional

import discord
from discord.ext import commands
Expand Down Expand Up @@ -73,6 +72,10 @@ def __init__(self, bot: Bot):
name="Bookmark",
callback=self._bookmark_context_menu_callback,
)
self.delete_book_mark_context_menu = discord.app_commands.ContextMenu(
name="Delete bookmark",
callback=self._delete_bookmark_context_menu_callback,
)
self.bot.tree.add_command(self.book_mark_context_menu, guild=discord.Object(bot.guild_id))

@staticmethod
Expand Down Expand Up @@ -105,6 +108,26 @@ def build_error_embed(message: str) -> discord.Embed:
colour=Colours.soft_red,
)

async def _delete_bookmark_context_menu_callback(
self,
interaction: discord.Interaction,
message: discord.Message
) -> None:
"""
Delete the Sir-Lancebot message that the command invocation is replying to.
This command allows deleting any message sent by Sir-Lancebot in the user's DM channel with the bot.
The command invocation must be a reply to the message that is to be deleted.
"""
if interaction.channel.type != discord.ChannelType.private:
raise commands.UserInputError("You can only run this command your own DMs!")
elif message.channel != interaction.channel:
raise commands.UserInputError("You can only delete messages in your own DMs!")
elif message.author != self.bot.user:
raise commands.UserInputError("You can only delete messages sent by Sir Lancebot!")

await message.delete()

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)
Expand Down

0 comments on commit 422cb58

Please sign in to comment.