Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions bot/exts/info/doc/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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
Expand Down Expand Up @@ -341,13 +341,12 @@ async def get_command(self, ctx: commands.Context, *, symbol_name: Optional[str]
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)
Expand Down
15 changes: 12 additions & 3 deletions bot/exts/info/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
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"
Expand Down Expand Up @@ -67,8 +69,15 @@ async def get_package_info(self, ctx: Context, package: str) -> None:
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)
Comment thread
Bluenix2 marked this conversation as resolved.

# 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)

Expand Down
10 changes: 7 additions & 3 deletions bot/utils/messages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import contextlib
import logging
import random
import re
Expand Down Expand Up @@ -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`.
Expand All @@ -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()
Comment thread
Bluenix2 marked this conversation as resolved.
else:
await message.delete()


Expand Down