diff options
| author | 2019-12-10 23:38:06 +0100 | |
|---|---|---|
| committer | 2019-12-10 23:38:06 +0100 | |
| commit | a463ab08c8ba329c0a282ad6e724455544c26690 (patch) | |
| tree | 9648fdf6eef49fde27cb21d9c58b305b3a357564 | |
| parent | Merge pull request #328 from python-discord/aoc-announcement-mention-fix (diff) | |
| parent | Merge branch 'bookmark' of https://github.com/AG4lyf/seasonalbot into bookmark (diff) | |
Merge pull request #327 from AG4lyf/bookmark
[Feature] `.bm` `.pin` bookmarks/personal-pins
Diffstat (limited to '')
| -rw-r--r-- | bot/constants.py | 6 | ||||
| -rw-r--r-- | bot/seasons/evergreen/bookmark.py | 55 | 
2 files changed, 61 insertions, 0 deletions
| diff --git a/bot/constants.py b/bot/constants.py index ce650b80..eca4f67b 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -4,6 +4,7 @@ from typing import NamedTuple  from datetime import datetime  __all__ = ( +    "bookmark_icon_url",      "AdventOfCode", "Channels", "Client", "Colours", "Emojis", "Hacktoberfest", "Roles", "Tokens",      "WHITELISTED_CHANNELS", "STAFF_ROLES", "MODERATION_ROLES",      "POSITIVE_REPLIES", "NEGATIVE_REPLIES", "ERROR_REPLIES", @@ -11,6 +12,11 @@ __all__ = (  log = logging.getLogger(__name__) +bookmark_icon_url = ( +    "https://images-ext-2.discordapp.net/external/zl4oDwcmxUILY7sD9ZWE2fU5R7n6QcxEmPYSE5eddbg/" +    "%3Fv%3D1/https/cdn.discordapp.com/emojis/654080405988966419.png?width=20&height=20" +) +  class AdventOfCode:      leaderboard_cache_age_threshold_seconds = 3600 diff --git a/bot/seasons/evergreen/bookmark.py b/bot/seasons/evergreen/bookmark.py new file mode 100644 index 00000000..9962186f --- /dev/null +++ b/bot/seasons/evergreen/bookmark.py @@ -0,0 +1,55 @@ +import logging
 +import random
 +
 +import discord
 +from discord.ext import commands
 +
 +from bot.constants import Colours, ERROR_REPLIES, Emojis, bookmark_icon_url
 +
 +log = logging.getLogger(__name__)
 +
 +
 +class Bookmark(commands.Cog):
 +    """Creates personal bookmarks by relaying a message link to the user's DMs."""
 +
 +    def __init__(self, bot: commands.Bot):
 +        self.bot = bot
 +
 +    @commands.command(name="bookmark", aliases=("bm", "pin"))
 +    async def bookmark(
 +        self,
 +        ctx: commands.Context,
 +        target_message: discord.Message,
 +        *,
 +        title: str = "Bookmark"
 +    ) -> None:
 +        """Send the author a link to `target_message` via DMs."""
 +        log.info(f"{ctx.author} bookmarked {target_message.jump_url} with title '{title}'")
 +        embed = discord.Embed(
 +            title=title,
 +            colour=Colours.soft_green,
 +            description=(
 +                f"{target_message.content}\n\n"
 +                f"[Visit original message]({target_message.jump_url})"
 +            )
 +        )
 +        embed.set_author(name=target_message.author, icon_url=target_message.author.avatar_url)
 +        embed.set_thumbnail(url=bookmark_icon_url)
 +
 +        try:
 +            await ctx.author.send(embed=embed)
 +        except discord.Forbidden:
 +            error_embed = discord.Embed(
 +                title=random.choice(ERROR_REPLIES),
 +                description=f"{ctx.author.mention}, please enable your DMs to receive the bookmark",
 +                colour=Colours.soft_red
 +            )
 +            await ctx.send(embed=error_embed)
 +        else:
 +            await ctx.message.add_reaction(Emojis.envelope)
 +
 +
 +def setup(bot: commands.Bot) -> None:
 +    """Load the Bookmark cog."""
 +    bot.add_cog(Bookmark(bot))
 +    log.info("Bookmark cog loaded")
 | 
