add teams list

This commit is contained in:
ddorn 2020-04-29 18:43:07 +02:00
parent 7b86be7e23
commit 0ab729afb3
6 changed files with 49 additions and 4 deletions

View File

@ -5,4 +5,10 @@
- 56
- Mais c'est faux !
- Oui mais c'est rapide !
```
```
Q: Why did the chicken cross the mobius strip?
A: To get to the same side.
```

View File

@ -4,4 +4,3 @@ of the TFJM² bot.
"""
from .tirages import TirageCog
from .help import TfjmHelpCommand

View File

@ -66,7 +66,7 @@ class ErrorsCog(Cog):
specific_handler = handlers.get(type(error.original))
if specific_handler:
return await specific_handler(ctx, error)
return await specific_handler(self, ctx, error)
traceback.print_tb(error.original.__traceback__, file=sys.stderr)
return (

View File

@ -2,10 +2,12 @@ import itertools
import random
import datetime
from operator import attrgetter
from pprint import pprint
from time import time
import discord
from discord import Guild
from discord.ext import commands
from discord.ext.commands import (
Cog,
command,
@ -52,8 +54,9 @@ class MiscCog(Cog, name="Divers"):
await ctx.send(msg)
@command(name="status")
@commands.has_role(Role.CNO)
async def status_cmd(self, ctx: Context):
"""Affiche des informations à propos du serveur."""
"""(cno) Affiche des informations à propos du serveur."""
guild: Guild = ctx.guild
embed = discord.Embed(title="État du serveur", color=EMBED_COLOR)
benevoles = [g for g in guild.members if has_role(g, Role.BENEVOLE)]

View File

@ -7,7 +7,7 @@ from discord.ext.commands import Cog, Bot, group, Context
from discord.utils import get, find
from src.constants import *
from src.utils import has_role
Team = namedtuple("Team", ["name", "trigram", "tournoi", "secret", "status"])
@ -235,6 +235,27 @@ class TeamsCog(Cog, name="Teams"):
reason=f"{ctx.author.name} à demandé un salon vocale pour son équipe.",
)
@team.command(name="list")
@commands.has_role(Role.CNO)
async def list_cmd(self, ctx):
"""(cno) Affiche les équipes de chaque tournoi présentes sur le discord."""
embed = discord.Embed(title="Liste des équipes", color=EMBED_COLOR)
captains = [m for m in ctx.guild.members if has_role(m, Role.CAPTAIN)]
tournois = {
tournoi: [c for c in captains if has_role(c, tournoi)]
for tournoi in TOURNOIS
}
for tournoi, caps in tournois.items():
# we assume captains have exactly one team.
txt = "\n".join(self.teams_for(c)[0][0].trigram for c in caps)
txt = txt or "Il n'y a pas encore d'équipes sur le discord."
embed.add_field(name=tournoi, value=txt)
await ctx.send(embed=embed)
def setup(bot: Bot):
bot.add_cog(TeamsCog(bot))

View File

@ -1,4 +1,20 @@
from discord import Message
from discord.ext.commands import Context, Bot
def has_role(member, role: str):
"""Return whether the member has a role with this name."""
return any(r.name == role for r in member.roles)
async def send_and_bin(bot: Bot, ctx: Context, msg=None, *, embed=None):
"""Send a message and wait 5min for the author to delete it."""
message: Message = await ctx.send(msg, embed=embed)
await msg
def setup(bot):
bot.send_and_bin = send_and_bin