show tirages for a team

This commit is contained in:
ddorn 2020-05-13 16:36:46 +02:00
parent eff492ceb8
commit 135724e87d
1 changed files with 13 additions and 11 deletions

View File

@ -14,7 +14,7 @@ from typing import Type, Dict, Union, Optional, List
import discord import discord
import yaml import yaml
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import group, Cog, Context from discord.ext.commands import group, Cog, Context, RoleConverter
from discord.utils import get from discord.utils import get
from src.base_tirage import BaseTirage, Event, Poule from src.base_tirage import BaseTirage, Event, Poule
@ -507,9 +507,10 @@ class TirageCog(Cog, name="Tirages"):
dice = random.randint(1, n) dice = random.randint(1, n)
return f"{ctx.author.mention} : {Emoji.DICE} {dice}" return f"{ctx.author.mention} : {Emoji.DICE} {dice}"
@commands.command(name="dice-all", aliases=["da"], hidden=True) @commands.command(name="dice-all", aliases=["da"])
@commands.has_role(Role.DEV) @commands.has_role(Role.DEV)
async def dice_all_cmd(self, ctx, *teams): async def dice_all_cmd(self, ctx, *teams):
"""Lance un dé pour chaque equipe afin de tester les tirages."""
channel = ctx.channel.id channel = ctx.channel.id
if channel in self.tirages: if channel in self.tirages:
for t in teams: for t in teams:
@ -626,10 +627,9 @@ class TirageCog(Cog, name="Tirages"):
channel_id = ctx.channel.id channel_id = ctx.channel.id
if channel_id in self.tirages: if channel_id in self.tirages:
print(self.tirages, channel_id) await ctx.send(f"Le tirage {self.tirages[channel_id].id} est annulé.")
print(self.tirages[channel_id]) self.tirages[channel_id].save()
del self.tirages[channel_id] del self.tirages[channel_id]
await ctx.send("Le tirage est annulé.")
else: else:
await ctx.send("Il n'y a pas de tirage en cours.") await ctx.send("Il n'y a pas de tirage en cours.")
@ -656,18 +656,14 @@ class TirageCog(Cog, name="Tirages"):
def get_tirages(self) -> Dict[int, BaseTirage]: def get_tirages(self) -> Dict[int, BaseTirage]:
return DiscordTirage.load_all() return DiscordTirage.load_all()
def save_tirages(self, tirages):
File.TIRAGES.touch()
with open(File.TIRAGES, "w") as f:
yaml.dump(tirages, f)
@draw_group.command(name="show") @draw_group.command(name="show")
async def show_cmd(self, ctx: Context, tirage_id: str = "all"): async def show_cmd(self, ctx: Context, tirage_id: str = "all"):
""" """
Affiche le résumé d'un tirage. Affiche le résumé d'un tirage.
Exemples: Exemples:
`!draw show all` - Liste les ID possible `!draw show all` - Liste les ID possibles
`!draw show TRI` - Affiche les tirages avec l'équipe TRI
`!draw show 42` - Affiche le tirage n°42 `!draw show 42` - Affiche le tirage n°42
""" """
@ -686,6 +682,12 @@ class TirageCog(Cog, name="Tirages"):
f"`{key}`: {', '.join(tirage.teams)}" for key, tirage in tirages.items() f"`{key}`: {', '.join(tirage.teams)}" for key, tirage in tirages.items()
) )
await ctx.send(msg) await ctx.send(msg)
elif len(tirage_id) == 3 and tirage_id.isupper():
for t in tirages.values():
for p, teams in t.poules.items():
if tirage_id in teams:
t.ctx = ctx
await t.annonce_poule(p)
else: else:
try: try:
n = int(tirage_id) n = int(tirage_id)