diff --git a/data/jokes b/data/jokes index 252e4a2..3de3eb2 100644 --- a/data/jokes +++ b/data/jokes @@ -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. ``` \ No newline at end of file diff --git a/src/cogs/__init__.py b/src/cogs/__init__.py index ba35cb1..3dc3149 100644 --- a/src/cogs/__init__.py +++ b/src/cogs/__init__.py @@ -4,4 +4,3 @@ of the TFJM² bot. """ from .tirages import TirageCog -from .help import TfjmHelpCommand diff --git a/src/cogs/errors.py b/src/cogs/errors.py index df560f3..d2eaf8c 100644 --- a/src/cogs/errors.py +++ b/src/cogs/errors.py @@ -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 ( diff --git a/src/cogs/misc.py b/src/cogs/misc.py index e67880b..955bac0 100644 --- a/src/cogs/misc.py +++ b/src/cogs/misc.py @@ -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)] diff --git a/src/cogs/teams.py b/src/cogs/teams.py index 321ff5c..9962f8b 100644 --- a/src/cogs/teams.py +++ b/src/cogs/teams.py @@ -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)) diff --git a/src/utils.py b/src/utils.py index 06c2096..6c44400 100644 --- a/src/utils.py +++ b/src/utils.py @@ -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