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 f7db834f3c
commit 3551068a3f
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) accept = await self.next(bool, team.name)
if accept.value: if accept.value:
team.accepted_problems[poule.rnd] = pevent.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: else:
await self.info_rejected(team, pevent.value, rnd=poule.rnd) await self.info_rejected(team, pevent.value, rnd=poule.rnd)
team.rejected[poule.rnd].add(pevent.value) team.rejected[poule.rnd].add(pevent.value)
@ -234,6 +236,33 @@ class BaseTirage(yaml.YAMLObject):
current += 1 current += 1
current %= len(teams) 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) await self.annonce_poule(poule)
async def draw_order(self, poule): async def draw_order(self, poule):
@ -292,7 +321,7 @@ class BaseTirage(yaml.YAMLObject):
async def info_draw_pb(self, team, pb, rnd): async def info_draw_pb(self, team, pb, rnd):
"""Called when a team draws a problem.""" """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.""" """Called when a team accepts a problem."""
async def info_rejected(self, team, pb, rnd): 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)) seed = seed or str(random.randint(0, 1_000_000_000))
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get( async with session.get(
FRACTAL_URL.format(seed=urllib.parse.quote(seed)) FRACTAL_URL.format(seed=urllib.parse.quote(seed)), timeout=120
) as resp: ) as resp:
if resp.status != 200: if resp.status != 200:
return await ctx.send( 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.") raise TfjmError("Il n'y a pas de blague avec cet ID.")
if joke.file: if joke.file:
file = discord.File(joke.file) file = discord.File(File.MEMES / joke.file)
else: else:
file = None file = None
@ -273,8 +273,8 @@ class MiscCog(Cog, name="Divers"):
if message.attachments: if message.attachments:
file: discord.Attachment = message.attachments[0] file: discord.Attachment = message.attachments[0]
joke.file = str(File.MEMES / f"{joke_id}-{file.filename}") joke.file = str(f"{joke_id}-{file.filename}")
await file.save(joke.file) await file.save(File.MEMES / joke.file)
jokes.append(joke) jokes.append(joke)
self.save_jokes(jokes) self.save_jokes(jokes)

View File

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

View File

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

View File

@ -34,9 +34,9 @@ if TOKEN is None:
GUILD = "690934836696973404" GUILD = "690934836696973404"
DIEGO = 430566197868625920 # Mon id DIEGO = 430566197868625920 # Mon id
BOT = 703305132300959754 BOT = 703305132300959754
TEAMS_CHANNEL_CATEGORY = "Channels d'équipes" TEAMS_CHANNEL_CATEGORY = "Channels d'équipes 2"
EMBED_COLOR = 0xFFA500 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 FRACTAL_COOLDOWN = 30 # seconds
ROUND_NAMES = ["premier tour", "deuxième tour"] ROUND_NAMES = ["premier tour", "deuxième tour"]