From bfb32b95c12a465b60943e527e83bd7d5fdc4b95 Mon Sep 17 00:00:00 2001 From: Daniel Brown Date: Wed, 25 Sep 2019 13:34:16 -0500 Subject: Free Command Fix - Fixed bug where if two channels had the same last message timestamp the command would error out. Signed-off-by: Daniel Brown --- bot/cogs/free.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/cogs/free.py b/bot/cogs/free.py index 167fab319..ec8834240 100644 --- a/bot/cogs/free.py +++ b/bot/cogs/free.py @@ -7,7 +7,6 @@ from discord.ext.commands import Bot, Cog, Context, command from bot.constants import Categories, Channels, Free, STAFF_ROLES from bot.decorators import redirect_output - log = logging.getLogger(__name__) TIMEOUT = Free.activity_timeout @@ -51,10 +50,10 @@ class Free(Cog): # the command was invoked in if channel.id == ctx.channel.id: messages = await channel.history(limit=seek).flatten() - msg = messages[seek-1] + msg = messages[seek - 1] # Otherwise get last message else: - msg = await channel.history(limit=1).next() # noqa (False positive) + msg = await channel.history(limit=1).next() # noqa (False positive) inactive = (datetime.utcnow() - msg.created_at).seconds if inactive > TIMEOUT: @@ -80,7 +79,8 @@ class Free(Cog): # Sort channels in descending order by seconds # Get position in list, inactivity, and channel object # For each channel, add to embed.description - for i, (inactive, channel) in enumerate(sorted(free_channels, reverse=True), 1): + for i, (inactive, channel) in enumerate( + sorted(free_channels, key=lambda free_channel: free_channel[0], reverse=True), 1): minutes, seconds = divmod(inactive, 60) if minutes > 59: hours, minutes = divmod(minutes, 60) -- cgit v1.2.3