✨ only one fractal at a time
This commit is contained in:
parent
9dc5b0f221
commit
56915d54b9
|
@ -95,6 +95,16 @@ class BaseTirage(yaml.YAMLObject):
|
||||||
self.poules: Dict[Poule, List[str]] = {}
|
self.poules: Dict[Poule, List[str]] = {}
|
||||||
"""A mapping between the poule and the list of teams in this poule."""
|
"""A mapping between the poule and the list of teams in this poule."""
|
||||||
|
|
||||||
|
def availaible(self, pb, poule):
|
||||||
|
pbs = [
|
||||||
|
self.teams[team].accepted_problems[poule.rnd] for team in self.poules[poule]
|
||||||
|
]
|
||||||
|
|
||||||
|
if len(self.poules[poule]) < 5:
|
||||||
|
return pb not in pbs
|
||||||
|
else:
|
||||||
|
return pbs.count(pb) < 2
|
||||||
|
|
||||||
async def event(self, event: Event):
|
async def event(self, event: Event):
|
||||||
event.set()
|
event.set()
|
||||||
await self.queue.put(event)
|
await self.queue.put(event)
|
||||||
|
@ -113,11 +123,10 @@ class BaseTirage(yaml.YAMLObject):
|
||||||
else:
|
else:
|
||||||
return await self.warn_wrong_team(None, trigram)
|
return await self.warn_wrong_team(None, trigram)
|
||||||
|
|
||||||
other_pbs = [self.teams[team].accepted_problems[rnd] for team in teams]
|
|
||||||
available = [
|
available = [
|
||||||
pb
|
pb
|
||||||
for pb in PROBLEMS
|
for pb in PROBLEMS
|
||||||
if pb not in team.accepted_problems and pb not in other_pbs
|
if pb not in team.accepted_problems and self.availaible(pb, poule)
|
||||||
]
|
]
|
||||||
return await self.event(Event(trigram, random.choice(available)))
|
return await self.event(Event(trigram, random.choice(available)))
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ class MiscCog(Cog, name="Divers"):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.show_hidden = False
|
self.show_hidden = False
|
||||||
self.verify_checks = True
|
self.verify_checks = True
|
||||||
self.last_fractal_time = 0.0
|
self.computing = False
|
||||||
|
|
||||||
@command(
|
@command(
|
||||||
name="choose",
|
name="choose",
|
||||||
|
@ -103,35 +103,30 @@ class MiscCog(Cog, name="Divers"):
|
||||||
@command(hidden=True)
|
@command(hidden=True)
|
||||||
async def fractal(self, ctx: Context):
|
async def fractal(self, ctx: Context):
|
||||||
|
|
||||||
if time() > self.last_fractal_time + FRACTAL_COOLDOWN or has_role(
|
if self.computing:
|
||||||
ctx.author, Role.DEV
|
return await ctx.send("Il y a déjà une fractale en cours de calcul...")
|
||||||
):
|
|
||||||
self.last_fractal_time = time()
|
|
||||||
else:
|
|
||||||
return await ctx.send(
|
|
||||||
f"Merci de ne pas générer plus d'une fractale "
|
|
||||||
f"toutes les {FRACTAL_COOLDOWN} secondes :wink: "
|
|
||||||
f"Il reste {round(FRACTAL_COOLDOWN - (time() - self.last_fractal_time), 1)}s."
|
|
||||||
)
|
|
||||||
|
|
||||||
await ctx.message.add_reaction(Emoji.CHECK)
|
try:
|
||||||
msg: discord.Message = ctx.message
|
self.computing = True
|
||||||
seed = msg.content[len("!fractal ") :]
|
|
||||||
seed = seed or str(random.randint(0, 1_000_000_000))
|
await ctx.message.add_reaction(Emoji.CHECK)
|
||||||
async with aiohttp.ClientSession() as session:
|
msg: discord.Message = ctx.message
|
||||||
async with session.get(
|
seed = msg.content[len("!fractal ") :]
|
||||||
FRACTAL_URL.format(seed=urllib.parse.quote(seed))
|
seed = seed or str(random.randint(0, 1_000_000_000))
|
||||||
) as resp:
|
async with aiohttp.ClientSession() as session:
|
||||||
if resp.status != 200:
|
async with session.get(
|
||||||
return await ctx.send(
|
FRACTAL_URL.format(seed=urllib.parse.quote(seed))
|
||||||
"Il y a un problème pour calculer/télécharger l'image..."
|
) as resp:
|
||||||
|
if resp.status != 200:
|
||||||
|
return await ctx.send(
|
||||||
|
"Il y a un problème pour calculer/télécharger l'image..."
|
||||||
|
)
|
||||||
|
data = io.BytesIO(await resp.read())
|
||||||
|
await ctx.send(
|
||||||
|
f"Seed: {seed}", file=discord.File(data, f"{seed}.png")
|
||||||
)
|
)
|
||||||
data = io.BytesIO(await resp.read())
|
finally:
|
||||||
await ctx.send(
|
self.computing = False
|
||||||
f"Seed: {seed}", file=discord.File(data, "cool_image.png")
|
|
||||||
)
|
|
||||||
|
|
||||||
self.last_fractal_time = time()
|
|
||||||
|
|
||||||
@command(hidden=True, aliases=["bang", "pan"])
|
@command(hidden=True, aliases=["bang", "pan"])
|
||||||
async def pew(self, ctx):
|
async def pew(self, ctx):
|
||||||
|
|
Loading…
Reference in New Issue