poules à 5

+ 120s timeout for fracals
+ relative path for memes
This commit is contained in:
ddorn 2020-05-13 15:49:00 +02:00
parent 56915d54b9
commit eff492ceb8
5 changed files with 85 additions and 28 deletions

View File

@ -226,7 +226,9 @@ class BaseTirage(yaml.YAMLObject):
accept = await self.next(bool, team.name)
if accept.value:
team.accepted_problems[poule.rnd] = pevent.value
await self.info_accepted(team, pevent.value)
await self.info_accepted(
team, pevent.value, self.availaible(pevent.value, poule)
)
else:
await self.info_rejected(team, pevent.value, rnd=poule.rnd)
team.rejected[poule.rnd].add(pevent.value)
@ -234,6 +236,33 @@ class BaseTirage(yaml.YAMLObject):
current += 1
current %= len(teams)
if len(teams) == 5:
# We can determine the passage order only once problems are drawn.
order = [self.teams[tri] for tri in self.poules[poule]]
pbs = [team.accepted_problems[poule.rnd] for team in order]
doubles = []
i = 0
while i < len(order):
team = order[i]
if pbs.count(team.accepted_problems[poule.rnd]) == 2:
# We pop the two with the same pb and add them to the doubles
doubles.append(order.pop(i))
other = next(
filter(
lambda t: team.accepted_problems[poule.rnd]
== t.accepted_problems[poule.rnd],
order,
)
)
doubles.append(other)
order.remove(other)
else:
i += 1
# The conflicts
order = doubles + order
self.poules[poule] = order
await self.annonce_poule(poule)
async def draw_order(self, poule):
@ -292,7 +321,7 @@ class BaseTirage(yaml.YAMLObject):
async def info_draw_pb(self, team, pb, rnd):
"""Called when a team draws a problem."""
async def info_accepted(self, team, pb):
async def info_accepted(self, team, pb, still_available):
"""Called when a team accepts a problem."""
async def info_rejected(self, team, pb, rnd):

View File

@ -115,7 +115,7 @@ class MiscCog(Cog, name="Divers"):
seed = seed or str(random.randint(0, 1_000_000_000))
async with aiohttp.ClientSession() as session:
async with session.get(
FRACTAL_URL.format(seed=urllib.parse.quote(seed))
FRACTAL_URL.format(seed=urllib.parse.quote(seed)), timeout=120
) as resp:
if resp.status != 200:
return await ctx.send(
@ -247,7 +247,7 @@ class MiscCog(Cog, name="Divers"):
raise TfjmError("Il n'y a pas de blague avec cet ID.")
if joke.file:
file = discord.File(joke.file)
file = discord.File(File.MEMES / joke.file)
else:
file = None
@ -273,8 +273,8 @@ class MiscCog(Cog, name="Divers"):
if message.attachments:
file: discord.Attachment = message.attachments[0]
joke.file = str(File.MEMES / f"{joke_id}-{file.filename}")
await file.save(joke.file)
joke.file = str(f"{joke_id}-{file.filename}")
await file.save(File.MEMES / joke.file)
jokes.append(joke)
self.save_jokes(jokes)

View File

@ -279,7 +279,9 @@ class TeamsCog(Cog, name="Teams"):
channel_name,
overwrites={
guild.default_role: discord.PermissionOverwrite(read_messages=False),
team_role: discord.PermissionOverwrite(read_messages=True),
team_role: discord.PermissionOverwrite(
read_messages=True, manage_channels=True
),
},
category=team_channel_category,
reason=f"{ctx.author.name} à demandé une channel pour son équipe.",

View File

@ -273,17 +273,17 @@ class DiscordTirage(BaseTirage):
if len(teams) == 3:
table = """```
+-----+---------+---------+---------+
| | Phase 1 | Phase 2 | Phase 3 |
| | Pb {0.pb} | Pb {1.pb} | Pb {2.pb} |
+-----+---------+---------+---------+
| {0.name} | Déf | Rap | Opp |
+-----+---------+---------+---------+
| {1.name} | Opp | Déf | Rap |
+-----+---------+---------+---------+
| {2.name} | Rap | Opp | Déf |
+-----+---------+---------+---------+```"""
else:
Phase 1 Phase 2 Phase 3
Pb {0.pb} Pb {0.pb} Pb {0.pb}
{0.name} Def Rap Opp
{1.name} Opp Def Rap
{2.name} Rap Opp Def
```"""
elif len(teams) == 4:
table = """```
+-----+---------+---------+---------+---------+
| | Phase 1 | Phase 2 | Phase 3 | Phase 4 |
@ -297,6 +297,26 @@ class DiscordTirage(BaseTirage):
+-----+---------+---------+---------+---------+
| {3.name} | | Rap | Opp | Déf |
+-----+---------+---------+---------+---------+```"""
elif len(teams) == 5:
table = """```
Phase 1 Phase 2 Phase 3
Salle 1 Salle 2 Salle 1 Salle 2 Salle 1
Pb {0.pb} Pb {1.pb} Pb {2.pb} Pb {3.pb} Pb {4.pb}
{0.name} Def Opp Rap
{1.name} Def Rap Opp
{2.name} Opp Def Rap
{3.name} Rap Opp Def
{4.name} Rap Opp Def
```"""
else:
table = "WTF il n'y a pas 3,4 ou 5 equipes ici."
embed = discord.Embed(
title=f"Résumé du tirage entre {french_join([t.name for t in teams])}",
@ -389,12 +409,18 @@ class DiscordTirage(BaseTirage):
)
@safe
async def info_accepted(self, team, pb):
await self.ctx.send(
f"L'équipe {team.mention} a accepté "
f"**{pb}** ! Les autres équipes "
f"ne peuvent plus l'accepter."
)
async def info_accepted(self, team, pb, still_available):
if still_available:
await self.ctx.send(
f"L'équipe {team.mention} a accepté "
f"**{pb}** ! Une autre équipe peut encore l'accepter."
)
else:
await self.ctx.send(
f"L'équipe {team.mention} a accepté "
f"**{pb}** ! Les autres équipes "
f"ne peuvent plus l'accepter."
)
@safe
async def info_rejected(self, team, pb, rnd):
@ -574,8 +600,8 @@ class TirageCog(Cog, name="Tirages"):
"par exemple `3+3` pour deux poules à trois équipes"
)
if not set(fmt).issubset({3, 4}):
raise TfjmError("Seuls les poules à 3 ou 4 équipes sont suportées.")
if not set(fmt).issubset({3, 4, 5}):
raise TfjmError("Seuls les poules à 3, 4 ou 5 équipes sont suportées.")
# Here all data should be valid

View File

@ -34,9 +34,9 @@ if TOKEN is None:
GUILD = "690934836696973404"
DIEGO = 430566197868625920 # Mon id
BOT = 703305132300959754
TEAMS_CHANNEL_CATEGORY = "Channels d'équipes"
TEAMS_CHANNEL_CATEGORY = "Channels d'équipes 2"
EMBED_COLOR = 0xFFA500
FRACTAL_URL = "https://thefractal.space/img/{seed}.png?size=1500"
FRACTAL_URL = "https://thefractal.space/img/{seed}.png?size=1000"
FRACTAL_COOLDOWN = 30 # seconds
ROUND_NAMES = ["premier tour", "deuxième tour"]