mirror of
https://gitlab.com/ddorn/tfjm-discord-bot.git
synced 2024-12-25 06:22:21 +00:00
✨ help for group commands
This commit is contained in:
parent
f55084e33e
commit
731cae29bd
@ -47,7 +47,7 @@ class MiscCog(Cog, name="Divers"):
|
||||
msg = random.choice(jokes)
|
||||
await ctx.send(msg)
|
||||
|
||||
@command(name="help-test", aliases=["h"])
|
||||
@command(name="help", aliases=["h"])
|
||||
async def help_test(self, ctx: Context, *args):
|
||||
"""Affiche ce message"""
|
||||
|
||||
@ -99,11 +99,12 @@ class MiscCog(Cog, name="Divers"):
|
||||
name = " ".join(args)
|
||||
comm: Command = self.bot.get_command(name)
|
||||
if comm is None:
|
||||
await ctx.send(
|
||||
return await ctx.send(
|
||||
f"La commande `!{name}` n'existe pas. "
|
||||
f"Utilise `!help` pour une liste des commandes."
|
||||
)
|
||||
return
|
||||
elif isinstance(comm, Group):
|
||||
return await self.send_group_help(ctx, comm)
|
||||
|
||||
embed = discord.Embed(
|
||||
title=f"Aide pour la commande `!{comm.qualified_name}`",
|
||||
@ -123,6 +124,41 @@ class MiscCog(Cog, name="Divers"):
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
async def send_group_help(self, ctx, group: Group):
|
||||
embed = discord.Embed(
|
||||
title=f"Aide pour le groupe de commandes `!{group.qualified_name}`",
|
||||
description=group.help,
|
||||
color=0xFFA500,
|
||||
)
|
||||
|
||||
comms = await self.filter_commands(ctx, group.commands, sort=True)
|
||||
if not comms:
|
||||
embed.add_field(
|
||||
name="Désolé", value="Il n'y a aucune commande pour toi ici."
|
||||
)
|
||||
else:
|
||||
names = ["!" + c.qualified_name for c in comms]
|
||||
width = max(map(len, names))
|
||||
names = [name.rjust(width) for name in names]
|
||||
short_help = [c.short_doc for c in comms]
|
||||
|
||||
lines = [f"`{n}` - {h}" for n, h in zip(names, short_help)]
|
||||
|
||||
c: Command
|
||||
text = "\n".join(lines)
|
||||
embed.add_field(name="Sous-commandes", value=text, inline=False)
|
||||
|
||||
if group.aliases:
|
||||
aliases = ", ".join(f"`{a}`" for a in group.aliases)
|
||||
embed.add_field(name="Alias", value=aliases, inline=True)
|
||||
if group.signature:
|
||||
embed.add_field(
|
||||
name="Usage", value=f"`!{group.qualified_name} {group.signature}`"
|
||||
)
|
||||
embed.set_footer(text="Suggestion ? Problème ? Envoie un message à @Diego")
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
def _name(self, command: Command):
|
||||
return f"`!{command.qualified_name}`"
|
||||
|
||||
@ -152,7 +188,7 @@ class MiscCog(Cog, name="Divers"):
|
||||
"""
|
||||
|
||||
if sort and key is None:
|
||||
key = lambda c: c.name
|
||||
key = lambda c: c.qualified_name
|
||||
|
||||
iterator = (
|
||||
commands if self.show_hidden else filter(lambda c: not c.hidden, commands)
|
||||
|
@ -13,7 +13,8 @@ Team = namedtuple("Team", ["name", "trigram", "tournoi", "secret", "status"])
|
||||
|
||||
|
||||
class TeamsCog(Cog, name="Teams"):
|
||||
def __init__(self):
|
||||
def __init__(self, bot: Bot):
|
||||
self.bot = bot
|
||||
self.teams = self.load_teams()
|
||||
|
||||
def load_teams(self):
|
||||
@ -35,10 +36,12 @@ class TeamsCog(Cog, name="Teams"):
|
||||
teams.append((team, role))
|
||||
return teams
|
||||
|
||||
@group(name="team")
|
||||
@group(name="team", invoke_without_command=True)
|
||||
async def team(self, ctx):
|
||||
"""Groupe de commandes pour la gestion des équipes."""
|
||||
|
||||
await ctx.invoke(self.bot.get_command("help"), "team")
|
||||
|
||||
@team.command(name="create")
|
||||
async def create_team(self, ctx: Context, trigram, team_secret):
|
||||
"""
|
||||
@ -234,4 +237,4 @@ class TeamsCog(Cog, name="Teams"):
|
||||
|
||||
|
||||
def setup(bot: Bot):
|
||||
bot.add_cog(TeamsCog())
|
||||
bot.add_cog(TeamsCog(bot))
|
||||
|
@ -655,7 +655,9 @@ class TirageCog(Cog, name="Tirages"):
|
||||
|
||||
@group(name="draw", aliases=["d", "tirage"], invoke_without_command=True)
|
||||
async def draw_group(self, ctx: Context) -> None:
|
||||
"""Groupe de commandes pour les tirages. Détails: `!help draw`"""
|
||||
"""Groupe de commandes pour les tirages."""
|
||||
|
||||
await ctx.invoke(self.bot.get_command("help"), "draw")
|
||||
|
||||
@draw_group.command(
|
||||
name="start", usage="équipe1 équipe2 équipe3 (équipe4)",
|
||||
|
@ -61,6 +61,7 @@ async def on_command_error(ctx: Context, error, *args, **kwargs):
|
||||
await ctx.send(msg)
|
||||
|
||||
|
||||
bot.remove_command("help")
|
||||
bot.load_extension("src.cogs.tirages")
|
||||
bot.load_extension("src.cogs.teams")
|
||||
bot.load_extension("src.cogs.dev")
|
||||
|
Loading…
Reference in New Issue
Block a user