From 3a8f388a94a6c9a1676a5e2b990e634435807c1a Mon Sep 17 00:00:00 2001 From: ddorn Date: Thu, 30 Apr 2020 00:53:34 +0200 Subject: [PATCH] :sparkles: use embed for tirage resume --- src/cogs/tirages.py | 46 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/cogs/tirages.py b/src/cogs/tirages.py index 385f3be..f170ea1 100644 --- a/src/cogs/tirages.py +++ b/src/cogs/tirages.py @@ -54,8 +54,21 @@ class Team(yaml.YAMLObject): return 2 - 0.5 * (len(self.rejected[round]) - MAX_REFUSE) def details(self, round): - return f"""{self.mention}: - - Accepté: {self.accepted_problems[round]} + + info = { + # "Accepté": self.accepted_problems[round], + "Refusés": ", ".join(p[0] for p in self.rejected[round]) + if self.rejected[round] + else "aucun", + "Coefficient": self.coeff(round), + # "Ordre passage": self.passage_order[round], + } + + width = max(map(len, info)) + + return "\n".join(f"`{n.rjust(width)}`: {v}" for n, v in info.items()) + + return f""" - Accepté: {self.accepted_problems[round]} - Refusés: {", ".join(p[0] for p in self.rejected[round]) if self.rejected[round] else "aucun"} - Coefficient: {self.coeff(round)} - Ordre au tirage: {self.tirage_order[round]} @@ -160,8 +173,7 @@ class Tirage(yaml.YAMLObject): ] async def show(self, ctx): - teams = ", ".join(team.mention for team in self.teams) - msg = f"Voici un résumé du tirage entre les équipes {teams}." + teams = ", ".join(team.name for team in self.teams) if len(self.teams) == 3: table = """``` @@ -192,13 +204,25 @@ class Tirage(yaml.YAMLObject): +-----+---------+---------+---------+---------+ ```""" - await ctx.send(msg) - for round in (0, 1): - msg = f"\n\n**{ROUND_NAMES[round].capitalize()}**:\n" - msg += table.format(*self.records(round)) + "\n" - for team in self.teams: - msg += team.details(round) - await ctx.send(msg) + embed = discord.Embed( + title=f"Résumé du tirage entre {teams}", color=EMBED_COLOR + ) + + for r in (0, 1): + embed.add_field( + name=ROUND_NAMES[r].capitalize(), + value=table.format(*self.records(r)), + inline=False, + ) + + for team in in_passage_order(self.teams, r): + embed.add_field( + name=team.name + " - " + team.accepted_problems[r], + value=team.details(r), + inline=True, + ) + + await ctx.send(embed=embed) async def show_tex(self, ctx): if len(self.teams) == 3: