Fix some buttons having priority

This commit is contained in:
Kai Vogelgesang 2022-10-29 13:09:39 +02:00
parent 003f9eb41c
commit fe6242cbbf

View File

@ -2,7 +2,6 @@ import asyncio
from datetime import datetime, timedelta
from dataclasses import dataclass
import random
from socket import socket
from typing import Callable, Awaitable
from fastapi import WebSocket, WebSocketDisconnect
@ -177,15 +176,13 @@ async def _(get_input: InputGetter, set_output: OutputSetter):
# cursed python syntax
vote["none"] += 1
max_choice = None
max_votes = -1
for (choice, votes) in vote.items():
if votes > max_votes:
max_votes = votes
max_choice = choice
max_vote = max(vote.values())
choice = random.choice(
[key for (key, value) in vote.items() if value == max_vote]
)
output = {button: False for button in Button}
if max_choice != "none":
output[max_choice] = True
if choice != "none":
output[choice] = True
set_output(output)