diff --git a/deploy/bots.py b/deploy/bots.py index 9453451..f5e1ce8 100644 --- a/deploy/bots.py +++ b/deploy/bots.py @@ -176,15 +176,20 @@ async def _tegn_player(ws_base, code, name, n_players, done, rng, stop_at_final) return task = me.get("task") key = (st["phase"], (st.get("step") or {}).get("index")) - await asyncio.sleep(rng.uniform(0.05, 0.4)) + # Tænkepausen kun før en handling: under afsløringen kommer der mange snapshots, og en bot, + # der sover efter hvert, når ikke at læse dem (og serverens ping) i tide. + pause = lambda: asyncio.sleep(rng.uniform(0.05, 0.4)) # noqa: E731 if st["phase"] == "lobby" and me["vip"] and len(st["players"]) >= n_players and key not in acted: acted.add(key) + await pause() await ws.send(json.dumps({"action": "start"})) elif st["phase"] == "theme" and me.get("can_choose") and key not in acted: acted.add(key) + await pause() await ws.send(json.dumps({"action": "choose_theme", "theme_id": rng.choice(st["theme"]["options"])["id"]})) elif task and not task["done"] and key not in acted: acted.add(key) + await pause() if task["kind"] == "word": if rng.random() < 0.3: await ws.send(json.dumps({"action": "suggest"})) # svaret afleveres, når det kommer @@ -205,7 +210,6 @@ async def _tegn_player(ws_base, code, name, n_players, done, rng, stop_at_final) if st["phase"] == "reveal" and rng.random() < 0.2: await ws.send(json.dumps({"action": "react", "emoji": rng.choice(st.get("reactions") or ["😂"])})) - async def main(): ap = argparse.ArgumentParser() ap.add_argument("--base", default="http://127.0.0.1:8000")