diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/info/doc/_cog.py | 5 | ||||
| -rw-r--r-- | bot/exts/info/pypi.py | 15 | ||||
| -rw-r--r-- | bot/utils/messages.py | 10 | 
3 files changed, 21 insertions, 9 deletions
| diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py index 704884fd1..fb9b2584a 100644 --- a/bot/exts/info/doc/_cog.py +++ b/bot/exts/info/doc/_cog.py @@ -14,7 +14,7 @@ import discord  from discord.ext import commands  from bot.bot import Bot -from bot.constants import Emojis, MODERATION_ROLES, RedirectOutput +from bot.constants import MODERATION_ROLES, RedirectOutput  from bot.converters import Inventory, PackageName, ValidURL, allowed_strings  from bot.pagination import LinePaginator  from bot.utils.lock import SharedEvent, lock @@ -341,13 +341,12 @@ class DocCog(commands.Cog):              if doc_embed is None:                  error_message = await send_denial(ctx, "No documentation found for the requested symbol.")                  await wait_for_deletion(error_message, (ctx.author.id,), timeout=NOT_FOUND_DELETE_DELAY) -                with suppress(discord.NotFound): -                    await error_message.clear_reaction(Emojis.trashcan)                  # Make sure that we won't cause a ghost-ping by deleting the message                  if not (ctx.message.mentions or ctx.message.role_mentions):                      with suppress(discord.NotFound):                          await ctx.message.delete() +                        await error_message.delete()              else:                  msg = await ctx.send(embed=doc_embed) diff --git a/bot/exts/info/pypi.py b/bot/exts/info/pypi.py index 2e42e7d6b..62498ce0b 100644 --- a/bot/exts/info/pypi.py +++ b/bot/exts/info/pypi.py @@ -2,13 +2,15 @@ import itertools  import logging  import random  import re +from contextlib import suppress -from discord import Embed +from discord import Embed, NotFound  from discord.ext.commands import Cog, Context, command  from discord.utils import escape_markdown  from bot.bot import Bot  from bot.constants import Colours, NEGATIVE_REPLIES, RedirectOutput +from bot.utils.messages import wait_for_deletion  URL = "https://pypi.org/pypi/{package}/json"  PYPI_ICON = "https://cdn.discordapp.com/emojis/766274397257334814.png" @@ -67,8 +69,15 @@ class PyPi(Cog):                      log.trace(f"Error when fetching PyPi package: {response.status}.")          if error: -            await ctx.send(embed=embed, delete_after=INVALID_INPUT_DELETE_DELAY) -            await ctx.message.delete(delay=INVALID_INPUT_DELETE_DELAY) +            error_message = await ctx.send(embed=embed) +            await wait_for_deletion(error_message, (ctx.author.id,), timeout=INVALID_INPUT_DELETE_DELAY) + +            # Make sure that we won't cause a ghost-ping by deleting the message +            if not (ctx.message.mentions or ctx.message.role_mentions): +                with suppress(NotFound): +                    await ctx.message.delete() +                    await error_message.delete() +          else:              await ctx.send(embed=embed) diff --git a/bot/utils/messages.py b/bot/utils/messages.py index d4a921161..90672fba2 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -1,5 +1,4 @@  import asyncio -import contextlib  import logging  import random  import re @@ -69,7 +68,9 @@ async def wait_for_deletion(      allow_mods: bool = True  ) -> None:      """ -    Wait for up to `timeout` seconds for a reaction by any of the specified `user_ids` to delete the message. +    Wait for any of `user_ids` to react with one of the `deletion_emojis` within `timeout` seconds to delete `message`. + +    If `timeout` expires then reactions are cleared to indicate the option to delete has expired.      An `attach_emojis` bool may be specified to determine whether to attach the given      `deletion_emojis` to the message in the given `context`. @@ -95,8 +96,11 @@ async def wait_for_deletion(          allow_mods=allow_mods,      ) -    with contextlib.suppress(asyncio.TimeoutError): +    try:          await bot.instance.wait_for('reaction_add', check=check, timeout=timeout) +    except asyncio.TimeoutError: +        await message.clear_reactions() +    else:          await message.delete() | 
