Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy fix:contestvote #980

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions cogs/contestvote/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def total_value(self):

def get_contribution_id(content: str) -> int:
"""extracts the contribution id from the string"""
contribution_id = re.match(r".*ID: (\d+).*", content).group(1)
return int(contribution_id)
contribution_id = re.match(r".*ID: (\d+).*", content)
if not contribution_id:
raise ValueError("No contribution id found")
return int(contribution_id.group(1))


async def get_top_contributions(emojis: dict, messages: list[disnake.Message], number_of: int) -> list[str]:
Expand All @@ -55,20 +57,22 @@ async def get_top_contributions(emojis: dict, messages: list[disnake.Message], n

# Create a dictionary to store all reactions for this message only once
reactions_list = {}
duplicate_votes = Counter()
duplicate_votes: Counter = Counter()
for r in message.reactions:
reactions_list[r] = {user.id for user in await r.users().flatten()}
duplicate_votes.update(user for user in reactions_list[r])
duplicate_votes = {user for user, count in duplicate_votes.items() if count > 1}
duplicate_user_votes = {user for user, count in duplicate_votes.items() if count > 1}

# iterate reactions and create Emoji objects for each reaction
for r, users in reactions_list.items():
users = users - duplicate_votes
users = users - duplicate_user_votes
emoji = utils.str_emoji_id(r.emoji)
if emoji in emojis:
emoji_obj = Emoji(emoji=emoji, count=len(users), value=emojis[emoji])
emojis_for_message.append(emoji_obj)
images.append(Image(message.jump_url, emojis_for_message, len(duplicate_votes) - 1)) # -1 for the bot
images.append(
Image(message.jump_url, emojis_for_message, len(duplicate_user_votes) - 1)
) # -1 for the bot

messages = []
# Sort the images by total_value in descending order and get the top n
Expand Down