✨ teams now use roles as input
This commit is contained in:
parent
d6133b3eea
commit
20eac4a4a7
|
@ -2,7 +2,10 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import random
|
import random
|
||||||
from collections import defaultdict, namedtuple
|
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 discord
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -22,9 +25,9 @@ def in_passage_order(teams, round=0):
|
||||||
class Team(yaml.YAMLObject):
|
class Team(yaml.YAMLObject):
|
||||||
yaml_tag = "Team"
|
yaml_tag = "Team"
|
||||||
|
|
||||||
def __init__(self, ctx, name):
|
def __init__(self, ctx, team_role):
|
||||||
self.name = name
|
self.name = team_role.name
|
||||||
self.mention = get(ctx.guild.roles, name=name).mention
|
self.mention = team_role.mention
|
||||||
self.tirage_order = [None, None]
|
self.tirage_order = [None, None]
|
||||||
self.passage_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.drawn_problem = None # Waiting to be accepted or refused
|
||||||
self.rejected = [set(), set()]
|
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):
|
def coeff(self, round):
|
||||||
if len(self.rejected[round]) <= MAX_REFUSE:
|
if len(self.rejected[round]) <= MAX_REFUSE:
|
||||||
return 2
|
return 2
|
||||||
|
@ -105,6 +116,7 @@ class Tirage(yaml.YAMLObject):
|
||||||
await self.phase.start(ctx)
|
await self.phase.start(ctx)
|
||||||
|
|
||||||
async def end(self, ctx):
|
async def end(self, ctx):
|
||||||
|
self.phase = None
|
||||||
if False:
|
if False:
|
||||||
# Allow everyone to send messages again
|
# Allow everyone to send messages again
|
||||||
send = discord.PermissionOverwrite() # reset
|
send = discord.PermissionOverwrite() # reset
|
||||||
|
@ -116,12 +128,14 @@ class Tirage(yaml.YAMLObject):
|
||||||
tl = list(yaml.load_all(f))
|
tl = list(yaml.load_all(f))
|
||||||
else:
|
else:
|
||||||
TIRAGES_FILE.touch()
|
TIRAGES_FILE.touch()
|
||||||
|
|
||||||
|
pprint(self.__dict__)
|
||||||
tl.append(self)
|
tl.append(self)
|
||||||
with open(TIRAGES_FILE, "w") as f:
|
with open(TIRAGES_FILE, "w") as f:
|
||||||
yaml.dump_all(tl, f)
|
yaml.dump_all(tl, f)
|
||||||
|
|
||||||
await ctx.send(
|
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):
|
async def show(self, ctx):
|
||||||
|
|
|
@ -97,11 +97,13 @@ class TirageCog(Cog, name="Tirages"):
|
||||||
async def draw_group(self, ctx: Context) -> None:
|
async def draw_group(self, ctx: Context) -> None:
|
||||||
"""Groupe de commandes pour les tirages."""
|
"""Groupe de commandes pour les tirages."""
|
||||||
|
|
||||||
|
print("WTFF")
|
||||||
|
|
||||||
@draw_group.command(
|
@draw_group.command(
|
||||||
name="start", usage="équipe1 équipe2 équipe3 (équipe4)",
|
name="start", usage="équipe1 équipe2 équipe3 (équipe4)",
|
||||||
)
|
)
|
||||||
@commands.has_role(Role.ORGA)
|
@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.
|
Commence un tirage avec 3 ou 4 équipes.
|
||||||
|
|
||||||
|
@ -119,13 +121,6 @@ class TirageCog(Cog, name="Tirages"):
|
||||||
if len(teams) not in (3, 4):
|
if len(teams) not in (3, 4):
|
||||||
raise TfjmError("Il faut 3 ou 4 équipes pour un tirage.")
|
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
|
# Here all data should be valid
|
||||||
|
|
||||||
# Prevent everyone from writing except Capitaines, Orga, CNO, Benevole
|
# 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"])
|
@draw_group.command(name="skip", aliases=["s"])
|
||||||
@commands.has_role(Role.DEV)
|
@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."""
|
"""Skip certaines phases du tirage."""
|
||||||
channel = ctx.channel.id
|
channel = ctx.channel.id
|
||||||
self.tirages[channel] = tirage = Tirage(ctx, channel, teams)
|
self.tirages[channel] = tirage = Tirage(ctx, channel, teams)
|
||||||
|
@ -207,13 +202,14 @@ class TirageCog(Cog, name="Tirages"):
|
||||||
tirages = list(yaml.load_all(f))
|
tirages = list(yaml.load_all(f))
|
||||||
|
|
||||||
if tirage_id.lower() == "all":
|
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(
|
await ctx.send(
|
||||||
"Voici in liste de tous les tirages qui ont été faits. "
|
"Voici in liste de tous les tirages qui ont été faits et "
|
||||||
"Vous pouvez en consulter un en particulier avec `!show ID`."
|
"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)
|
await ctx.send(msg)
|
||||||
else:
|
else:
|
||||||
|
@ -225,7 +221,7 @@ class TirageCog(Cog, name="Tirages"):
|
||||||
except (ValueError, IndexError):
|
except (ValueError, IndexError):
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
f"`{tirage_id}` n'est pas un identifiant valide. "
|
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:
|
else:
|
||||||
await tirage.show(ctx)
|
await tirage.show(ctx)
|
||||||
|
|
Loading…
Reference in New Issue