From da6eca03ee05b794c8d2ded6a0874266cded8804 Mon Sep 17 00:00:00 2001 From: Anri Kennel Date: Mon, 9 Nov 2020 09:56:57 +0100 Subject: [PATCH] Help : Affichage des commandes directement, meilleur organisation --- cogs/help.py | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/cogs/help.py b/cogs/help.py index 8770a8b..c9de194 100755 --- a/cogs/help.py +++ b/cogs/help.py @@ -2,34 +2,44 @@ import discord from discord.ext import commands from random import randint -# il y a deja une commande help de base mais celle ci est + jolie +def setup(bot): + bot.add_cog(Help(bot)) class Help(commands.Cog): """Listes des commandes et/ou catégories.""" def __init__(self, bot): self.bot = bot + self.bot.remove_command("help") @commands.command() async def help(self, ctx, *cog): """Affiche toutes les commandes du bot.\n ➡ Syntaxe: .help [catégorie]⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" if not cog: """Liste des Cog""" - halp=discord.Embed(title = 'Liste des catégories et commandes non catégorisées', - description = 'Utilisez `.help *Catégorie*` pour en savoir plus sur eux !', + halp=discord.Embed(title = 'Liste des catégories et commandes sans catégorie', + description = f'Utilisez `{ctx.prefix}help [catégorie]` pour en savoir plus sur elles et leur commande.', color = randint(0, 0xFFFFFF)) - # liste des cogs - cogs_desc = '' - for x in self.bot.cogs: - cogs_desc += (f'{x} - {self.bot.cogs[x].__doc__}\n') - halp.add_field(name = 'Catégories', value = cogs_desc[0:len(cogs_desc)-1], inline = False) - # liste des commandes dans main.py + + + for name_cog in self.bot.cogs: + liste_cmds = "" + nb_cmds = 0 + for cmds in self.bot.get_cog(name_cog).get_commands(): + if not cmds.hidden: + liste_cmds += f", `{ctx.prefix}{cmds.name}`" + nb_cmds += 1 + if name_cog != "Help": + halp.add_field(name = f'**{name_cog} — {nb_cmds}**', value = liste_cmds[2:], inline = False) + + cmds_desc = '' for y in self.bot.walk_commands(): if not y.cog_name and not y.hidden: - cmds_desc += (f'.{y.name} - {y.help}\n ⁢⁢⁢⁢⁢ ') + cmds_desc += (f'{ctx.prefix}{y.name} - {y.help}\n ⁢⁢⁢⁢⁢ ') + if len(cmds_desc) > 1: - halp.add_field(name = 'Commandes sans catégories', value = cmds_desc[0:len(cmds_desc)-1], inline = False) + halp.add_field(name = 'Commandes sans catégorie', value = cmds_desc[0:len(cmds_desc)-1], inline = False) await ctx.message.add_reaction(emoji = '✅') await ctx.send(embed = halp) else: @@ -49,7 +59,10 @@ class Help(commands.Cog): halp = discord.Embed(title = f'{cog[0]} - Liste des commandes', description = self.bot.cogs[cog[0]].__doc__, color = randint(0, 0xFFFFFF)) for c in self.bot.get_cog(y).get_commands(): if not c.hidden: - halp.add_field(name = f".{c.name}", value = f"{c.help}\n ⁢⁢⁢⁢⁢ ", inline = False) + cmds_help = str(c.help).split("\n") + del cmds_help[0] + backslash = '\n' + halp.add_field(name = f"`{ctx.prefix}{c.name}` - {str(c.help).split(backslash)[0]}", value = f"{''.join(cmds_help)}\u200b", inline = False) found = True if not found: """Rappel si le cog n'existe pas.""" @@ -57,7 +70,4 @@ class Help(commands.Cog): halp = discord.Embed(title = 'Erreur !', description = f"Qu'est ce que {cog[0]} ?", color = 0xC41B1B) else: await ctx.message.add_reaction(emoji = '✅') - await ctx.send('', embed = halp) - -def setup(bot): - bot.add_cog(Help(bot)) \ No newline at end of file + await ctx.send('', embed = halp) \ No newline at end of file