From f64f5ed78de30bd9a07c3b6a7a5178048deb1865 Mon Sep 17 00:00:00 2001 From: ddorn Date: Sat, 25 Apr 2020 20:26:56 +0200 Subject: [PATCH] :sparkles: handle same number draw --- tfjm-discord-bot.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tfjm-discord-bot.py b/tfjm-discord-bot.py index a001346..e6e6c11 100644 --- a/tfjm-discord-bot.py +++ b/tfjm-discord-bot.py @@ -3,6 +3,7 @@ import enum import os import sys import traceback +from collections import defaultdict from time import sleep from typing import List, Dict @@ -127,11 +128,29 @@ class OrderPhase(Phase): async def next(self, ctx) -> "Phase": orders = [team.tirage_order for team in self.teams.values()] - # Check that order is unique if len(set(orders)) == len(orders): + # All dice are different: good return self.NEXT else: - await ctx.send("crotte.") + # Find dice that are the same + count = defaultdict(list) + for team in self.teams.values: + count[team.tirage_order].append(team) + + re_do = [] + for dice, teams in count.items(): + if len(teams) > 1: + re_do.extend(teams) + + teams_str = ", ".join(team.role.mention for team in re_do) + await ctx.send( + f"Les equipes {teams_str} ont fait le même résultat " + "et doivent relancer un dé. " + "Le nouveau lancer effacera l'ancien." + ) + for team in re_do: + team.tirage_order = None + return self bot = commands.Bot(