diff options
| author | 2020-03-30 09:29:50 +0300 | |
|---|---|---|
| committer | 2020-03-30 09:29:50 +0300 | |
| commit | f9fa3e6a67a196c9b529c9a8b8b68bcd89f0dcec (patch) | |
| tree | f93f20158fc6cccb1c5c38cceecf83131b0fd6a3 | |
| parent | Merge pull request #849 from ks129/webhook-match (diff) | |
(Tags): Added helper function `handle_trashcan_react` for tag response deletion handling.
| -rw-r--r-- | bot/cogs/tags.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py index 539105017..293fa36f6 100644 --- a/bot/cogs/tags.py +++ b/bot/cogs/tags.py @@ -1,14 +1,16 @@ import logging import re import time +from asyncio import TimeoutError from pathlib import Path from typing import Callable, Dict, Iterable, List, Optional -from discord import Colour, Embed +from discord import Colour, Embed, Message, Reaction, User from discord.ext.commands import Cog, Context, group from bot import constants from bot.bot import Bot +from bot.constants import Emojis from bot.converters import TagNameConverter from bot.pagination import LinePaginator @@ -139,6 +141,24 @@ class Tags(Cog): max_lines=15 ) + async def handle_trashcan_react(self, ctx: Context, msg: Message) -> None: + """Add `trashcan` emoji to Tag and handle deletion when user react to it.""" + await msg.add_reaction(Emojis.trashcan) + + def check_trashcan(reaction: Reaction, user: User) -> bool: + return ( + reaction.emoji == Emojis.trashcan + and user.id == ctx.author.id + and reaction.message == msg + ) + try: + await self.bot.wait_for("reaction_add", timeout=60.0, check=check_trashcan) + except TimeoutError: + await msg.remove_reaction(Emojis.trashcan, msg.author) + else: + await ctx.message.delete() + await msg.delete() + @group(name='tags', aliases=('tag', 't'), invoke_without_command=True) async def tags_group(self, ctx: Context, *, tag_name: TagNameConverter = None) -> None: """Show all known tags, a single tag, or run a subcommand.""" |