✨ teams now use roles as input
This commit is contained in:
parent
d6133b3eea
commit
20eac4a4a7
|
@ -2,7 +2,10 @@
|
|||
import asyncio
|
||||
import random
|
||||
from collections import defaultdict, namedtuple
|
||||
from typing import Type
|
||||
from contextlib import redirect_stdout
|
||||
from io import BytesIO, StringIO
|
||||
from pprint import pprint
|
||||
from typing import Type, TextIO
|
||||
|
||||
import discord
|
||||
import yaml
|
||||
|
@ -22,9 +25,9 @@ def in_passage_order(teams, round=0):
|
|||
class Team(yaml.YAMLObject):
|
||||
yaml_tag = "Team"
|
||||
|
||||
def __init__(self, ctx, name):
|
||||
self.name = name
|
||||
self.mention = get(ctx.guild.roles, name=name).mention
|
||||
def __init__(self, ctx, team_role):
|
||||
self.name = team_role.name
|
||||
self.mention = team_role.mention
|
||||
self.tirage_order = [None, None]
|
||||
self.passage_order = [None, None]
|
||||
|
||||
|
@ -32,6 +35,14 @@ class Team(yaml.YAMLObject):
|
|||
self.drawn_problem = None # Waiting to be accepted or refused
|
||||
self.rejected = [set(), set()]
|
||||
|
||||
def __str__(self):
|
||||
s = StringIO()
|
||||
pprint(self.__dict__, stream=s)
|
||||
s.seek(0)
|
||||
return s.read()
|
||||
|
||||
__repr__ = __str__
|
||||
|
||||
def coeff(self, round):
|
||||
if len(self.rejected[round]) <= MAX_REFUSE:
|
||||
return 2
|
||||
|
@ -105,6 +116,7 @@ class Tirage(yaml.YAMLObject):
|
|||
await self.phase.start(ctx)
|
||||
|
||||
async def end(self, ctx):
|
||||
self.phase = None
|
||||
if False:
|
||||
# Allow everyone to send messages again
|
||||
send = discord.PermissionOverwrite() # reset
|
||||
|
@ -116,12 +128,14 @@ class Tirage(yaml.YAMLObject):
|
|||
tl = list(yaml.load_all(f))
|
||||
else:
|
||||
TIRAGES_FILE.touch()
|
||||
|
||||
pprint(self.__dict__)
|
||||
tl.append(self)
|
||||
with open(TIRAGES_FILE, "w") as f:
|
||||
yaml.dump_all(tl, f)
|
||||
|
||||
await ctx.send(
|
||||
f"A tout moment, ce rapport peut être envoyé avec `!show {len(tl) - 1}`"
|
||||
f"A tout moment, ce rapport peut être envoyé avec `!draw show {len(tl) - 1}`"
|
||||
)
|
||||
|
||||
async def show(self, ctx):
|
||||
|
|
|
@ -97,11 +97,13 @@ class TirageCog(Cog, name="Tirages"):
|
|||
async def draw_group(self, ctx: Context) -> None:
|
||||
"""Groupe de commandes pour les tirages."""
|
||||
|
||||
print("WTFF")
|
||||
|
||||
@draw_group.command(
|
||||
name="start", usage="équipe1 équipe2 équipe3 (équipe4)",
|
||||
)
|
||||
@commands.has_role(Role.ORGA)
|
||||
async def start(self, ctx: Context, *teams):
|
||||
async def start(self, ctx: Context, *teams: discord.Role):
|
||||
"""
|
||||
Commence un tirage avec 3 ou 4 équipes.
|
||||
|
||||
|
@ -119,13 +121,6 @@ class TirageCog(Cog, name="Tirages"):
|
|||
if len(teams) not in (3, 4):
|
||||
raise TfjmError("Il faut 3 ou 4 équipes pour un tirage.")
|
||||
|
||||
roles = {role.name for role in ctx.guild.roles}
|
||||
for team in teams:
|
||||
if team not in roles:
|
||||
raise TfjmError(
|
||||
"Le nom de l'équipe doit être exactement celui du rôle."
|
||||
)
|
||||
|
||||
# Here all data should be valid
|
||||
|
||||
# Prevent everyone from writing except Capitaines, Orga, CNO, Benevole
|
||||
|
@ -172,7 +167,7 @@ class TirageCog(Cog, name="Tirages"):
|
|||
|
||||
@draw_group.command(name="skip", aliases=["s"])
|
||||
@commands.has_role(Role.DEV)
|
||||
async def draw_skip(self, ctx, *teams):
|
||||
async def draw_skip(self, ctx, *teams: discord.Role):
|
||||
"""Skip certaines phases du tirage."""
|
||||
channel = ctx.channel.id
|
||||
self.tirages[channel] = tirage = Tirage(ctx, channel, teams)
|
||||
|
@ -207,13 +202,14 @@ class TirageCog(Cog, name="Tirages"):
|
|||
tirages = list(yaml.load_all(f))
|
||||
|
||||
if tirage_id.lower() == "all":
|
||||
msg = "\n".join(
|
||||
f"{i}: {', '.join(team.name for team in tirage.teams)}"
|
||||
for i, tirage in enumerate(tirages)
|
||||
)
|
||||
await ctx.send(
|
||||
"Voici in liste de tous les tirages qui ont été faits. "
|
||||
"Vous pouvez en consulter un en particulier avec `!show ID`."
|
||||
"Voici in liste de tous les tirages qui ont été faits et "
|
||||
"quelles équipes y on participé."
|
||||
"Vous pouvez en consulter un en particulier avec `!draw show ID`."
|
||||
)
|
||||
msg = "\n".join(
|
||||
f"`{i}`: {', '.join(team.name for team in tirage.teams)}"
|
||||
for i, tirage in enumerate(tirages)
|
||||
)
|
||||
await ctx.send(msg)
|
||||
else:
|
||||
|
@ -225,7 +221,7 @@ class TirageCog(Cog, name="Tirages"):
|
|||
except (ValueError, IndexError):
|
||||
await ctx.send(
|
||||
f"`{tirage_id}` n'est pas un identifiant valide. "
|
||||
f"Les identifiants valides sont visibles avec `!show all`"
|
||||
f"Les identifiants valides sont visibles avec `!draw show all`"
|
||||
)
|
||||
else:
|
||||
await tirage.show(ctx)
|
||||
|
|
Loading…
Reference in New Issue