♻️ Tirage.teams is now a list of teams

This commit is contained in:
ddorn 2020-04-25 20:32:14 +02:00
parent f64f5ed78d
commit cc5b31b9d6
1 changed files with 7 additions and 7 deletions

View File

@ -53,13 +53,13 @@ class Tirage:
assert len(teams) in (3, 4) assert len(teams) in (3, 4)
self.channel = channel self.channel = channel
self.teams = {team: Team(ctx, team) for team in teams} self.teams = [Team(ctx, team) for team in teams]
self.phase = OrderPhase(self) self.phase = OrderPhase(self)
def team_for(self, author): def team_for(self, author):
for team in self.teams: for team in self.teams:
if get(author.roles, name=team): if get(author.roles, name=team.name):
return self.teams[team] return team
# Should theoretically not happen # Should theoretically not happen
raise TfjmError( raise TfjmError(
@ -83,7 +83,7 @@ class Phase:
NEXT = None NEXT = None
def __init__(self, tirage): def __init__(self, tirage):
self.tirage = tirage self.tirage: Tirage = tirage
async def fais_pas_chier(self, ctx): async def fais_pas_chier(self, ctx):
await ctx.send( await ctx.send(
@ -124,17 +124,17 @@ class OrderPhase(Phase):
await ctx.send(f"{author.mention}: merci de ne lancer qu'un dé.") await ctx.send(f"{author.mention}: merci de ne lancer qu'un dé.")
def finished(self) -> bool: def finished(self) -> bool:
return all(team.tirage_order is not None for team in self.teams.values()) return all(team.tirage_order is not None for team in self.teams)
async def next(self, ctx) -> "Phase": async def next(self, ctx) -> "Phase":
orders = [team.tirage_order for team in self.teams.values()] orders = [team.tirage_order for team in self.teams]
if len(set(orders)) == len(orders): if len(set(orders)) == len(orders):
# All dice are different: good # All dice are different: good
return self.NEXT return self.NEXT
else: else:
# Find dice that are the same # Find dice that are the same
count = defaultdict(list) count = defaultdict(list)
for team in self.teams.values: for team in self.teams:
count[team.tirage_order].append(team) count[team.tirage_order].append(team)
re_do = [] re_do = []