mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-07-04 13:43:12 +02:00
Fix voting logic to trigger exactly at threshold
Co-authored-by: kuhyx <147418882+kuhyx@users.noreply.github.com>
This commit is contained in:
parent
19744c86f0
commit
ff599df6c7
12
main.py
12
main.py
@ -63,8 +63,8 @@ class VotingSystem:
|
|||||||
self.votes[command][user_uuid] = current_time
|
self.votes[command][user_uuid] = current_time
|
||||||
|
|
||||||
vote_count = len(self.votes[command])
|
vote_count = len(self.votes[command])
|
||||||
# Check if we just reached the threshold
|
# Check if we just reached the threshold (exactly equals, not >=)
|
||||||
newly_passed = vote_count >= self.REQUIRED_VOTES and not already_voted
|
newly_passed = vote_count == self.REQUIRED_VOTES and not already_voted
|
||||||
|
|
||||||
return vote_count, newly_passed
|
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):
|
async def handle_voting_command(command, user_uuid, recipient):
|
||||||
"""Handle commands that require voting."""
|
"""Handle commands that require voting."""
|
||||||
global last_command_time, warning_sent
|
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
|
required = VotingSystem.REQUIRED_VOTES
|
||||||
timeout = VotingSystem.VOTE_TIMEOUT_MINUTES
|
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)
|
send_message(f"Głosowanie zakończone! ({vote_count}/{required}) Wysyłam obrazek...", recipient)
|
||||||
await send_trap_image(recipient)
|
await send_trap_image(recipient)
|
||||||
voting_system.reset_votes("traps")
|
voting_system.reset_votes(vote_key)
|
||||||
last_command_time = current_time
|
last_command_time = current_time
|
||||||
warning_sent = False
|
warning_sent = False
|
||||||
elif vote_count >= required:
|
elif vote_count >= required:
|
||||||
# Already passed in a previous vote, just inform
|
# Already passed in a previous vote, just inform
|
||||||
send_message("Już wysłano obrazek. Głosowanie zresetowane.", recipient)
|
send_message("Już wysłano obrazek. Głosowanie zresetowane.", recipient)
|
||||||
voting_system.reset_votes("traps")
|
voting_system.reset_votes(vote_key)
|
||||||
else:
|
else:
|
||||||
remaining_votes = required - vote_count
|
remaining_votes = required - vote_count
|
||||||
send_message(
|
send_message(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user