From fdca640285db3722e7456e635f78805a73f3deef Mon Sep 17 00:00:00 2001 From: Mega-JC <65417594+Mega-JC@users.noreply.github.com> Date: Mon, 1 Jul 2024 21:45:52 +0200 Subject: [PATCH] Only consider unique reactions in 'showcase rank' command in 'showcase' extension --- pcbot/exts/showcase.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pcbot/exts/showcase.py b/pcbot/exts/showcase.py index c981b84..9a32f8b 100644 --- a/pcbot/exts/showcase.py +++ b/pcbot/exts/showcase.py @@ -169,17 +169,25 @@ async def showcase_rank( ) ) - def count_thread_reactions( + async def count_unique_thread_reactions( thread: discord.Thread, starter_message: discord.Message ): - return ( - sum( + if rank_emoji: + return sum( reaction.count for reaction in starter_message.reactions if snakecore.utils.is_emoji_equal(rank_emoji, reaction.emoji) ) - if rank_emoji - else sum(reaction.count for reaction in starter_message.reactions) + + user_ids_by_reaction: dict[tuple[str, int], list[int]] = {} + + for i, reaction in enumerate(starter_message.reactions): + user_ids_by_reaction[str(reaction.emoji), i] = [ + user.id async for user in reaction.users() + ] + + return len( + set(itertools.chain.from_iterable(user_ids_by_reaction.values())) ) async def thread_triple(thread: discord.Thread): @@ -193,7 +201,7 @@ async def thread_triple(thread: discord.Thread): return ( thread, starter_message, - count_thread_reactions(thread, starter_message), + await count_unique_thread_reactions(thread, starter_message), ) max_archived_threads = max( @@ -261,7 +269,7 @@ async def thread_triple(thread: discord.Thread): ).timestamp() ) ) - + ">)", + + ">, based on unique reactions)", "color": self.theme_color.value, "fields": [], } @@ -276,7 +284,8 @@ async def thread_triple(thread: discord.Thread): + ( f"{rank_emoji}: {thread_reactions_count}" if rank_emoji - else ", ".join( + else f"{thread_reactions_count}: Unique | " + + ", ".join( f"{reaction.emoji}: {reaction.count}" for reaction in starter_message.reactions )