From 4e87b4e9c3eee762c061b8d1c17d57f172e4dd43 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Sun, 27 Oct 2019 10:56:11 +0800 Subject: Use trashcan emoji for message deletion --- bot/constants.py | 2 ++ bot/utils/messages.py | 6 +++++- config-default.yml | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bot/constants.py b/bot/constants.py index f341fb499..4737ce6a3 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -254,6 +254,8 @@ class Emojis(metaclass=YAMLGetter): status_idle: str status_dnd: str + trashcan: str + bullet: str new: str pencil: str diff --git a/bot/utils/messages.py b/bot/utils/messages.py index 549b33ca6..fe0b6b29f 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -15,7 +15,7 @@ MAX_SIZE = 1024 * 1024 * 8 # 8 Mebibytes async def wait_for_deletion( message: Message, user_ids: Sequence[Snowflake], - deletion_emojis: Sequence[str] = (Emojis.cross_mark,), + deletion_emojis: Sequence[str] = None, timeout: float = 60 * 5, attach_emojis: bool = True, client: Optional[Client] = None @@ -34,6 +34,10 @@ async def wait_for_deletion( bot = client or message.guild.me + if deletion_emojis is None: + default_emoji = bot.get_emoji(int(Emojis.trashcan)) or Emojis.cross_mark + deletion_emojis = (default_emoji,) + if attach_emojis: for emoji in deletion_emojis: await message.add_reaction(emoji) diff --git a/config-default.yml b/config-default.yml index 23dcbd44c..16842534d 100644 --- a/config-default.yml +++ b/config-default.yml @@ -32,6 +32,8 @@ style: status_dnd: "<:status_dnd:470326272082313216>" status_offline: "<:status_offline:470326266537705472>" + trashcan: "637136429717389331" + bullet: "\u2022" pencil: "\u270F" new: "\U0001F195" -- cgit v1.2.3 From 30ba84eecd7fc10c96a739dc53d3454de5d8fd6a Mon Sep 17 00:00:00 2001 From: kosayoda Date: Sun, 27 Oct 2019 17:24:21 +0800 Subject: Differentiate clear and delete emoji in help cog --- bot/cogs/help.py | 13 ++++++++++--- bot/utils/messages.py | 8 ++------ config-default.yml | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bot/cogs/help.py b/bot/cogs/help.py index 9607dbd8d..63b4e89b8 100644 --- a/bot/cogs/help.py +++ b/bot/cogs/help.py @@ -10,20 +10,22 @@ from discord.ext.commands import Bot, CheckFailure, Cog as DiscordCog, Command, from fuzzywuzzy import fuzz, process from bot import constants -from bot.constants import Channels, STAFF_ROLES +from bot.constants import Channels, Emojis, STAFF_ROLES from bot.decorators import redirect_output from bot.pagination import ( - DELETE_EMOJI, FIRST_EMOJI, LAST_EMOJI, + DELETE_EMOJI as CLEAR_EMOJI, FIRST_EMOJI, LAST_EMOJI, LEFT_EMOJI, LinePaginator, RIGHT_EMOJI, ) +DELETE_EMOJI = Emojis.trashcan REACTIONS = { FIRST_EMOJI: 'first', LEFT_EMOJI: 'back', RIGHT_EMOJI: 'next', LAST_EMOJI: 'end', - DELETE_EMOJI: 'stop' + CLEAR_EMOJI: 'clear', + DELETE_EMOJI: 'stop', } Cog = namedtuple('Cog', ['name', 'description', 'commands']) @@ -496,6 +498,11 @@ class HelpSession: if not self.is_last_page: await self.update_page(len(self._pages)-1) + async def do_clear(self) -> None: + """Event that is called when the user clears the emojis from the pagination.""" + await self.message.clear_reactions() + await self.message.add_reaction(DELETE_EMOJI) + async def do_stop(self) -> None: """Event that is called when the user requests to stop the help session.""" await self.message.delete() diff --git a/bot/utils/messages.py b/bot/utils/messages.py index fe0b6b29f..654d71797 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -15,7 +15,7 @@ MAX_SIZE = 1024 * 1024 * 8 # 8 Mebibytes async def wait_for_deletion( message: Message, user_ids: Sequence[Snowflake], - deletion_emojis: Sequence[str] = None, + deletion_emojis: Sequence[str] = (Emojis.trashcan,), timeout: float = 60 * 5, attach_emojis: bool = True, client: Optional[Client] = None @@ -34,10 +34,6 @@ async def wait_for_deletion( bot = client or message.guild.me - if deletion_emojis is None: - default_emoji = bot.get_emoji(int(Emojis.trashcan)) or Emojis.cross_mark - deletion_emojis = (default_emoji,) - if attach_emojis: for emoji in deletion_emojis: await message.add_reaction(emoji) @@ -46,7 +42,7 @@ async def wait_for_deletion( """Check that the deletion emoji is reacted by the approprite user.""" return ( reaction.message.id == message.id - and reaction.emoji in deletion_emojis + and str(reaction.emoji) in deletion_emojis and user.id in user_ids ) diff --git a/config-default.yml b/config-default.yml index 16842534d..696ef8a7e 100644 --- a/config-default.yml +++ b/config-default.yml @@ -32,7 +32,7 @@ style: status_dnd: "<:status_dnd:470326272082313216>" status_offline: "<:status_offline:470326266537705472>" - trashcan: "637136429717389331" + trashcan: "<:trashcan:637136429717389331>" bullet: "\u2022" pencil: "\u270F" -- cgit v1.2.3 From 56696b3b1858ad27dc7f3dce2898c7a6eb151f43 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Sun, 27 Oct 2019 17:26:27 +0800 Subject: Remove dev-test limit for filtering debugging --- bot/cogs/filtering.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 1d1d74e74..11c5d7223 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -136,9 +136,9 @@ class Filtering(Cog): and not msg.author.bot # Author not a bot ) - # If we're running the bot locally, ignore role whitelist and only listen to #dev-test + # If we're running the bot locally, ignore role whitelist if DEBUG_MODE: - filter_message = not msg.author.bot and msg.channel.id == Channels.devtest + filter_message = not msg.author.bot # If none of the above, we can start filtering. if filter_message: -- cgit v1.2.3 From af0e5329a5202c52cd94f86078c4a03119f7e324 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Mon, 28 Oct 2019 02:55:43 +0800 Subject: Revert "Remove dev-test limit for filtering debugging" This reverts commit 56696b3b1858ad27dc7f3dce2898c7a6eb151f43. --- bot/cogs/filtering.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 11c5d7223..1d1d74e74 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -136,9 +136,9 @@ class Filtering(Cog): and not msg.author.bot # Author not a bot ) - # If we're running the bot locally, ignore role whitelist + # If we're running the bot locally, ignore role whitelist and only listen to #dev-test if DEBUG_MODE: - filter_message = not msg.author.bot + filter_message = not msg.author.bot and msg.channel.id == Channels.devtest # If none of the above, we can start filtering. if filter_message: -- cgit v1.2.3 From a2210247a4ba9a2903f9e21bb637bd12603b486e Mon Sep 17 00:00:00 2001 From: kosayoda Date: Mon, 28 Oct 2019 10:47:10 +0800 Subject: Add delete emoji to pagination --- bot/cogs/help.py | 3 +-- bot/pagination.py | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/bot/cogs/help.py b/bot/cogs/help.py index 63b4e89b8..f5538ce5e 100644 --- a/bot/cogs/help.py +++ b/bot/cogs/help.py @@ -13,7 +13,7 @@ from bot import constants from bot.constants import Channels, Emojis, STAFF_ROLES from bot.decorators import redirect_output from bot.pagination import ( - DELETE_EMOJI as CLEAR_EMOJI, FIRST_EMOJI, LAST_EMOJI, + CLEAR_EMOJI, FIRST_EMOJI, LAST_EMOJI, LEFT_EMOJI, LinePaginator, RIGHT_EMOJI, ) @@ -501,7 +501,6 @@ class HelpSession: async def do_clear(self) -> None: """Event that is called when the user clears the emojis from the pagination.""" await self.message.clear_reactions() - await self.message.add_reaction(DELETE_EMOJI) async def do_stop(self) -> None: """Event that is called when the user requests to stop the help session.""" diff --git a/bot/pagination.py b/bot/pagination.py index 76082f459..11f7c77fe 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -6,13 +6,16 @@ from discord import Embed, Member, Message, Reaction from discord.abc import User from discord.ext.commands import Context, Paginator +from bot import constants + FIRST_EMOJI = "\u23EE" # [:track_previous:] LEFT_EMOJI = "\u2B05" # [:arrow_left:] RIGHT_EMOJI = "\u27A1" # [:arrow_right:] LAST_EMOJI = "\u23ED" # [:track_next:] -DELETE_EMOJI = "\u274c" # [:x:] +CLEAR_EMOJI = "\u274c" # [:x:] +DELETE_EMOJI = constants.Emojis.trashcan # [:trashcan:] -PAGINATION_EMOJI = [FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, DELETE_EMOJI] +PAGINATION_EMOJI = [FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, CLEAR_EMOJI, DELETE_EMOJI] log = logging.getLogger(__name__) @@ -131,7 +134,7 @@ class LinePaginator(Paginator): # Reaction is on this message reaction_.message.id == message.id, # Reaction is one of the pagination emotes - reaction_.emoji in PAGINATION_EMOJI, + str(reaction_.emoji) in PAGINATION_EMOJI, # Reaction was not made by the Bot user_.id != ctx.bot.user.id, # There were no restrictions @@ -203,10 +206,14 @@ class LinePaginator(Paginator): log.debug("Timed out waiting for a reaction") break # We're done, no reactions for the last 5 minutes - if reaction.emoji == DELETE_EMOJI: - log.debug("Got delete reaction") + if reaction.emoji == CLEAR_EMOJI: + log.debug("Got clear reaction") break + if str(reaction.emoji) == DELETE_EMOJI: + log.debug("Got delete reaction") + return await message.delete() + if reaction.emoji == FIRST_EMOJI: await message.remove_reaction(reaction.emoji, user) current_page = 0 @@ -342,7 +349,7 @@ class ImagePaginator(Paginator): # Reaction is on the same message sent reaction_.message.id == message.id, # The reaction is part of the navigation menu - reaction_.emoji in PAGINATION_EMOJI, + str(reaction_.emoji) in PAGINATION_EMOJI, # The reactor is not a bot not member.bot )) @@ -388,11 +395,16 @@ class ImagePaginator(Paginator): # Deletes the users reaction await message.remove_reaction(reaction.emoji, user) - # Delete reaction press - [:x:] - if reaction.emoji == DELETE_EMOJI: + # Clear reaction press - [:x:] + if reaction.emoji == CLEAR_EMOJI: log.debug("Got delete reaction") break + # Delete reaction press - [:trashcan:] + if str(reaction.emoji) == DELETE_EMOJI: + log.debug("Got delete reaction") + return await message.delete() + # First reaction press - [:track_previous:] if reaction.emoji == FIRST_EMOJI: if current_page == 0: -- cgit v1.2.3 From bab7fc2e4600bd89a62ad07dd8177de0ff943343 Mon Sep 17 00:00:00 2001 From: Kieran Siek Date: Mon, 28 Oct 2019 12:37:24 +0800 Subject: Apply suggestions from code review Fix incorrect docstring and comment Co-Authored-By: Mark --- bot/pagination.py | 2 +- bot/utils/messages.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/pagination.py b/bot/pagination.py index 11f7c77fe..8e3329c4b 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -397,7 +397,7 @@ class ImagePaginator(Paginator): # Clear reaction press - [:x:] if reaction.emoji == CLEAR_EMOJI: - log.debug("Got delete reaction") + log.debug("Got clear reaction") break # Delete reaction press - [:trashcan:] diff --git a/bot/utils/messages.py b/bot/utils/messages.py index 654d71797..7ab35257c 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -39,7 +39,7 @@ async def wait_for_deletion( await message.add_reaction(emoji) def check(reaction: Reaction, user: Member) -> bool: - """Check that the deletion emoji is reacted by the approprite user.""" + """Check that the deletion emoji is reacted by the appropriate user.""" return ( reaction.message.id == message.id and str(reaction.emoji) in deletion_emojis -- cgit v1.2.3 From d4ff83e6d2ffdbde4b934c37b24f61a8dc6c4ebb Mon Sep 17 00:00:00 2001 From: kosayoda Date: Mon, 28 Oct 2019 13:01:47 +0800 Subject: Fix linting error --- bot/pagination.py | 2 +- bot/utils/messages.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/pagination.py b/bot/pagination.py index 8e3329c4b..a7938fe85 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -397,7 +397,7 @@ class ImagePaginator(Paginator): # Clear reaction press - [:x:] if reaction.emoji == CLEAR_EMOJI: - log.debug("Got clear reaction") + log.debug("Got clear reaction") break # Delete reaction press - [:trashcan:] diff --git a/bot/utils/messages.py b/bot/utils/messages.py index 7ab35257c..022f79599 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -39,7 +39,7 @@ async def wait_for_deletion( await message.add_reaction(emoji) def check(reaction: Reaction, user: Member) -> bool: - """Check that the deletion emoji is reacted by the appropriate user.""" + """Check that the deletion emoji is reacted by the appropriate user.""" return ( reaction.message.id == message.id and str(reaction.emoji) in deletion_emojis -- cgit v1.2.3 From 9efd88047ed9201ab6bb6077de10b39490b9434f Mon Sep 17 00:00:00 2001 From: MarkKoz Date: Sat, 8 Feb 2020 07:40:26 -0800 Subject: Remove clear reaction from paginators It could be confused with the delete reaction. Clearing reactions manually is rarely a useful feature anyway. --- bot/cogs/help.py | 7 +------ bot/pagination.py | 12 +----------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/bot/cogs/help.py b/bot/cogs/help.py index ecf14d131..fd5bbc3ca 100644 --- a/bot/cogs/help.py +++ b/bot/cogs/help.py @@ -14,7 +14,7 @@ from bot.bot import Bot from bot.constants import Channels, Emojis, STAFF_ROLES from bot.decorators import redirect_output from bot.pagination import ( - CLEAR_EMOJI, FIRST_EMOJI, LAST_EMOJI, + FIRST_EMOJI, LAST_EMOJI, LEFT_EMOJI, LinePaginator, RIGHT_EMOJI, ) @@ -25,7 +25,6 @@ REACTIONS = { LEFT_EMOJI: 'back', RIGHT_EMOJI: 'next', LAST_EMOJI: 'end', - CLEAR_EMOJI: 'clear', DELETE_EMOJI: 'stop', } @@ -499,10 +498,6 @@ class HelpSession: if not self.is_last_page: await self.update_page(len(self._pages)-1) - async def do_clear(self) -> None: - """Event that is called when the user clears the emojis from the pagination.""" - await self.message.clear_reactions() - async def do_stop(self) -> None: """Event that is called when the user requests to stop the help session.""" await self.message.delete() diff --git a/bot/pagination.py b/bot/pagination.py index a7938fe85..35870c040 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -12,10 +12,9 @@ FIRST_EMOJI = "\u23EE" # [:track_previous:] LEFT_EMOJI = "\u2B05" # [:arrow_left:] RIGHT_EMOJI = "\u27A1" # [:arrow_right:] LAST_EMOJI = "\u23ED" # [:track_next:] -CLEAR_EMOJI = "\u274c" # [:x:] DELETE_EMOJI = constants.Emojis.trashcan # [:trashcan:] -PAGINATION_EMOJI = [FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, CLEAR_EMOJI, DELETE_EMOJI] +PAGINATION_EMOJI = [FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, DELETE_EMOJI] log = logging.getLogger(__name__) @@ -206,10 +205,6 @@ class LinePaginator(Paginator): log.debug("Timed out waiting for a reaction") break # We're done, no reactions for the last 5 minutes - if reaction.emoji == CLEAR_EMOJI: - log.debug("Got clear reaction") - break - if str(reaction.emoji) == DELETE_EMOJI: log.debug("Got delete reaction") return await message.delete() @@ -395,11 +390,6 @@ class ImagePaginator(Paginator): # Deletes the users reaction await message.remove_reaction(reaction.emoji, user) - # Clear reaction press - [:x:] - if reaction.emoji == CLEAR_EMOJI: - log.debug("Got clear reaction") - break - # Delete reaction press - [:trashcan:] if str(reaction.emoji) == DELETE_EMOJI: log.debug("Got delete reaction") -- cgit v1.2.3