Fix voting logic to trigger exactly at threshold

Co-authored-by: kuhyx <147418882+kuhyx@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-01 15:19:13 +00:00
parent 19744c86f0
commit ff599df6c7

12
main.py
View File

@ -63,8 +63,8 @@ class VotingSystem:
self.votes[command][user_uuid] = current_time
vote_count = len(self.votes[command])
# Check if we just reached the threshold
newly_passed = vote_count >= self.REQUIRED_VOTES and not already_voted
# Check if we just reached the threshold (exactly equals, not >=)
newly_passed = vote_count == self.REQUIRED_VOTES and not already_voted
return vote_count, newly_passed
@ -262,7 +262,9 @@ async def trigger_command(message_content, recipient, user_uuid=None):
async def handle_voting_command(command, user_uuid, recipient):
"""Handle commands that require voting."""
global last_command_time, warning_sent
vote_count, newly_passed = voting_system.add_vote("traps", user_uuid)
# Use a normalized command key for voting (both !trap and !traps map to same vote)
vote_key = "traps"
vote_count, newly_passed = voting_system.add_vote(vote_key, user_uuid)
required = VotingSystem.REQUIRED_VOTES
timeout = VotingSystem.VOTE_TIMEOUT_MINUTES
@ -277,13 +279,13 @@ async def handle_voting_command(command, user_uuid, recipient):
send_message(f"Głosowanie zakończone! ({vote_count}/{required}) Wysyłam obrazek...", recipient)
await send_trap_image(recipient)
voting_system.reset_votes("traps")
voting_system.reset_votes(vote_key)
last_command_time = current_time
warning_sent = False
elif vote_count >= required:
# Already passed in a previous vote, just inform
send_message("Już wysłano obrazek. Głosowanie zresetowane.", recipient)
voting_system.reset_votes("traps")
voting_system.reset_votes(vote_key)
else:
remaining_votes = required - vote_count
send_message(