From 87cd31e1af470d5ac52beb1edbb9e552eed9ece1 Mon Sep 17 00:00:00 2001 From: F4zii Date: Sun, 16 Feb 2020 18:22:40 +0200 Subject: Fix the Pagination cog When using pagination in the Reddit cog, clicking the LAST_EMOJI would raise an exception like this: TypeError: unsupported operand type(s) for -: 'list' and 'int' This was resolved by taking the subtraction out of the len() function. --- bot/pagination.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/pagination.py') diff --git a/bot/pagination.py b/bot/pagination.py index f1233482..1858bd2d 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -389,7 +389,7 @@ class ImagePaginator(Paginator): log.debug("Got last page reaction, but we're on the last page - ignoring") continue - current_page = len(paginator.pages - 1) + current_page = len(paginator.pages) - 1 reaction_type = "last" # Previous reaction press - [:arrow_left: ] -- cgit v1.2.3 From 4ba52054c86e293eeec8730d4d338dbb6f375522 Mon Sep 17 00:00:00 2001 From: F4zii Date: Sun, 16 Feb 2020 21:38:09 +0200 Subject: Paginator Migration - Emoji and actions Switched the emoji used to clear the reactions of a paginator [":x:"] With [":trashcan:"], Clicking on this emoji deletes the message --- bot/pagination.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'bot/pagination.py') diff --git a/bot/pagination.py b/bot/pagination.py index 1858bd2d..841e33eb 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -10,7 +10,7 @@ FIRST_EMOJI = "\u23EE" # [:track_previous:] LEFT_EMOJI = "\u2B05" # [:arrow_left:] RIGHT_EMOJI = "\u27A1" # [:arrow_right:] LAST_EMOJI = "\u23ED" # [:track_next:] -DELETE_EMOJI = "\u274c" # [:x:] +DELETE_EMOJI = "<:trashcan:637136429717389331>" # [:trashcan:] PAGINATION_EMOJI = [FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, DELETE_EMOJI] @@ -113,7 +113,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, # Note: DELETE_EMOJI is a string and not unicode # Reaction was not made by the Bot user_.id != ctx.bot.user.id, # There were no restrictions @@ -185,7 +185,7 @@ 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: + if str(reaction.emoji) == DELETE_EMOJI: # Note: DELETE_EMOJI is a string and not unicode log.debug("Got delete reaction") break @@ -261,8 +261,8 @@ class LinePaginator(Paginator): await message.edit(embed=embed) - log.debug("Ending pagination and removing all reactions...") - await message.clear_reactions() + log.debug("Ending pagination and deleting the message") + await message.delete() class ImagePaginator(Paginator): @@ -323,7 +323,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, # Note: DELETE_EMOJI is a string and not unicode # The reactor is not a bot not member.bot )) @@ -369,8 +369,8 @@ class ImagePaginator(Paginator): # Deletes the users reaction await message.remove_reaction(reaction.emoji, user) - # Delete reaction press - [:x:] - if reaction.emoji == DELETE_EMOJI: + # Delete reaction press - [:trashcan:] + if str(reaction.emoji) == DELETE_EMOJI: # Note: DELETE_EMOJI is a string and not unicode log.debug("Got delete reaction") break @@ -424,5 +424,5 @@ class ImagePaginator(Paginator): await message.edit(embed=embed) - log.debug("Ending pagination and removing all reactions...") - await message.clear_reactions() + log.debug("Ending pagination and deleting the message") + await message.delete() -- cgit v1.2.3 From cd4841aa6407ab6bece89d12d9645dab56f18d89 Mon Sep 17 00:00:00 2001 From: F4zi <44242259+F4zi780@users.noreply.github.com> Date: Mon, 17 Feb 2020 11:35:14 +0200 Subject: Pagination migrations - Actions and emojis Clicking on [:trashcan:] broke the loop and deleted the message, instead, now we return after a message deletion and break when an `asyncio.TimeoutError` is raised (when a user fails to add reactions in time) --- bot/pagination.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'bot/pagination.py') diff --git a/bot/pagination.py b/bot/pagination.py index 841e33eb..b5bb1720 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -187,7 +187,7 @@ class LinePaginator(Paginator): if str(reaction.emoji) == DELETE_EMOJI: # Note: DELETE_EMOJI is a string and not unicode log.debug("Got delete reaction") - break + return await message.delete() if reaction.emoji == FIRST_EMOJI: await message.remove_reaction(reaction.emoji, user) @@ -261,8 +261,8 @@ class LinePaginator(Paginator): await message.edit(embed=embed) - log.debug("Ending pagination and deleting the message") - await message.delete() + log.debug("Ending pagination and clearing reactions...") + await message.clear_reactions() class ImagePaginator(Paginator): @@ -372,7 +372,7 @@ class ImagePaginator(Paginator): # Delete reaction press - [:trashcan:] if str(reaction.emoji) == DELETE_EMOJI: # Note: DELETE_EMOJI is a string and not unicode log.debug("Got delete reaction") - break + return await message.delete() # First reaction press - [:track_previous:] if reaction.emoji == FIRST_EMOJI: @@ -424,5 +424,5 @@ class ImagePaginator(Paginator): await message.edit(embed=embed) - log.debug("Ending pagination and deleting the message") - await message.delete() + log.debug("Ending pagination and clearing reactions...") + await message.clear_reactions() -- cgit v1.2.3 From c1fe1a989d1d9035bc32b1f6e789f2a82bbadab8 Mon Sep 17 00:00:00 2001 From: F4zi <44242259+F4zi780@users.noreply.github.com> Date: Mon, 17 Feb 2020 12:36:20 +0200 Subject: Pagination migrations - Data Structure Modified Changed the pagination emoji collection from list to tuple This change was suggested since this collection is constant --- bot/pagination.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/pagination.py') diff --git a/bot/pagination.py b/bot/pagination.py index b5bb1720..a024e0d9 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -12,7 +12,7 @@ RIGHT_EMOJI = "\u27A1" # [:arrow_right:] LAST_EMOJI = "\u23ED" # [:track_next:] DELETE_EMOJI = "<:trashcan:637136429717389331>" # [:trashcan:] -PAGINATION_EMOJI = [FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, DELETE_EMOJI] +PAGINATION_EMOJI = (FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, DELETE_EMOJI) log = logging.getLogger(__name__) -- cgit v1.2.3 From 08c4d7f4883df94f6f63f27d1531d881cf33f1e5 Mon Sep 17 00:00:00 2001 From: F4zii Date: Mon, 17 Feb 2020 16:52:31 +0200 Subject: Paginator Migration - Added trashcan emoji to constants.py --- bot/constants.py | 1 + bot/pagination.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'bot/pagination.py') diff --git a/bot/constants.py b/bot/constants.py index eca4f67b..be92770d 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -88,6 +88,7 @@ class Emojis: christmas_tree = "\U0001F384" check = "\u2611" envelope = "\U0001F4E8" + trashcan = "<:trashcan:678677706652647506>" terning1 = "<:terning1:431249668983488527>" terning2 = "<:terning2:462339216987127808>" diff --git a/bot/pagination.py b/bot/pagination.py index a024e0d9..c77ad571 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -5,12 +5,13 @@ from typing import Iterable, List, Optional, Tuple from discord import Embed, Member, Reaction from discord.abc import User from discord.ext.commands import Context, Paginator +from bot.constants import Emojis FIRST_EMOJI = "\u23EE" # [:track_previous:] LEFT_EMOJI = "\u2B05" # [:arrow_left:] RIGHT_EMOJI = "\u27A1" # [:arrow_right:] LAST_EMOJI = "\u23ED" # [:track_next:] -DELETE_EMOJI = "<:trashcan:637136429717389331>" # [:trashcan:] +DELETE_EMOJI = Emojis.trashcan # [:trashcan:] PAGINATION_EMOJI = (FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, DELETE_EMOJI) -- cgit v1.2.3 From 7ec299251afd794d10e82e66fd9cb4c9c0f744ea Mon Sep 17 00:00:00 2001 From: F4zii Date: Mon, 17 Feb 2020 17:11:37 +0200 Subject: Paginator Migration - Added trashcan emoji to constants.py --- bot/constants.py | 1 + bot/pagination.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'bot/pagination.py') diff --git a/bot/constants.py b/bot/constants.py index eca4f67b..2c68f719 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -88,6 +88,7 @@ class Emojis: christmas_tree = "\U0001F384" check = "\u2611" envelope = "\U0001F4E8" + trashcan = "<:trashcan:637136429717389331>" terning1 = "<:terning1:431249668983488527>" terning2 = "<:terning2:462339216987127808>" diff --git a/bot/pagination.py b/bot/pagination.py index a024e0d9..9a7a0382 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -6,11 +6,13 @@ from discord import Embed, Member, Reaction from discord.abc import User from discord.ext.commands import Context, Paginator +from bot.constants import Emojis + FIRST_EMOJI = "\u23EE" # [:track_previous:] LEFT_EMOJI = "\u2B05" # [:arrow_left:] RIGHT_EMOJI = "\u27A1" # [:arrow_right:] LAST_EMOJI = "\u23ED" # [:track_next:] -DELETE_EMOJI = "<:trashcan:637136429717389331>" # [:trashcan:] +DELETE_EMOJI = Emojis.trashcan # [:trashcan:] PAGINATION_EMOJI = (FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, DELETE_EMOJI) -- cgit v1.2.3 From 3e10585525ccf6fca5c5174f1077d0f6ecbf0622 Mon Sep 17 00:00:00 2001 From: F4zii Date: Mon, 17 Feb 2020 17:29:02 +0200 Subject: Lint error - missing line --- bot/pagination.py | 1 - 1 file changed, 1 deletion(-) (limited to 'bot/pagination.py') diff --git a/bot/pagination.py b/bot/pagination.py index f8fa538c..9a7a0382 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -5,7 +5,6 @@ from typing import Iterable, List, Optional, Tuple from discord import Embed, Member, Reaction from discord.abc import User from discord.ext.commands import Context, Paginator -from bot.constants import Emojis from bot.constants import Emojis -- cgit v1.2.3