diff options
| author | 2020-08-15 10:22:21 +0200 | |
|---|---|---|
| committer | 2020-08-15 10:22:21 +0200 | |
| commit | b7e40706aa152228154ce96f5aa346a9f5fc43db (patch) | |
| tree | 84b49fd3aa1f55532ff8d96033111194324a099f | |
| parent | Merge pull request #1097 from Numerlor/remove-api-endpoints (diff) | |
Add doc cleanup
Diffstat (limited to '')
| -rw-r--r-- | bot/cogs/doc.py | 28 | 
1 files changed, 26 insertions, 2 deletions
| diff --git a/bot/cogs/doc.py b/bot/cogs/doc.py index 204cffb37..63dcc2c15 100644 --- a/bot/cogs/doc.py +++ b/bot/cogs/doc.py @@ -19,7 +19,7 @@ from sphinx.ext import intersphinx  from urllib3.exceptions import ProtocolError  from bot.bot import Bot -from bot.constants import MODERATION_ROLES, RedirectOutput +from bot.constants import MODERATION_ROLES, RedirectOutput, Emojis  from bot.converters import ValidPythonIdentifier, ValidURL  from bot.decorators import with_role  from bot.pagination import LinePaginator @@ -28,6 +28,8 @@ from bot.pagination import LinePaginator  log = logging.getLogger(__name__)  logging.getLogger('urllib3').setLevel(logging.WARNING) +DELETE_EMOJI = Emojis.trashcan +  # Since Intersphinx is intended to be used with Sphinx,  # we need to mock its configuration.  SPHINX_MOCK_APP = SimpleNamespace( @@ -66,6 +68,27 @@ FAILED_REQUEST_RETRY_AMOUNT = 3  NOT_FOUND_DELETE_DELAY = RedirectOutput.delete_delay +async def doc_cleanup(bot: Bot, author: discord.Member, message: discord.Message) -> None: +    """ +    Runs the cleanup for the documentation command. + +    Adds a :trashcan: reaction what, when clicked, will delete the documentation embed. +    After a 300 second timeout, the reaction will be removed.""" + +    await message.add_reaction(DELETE_EMOJI) + +    def check(reaction: discord.Reaction, member: discord.Member) -> bool: +        """Check the reaction is :trashcan:, the author is original author and messages are the same.""" +        return str(reaction) == DELETE_EMOJI and member.id == author.id and reaction.message.id == message.id + +    with suppress(NotFound): +        try: +            await bot.wait_for("reaction_add", check=check, timeout=300) +            await message.delete() +        except asyncio.TimeoutError: +            await message.remove_reaction(DELETE_EMOJI, bot.user) + +  def async_cache(max_size: int = 128, arg_offset: int = 0) -> Callable:      """      LRU cache implementation for coroutines. @@ -391,7 +414,8 @@ class Doc(commands.Cog):                      await error_message.delete(delay=NOT_FOUND_DELETE_DELAY)                      await ctx.message.delete(delay=NOT_FOUND_DELETE_DELAY)              else: -                await ctx.send(embed=doc_embed) +                doc_embed = await ctx.send(embed=doc_embed) +                await doc_cleanup(self.bot, ctx.author, doc_embed)      @docs_group.command(name='set', aliases=('s',))      @with_role(*MODERATION_ROLES) | 
