mirror of
				https://gitlab.com/ddorn/tfjm-discord-bot.git
				synced 2025-10-31 00:59:51 +01:00 
			
		
		
		
	✨ only one fractal at a time
This commit is contained in:
		| @@ -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,16 +103,11 @@ 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() |         try: | ||||||
|         else: |             self.computing = True | ||||||
|             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) |             await ctx.message.add_reaction(Emoji.CHECK) | ||||||
|             msg: discord.Message = ctx.message |             msg: discord.Message = ctx.message | ||||||
| @@ -128,10 +123,10 @@ class MiscCog(Cog, name="Divers"): | |||||||
|                         ) |                         ) | ||||||
|                     data = io.BytesIO(await resp.read()) |                     data = io.BytesIO(await resp.read()) | ||||||
|                     await ctx.send( |                     await ctx.send( | ||||||
|                     f"Seed: {seed}", file=discord.File(data, "cool_image.png") |                         f"Seed: {seed}", file=discord.File(data, f"{seed}.png") | ||||||
|                     ) |                     ) | ||||||
|  |         finally: | ||||||
|                 self.last_fractal_time = time() |             self.computing = False | ||||||
|  |  | ||||||
|     @command(hidden=True, aliases=["bang", "pan"]) |     @command(hidden=True, aliases=["bang", "pan"]) | ||||||
|     async def pew(self, ctx): |     async def pew(self, ctx): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user