aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dennis Pham <[email protected]>2020-09-01 19:52:26 -0400
committerGravatar GitHub <[email protected]>2020-09-01 19:52:26 -0400
commit845106db2353a8716320458445a1c08baf834a0e (patch)
tree2d9766f20d3a65c5fc00301df74cd0c2dcc5721e
parentFixed old tests and added 2 new ones (diff)
parentMerge pull request #1123 from AtieP/master (diff)
Merge branch 'master' into make-antimalware-ignore-bot-and-webhook
-rw-r--r--bot/cogs/help.py34
1 files changed, 6 insertions, 28 deletions
diff --git a/bot/cogs/help.py b/bot/cogs/help.py
index 25ce4ae0f..99d503f5c 100644
--- a/bot/cogs/help.py
+++ b/bot/cogs/help.py
@@ -1,50 +1,28 @@
import itertools
import logging
-from asyncio import TimeoutError
from collections import namedtuple
from contextlib import suppress
from typing import List, Union
-from discord import Colour, Embed, Member, Message, NotFound, Reaction, User
+from discord import Colour, Embed
from discord.ext.commands import Bot, Cog, Command, Context, Group, HelpCommand
from fuzzywuzzy import fuzz, process
from fuzzywuzzy.utils import full_process
from bot import constants
-from bot.constants import Channels, Emojis, STAFF_ROLES
+from bot.constants import Channels, STAFF_ROLES
from bot.decorators import redirect_output
from bot.pagination import LinePaginator
+from bot.utils.messages import wait_for_deletion
log = logging.getLogger(__name__)
COMMANDS_PER_PAGE = 8
-DELETE_EMOJI = Emojis.trashcan
PREFIX = constants.Bot.prefix
Category = namedtuple("Category", ["name", "description", "cogs"])
-async def help_cleanup(bot: Bot, author: Member, message: Message) -> None:
- """
- Runs the cleanup for the help command.
-
- Adds the :trashcan: reaction that, when clicked, will delete the help message.
- After a 300 second timeout, the reaction will be removed.
- """
- def check(reaction: Reaction, user: User) -> bool:
- """Checks the reaction is :trashcan:, the author is original author and messages are the same."""
- return str(reaction) == DELETE_EMOJI and user.id == author.id and reaction.message.id == message.id
-
- await message.add_reaction(DELETE_EMOJI)
-
- with suppress(NotFound):
- try:
- await bot.wait_for("reaction_add", check=check, timeout=300)
- await message.delete()
- except TimeoutError:
- await message.remove_reaction(DELETE_EMOJI, bot.user)
-
-
class HelpQueryNotFound(ValueError):
"""
Raised when a HelpSession Query doesn't match a command or cog.
@@ -208,7 +186,7 @@ class CustomHelpCommand(HelpCommand):
"""Send help for a single command."""
embed = await self.command_formatting(command)
message = await self.context.send(embed=embed)
- await help_cleanup(self.context.bot, self.context.author, message)
+ await wait_for_deletion(message, (self.context.author.id,), self.context.bot)
@staticmethod
def get_commands_brief_details(commands_: List[Command], return_as_list: bool = False) -> Union[List[str], str]:
@@ -247,7 +225,7 @@ class CustomHelpCommand(HelpCommand):
embed.description += f"\n**Subcommands:**\n{command_details}"
message = await self.context.send(embed=embed)
- await help_cleanup(self.context.bot, self.context.author, message)
+ await wait_for_deletion(message, (self.context.author.id,), self.context.bot)
async def send_cog_help(self, cog: Cog) -> None:
"""Send help for a cog."""
@@ -263,7 +241,7 @@ class CustomHelpCommand(HelpCommand):
embed.description += f"\n\n**Commands:**\n{command_details}"
message = await self.context.send(embed=embed)
- await help_cleanup(self.context.bot, self.context.author, message)
+ await wait_for_deletion(message, (self.context.author.id,), self.context.bot)
@staticmethod
def _category_key(command: Command) -> str: