Skip to content

Commit

Permalink
Only consider unique reactions in 'showcase rank' command in 'showcas…
Browse files Browse the repository at this point in the history
…e' extension
  • Loading branch information
Mega-JC committed Jul 1, 2024
1 parent 16bfbd0 commit fdca640
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions pcbot/exts/showcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(
Expand Down Expand Up @@ -261,7 +269,7 @@ async def thread_triple(thread: discord.Thread):
).timestamp()
)
)
+ ">)",
+ ">, based on unique reactions)",
"color": self.theme_color.value,
"fields": [],
}
Expand All @@ -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
)
Expand Down

0 comments on commit fdca640

Please sign in to comment.