diff options
Diffstat (limited to 'bot/exts/utilities/bookmark.py')
| -rw-r--r-- | bot/exts/utilities/bookmark.py | 100 | 
1 files changed, 11 insertions, 89 deletions
| diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index c049a712..10acca1e 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -1,27 +1,16 @@  import logging  import random -from typing import Callable, Optional +from typing import Optional  import discord  from discord.ext import commands  from bot.bot import Bot  from bot.constants import Colours, ERROR_REPLIES, Icons, Roles -from bot.utils.converters import WrappedMessageConverter  from bot.utils.decorators import whitelist_override  log = logging.getLogger(__name__) -# Number of seconds to wait for other users to bookmark the same message -TIMEOUT = 120 -MESSAGE_NOT_FOUND_ERROR = ( -    "You must either provide a reference to a valid message, or reply to one." -    "\n\nThe lookup strategy for a message is as follows (in order):" -    "\n1. Lookup by '{channel ID}-{message ID}' (retrieved by shift-clicking on 'Copy ID')" -    "\n2. Lookup by message ID (the message **must** be in the current channel)" -    "\n3. Lookup by message URL" -) -  class BookmarkTitleSelectionForm(discord.ui.Modal):      """ @@ -64,41 +53,6 @@ class LinkTargetMessage(discord.ui.View):          self.add_item(discord.ui.Button(label="View Message", url=target_message.jump_url)) -class SendBookmark(discord.ui.View): -    """The button that sends the bookmark to other users.""" - -    def __init__( -        self, -        action_bookmark_function: Callable[[discord.TextChannel, discord.Member, discord.Message, str], None], -        author: discord.Member, -        channel: discord.TextChannel, -        target_message: discord.Message, -        title: str -    ): -        super().__init__() - -        self.bookmark_function = action_bookmark_function -        self.clicked = [author.id] -        self.channel = channel -        self.target_message = target_message -        self.title = title - -    @discord.ui.button(label="Receive Bookmark", style=discord.ButtonStyle.green) -    async def button_callback(self, interaction: discord.Interaction, button: discord.Button) -> None: -        """The button callback.""" -        if interaction.user.id in self.clicked: -            await interaction.response.send_message( -                "You have already received a bookmark to that message.", -                ephemeral=True, -            ) -            return -        self.clicked.append(interaction.user.id) - -        await self.bookmark_function(self.channel, interaction.user, self.target_message, self.title) - -        await interaction.response.send_message("You have received a bookmark to that message.", ephemeral=True) - -  class Bookmark(commands.Cog):      """Creates personal bookmarks by relaying a message link to the user's DMs.""" @@ -111,17 +65,6 @@ class Bookmark(commands.Cog):          self.bot.tree.add_command(self.book_mark_context_menu, guild=discord.Object(bot.guild_id))      @staticmethod -    def build_bookmark_embed(target_message: discord.Message) -> discord.Embed: -        """Build the channel embed to the bookmark requester.""" -        return discord.Embed( -            description=( -                f"Click the button to be sent your very own bookmark to " -                f"[this message]({target_message.jump_url})." -            ), -            colour=Colours.soft_green, -        ) - -    @staticmethod      def build_ephemeral_bookmark_embed(target_message: discord.Message) -> discord.Embed:          """Build the ephemeral embed to the bookmark requester."""          return discord.Embed( @@ -196,37 +139,16 @@ class Bookmark(commands.Cog):      @commands.group(name="bookmark", aliases=("bm", "pin"), invoke_without_command=True)      @commands.guild_only()      @whitelist_override(roles=(Roles.everyone,)) -    async def bookmark( -        self, -        ctx: commands.Context, -        target_message: Optional[WrappedMessageConverter], -        *, -        title: str = "Bookmark" -    ) -> None: -        """ -        Send the author a link to the specified message via DMs. - -        Members can either give a message as an argument, or reply to a message. - -        Bookmarks can subsequently be deleted by using the `bookmark delete` command in DMs. -        """ -        target_message: Optional[discord.Message] = target_message or getattr(ctx.message.reference, "resolved", None) -        if target_message is None: -            raise commands.UserInputError(MESSAGE_NOT_FOUND_ERROR) - -        permissions = ctx.channel.permissions_for(ctx.author) -        if not permissions.read_messages: -            log.info(f"{ctx.author} tried to bookmark a message in #{ctx.channel} but has no permissions.") -            embed = Bookmark.build_error_embed("You don't have permission to view this channel.") -            await ctx.send(embed=embed) -            return - -        await self.action_bookmark(ctx.channel, ctx.author, target_message, title) - -        view = SendBookmark(self.action_bookmark, ctx.author, ctx.channel, target_message, title) -        embed = self.build_bookmark_embed(target_message) - -        await ctx.send(embed=embed, view=view) +    @commands.cooldown(1, 30, commands.BucketType.channel) +    async def bookmark(self, ctx: commands.Context) -> None: +        """Teach the invoker how to use the new context-menu based command for a smooth migration.""" +        await ctx.send( +            embed=self.build_error_embed( +                "The bookmark text command has been replaced with a context menu command!\n\n" +                "To bookmark a message simply right-click (press and hold on mobile) " +                "on a message, open the 'Apps' menu, and click 'Bookmark'." +            ) +        )      @bookmark.command(name="delete", aliases=("del", "rm"), root_aliases=("unbm", "unbookmark", "dmdelete", "dmdel"))      @whitelist_override(bypass_defaults=True, allow_dm=True) | 
