2020-10-14 02:50:24 +02:00
|
|
|
|
import discord
|
|
|
|
|
from discord.ext import commands
|
|
|
|
|
from random import randint
|
|
|
|
|
|
2020-11-09 09:56:57 +01:00
|
|
|
|
def setup(bot):
|
|
|
|
|
bot.add_cog(Help(bot))
|
2020-10-14 03:23:14 +02:00
|
|
|
|
|
2020-10-14 02:50:24 +02:00
|
|
|
|
class Help(commands.Cog):
|
2020-10-14 03:02:43 +02:00
|
|
|
|
"""Listes des commandes et/ou catégories."""
|
2020-10-14 02:50:24 +02:00
|
|
|
|
|
2020-10-14 03:02:43 +02:00
|
|
|
|
def __init__(self, bot):
|
|
|
|
|
self.bot = bot
|
2020-11-09 09:56:57 +01:00
|
|
|
|
self.bot.remove_command("help")
|
2020-10-14 02:50:24 +02:00
|
|
|
|
|
2020-11-24 09:23:24 +01:00
|
|
|
|
@commands.command(name='help')
|
|
|
|
|
async def _help(self, ctx, *cog):
|
2020-10-14 03:02:43 +02:00
|
|
|
|
"""Affiche toutes les commandes du bot.\n ➡ Syntaxe: .help [catégorie]"""
|
|
|
|
|
if not cog:
|
|
|
|
|
"""Liste des Cog"""
|
2020-11-09 09:56:57 +01:00
|
|
|
|
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.',
|
2020-10-14 03:02:43 +02:00
|
|
|
|
color = randint(0, 0xFFFFFF))
|
2020-11-09 09:56:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2020-12-11 15:46:30 +01:00
|
|
|
|
if name_cog != "Help" and nb_cmds > 0:
|
2020-11-09 09:56:57 +01:00
|
|
|
|
halp.add_field(name = f'**{name_cog} — {nb_cmds}**', value = liste_cmds[2:], inline = False)
|
|
|
|
|
|
|
|
|
|
|
2020-10-14 03:02:43 +02:00
|
|
|
|
cmds_desc = ''
|
|
|
|
|
for y in self.bot.walk_commands():
|
|
|
|
|
if not y.cog_name and not y.hidden:
|
2020-11-09 09:56:57 +01:00
|
|
|
|
cmds_desc += (f'{ctx.prefix}{y.name} - {y.help}\n ')
|
|
|
|
|
|
2020-10-14 03:02:43 +02:00
|
|
|
|
if len(cmds_desc) > 1:
|
2020-11-09 09:56:57 +01:00
|
|
|
|
halp.add_field(name = 'Commandes sans catégorie', value = cmds_desc[0:len(cmds_desc)-1], inline = False)
|
2020-10-14 03:02:43 +02:00
|
|
|
|
await ctx.message.add_reaction(emoji = '✅')
|
|
|
|
|
await ctx.send(embed = halp)
|
|
|
|
|
else:
|
|
|
|
|
"""Avertissement si il y a trop d'arguments dans la variable cog"""
|
|
|
|
|
if len(cog) > 1:
|
|
|
|
|
halp = discord.Embed(title = 'Erreur !', description = "Tu as renseigné trop d'arguments !", color = 0xC41B1B)
|
|
|
|
|
await ctx.send(embed = halp)
|
|
|
|
|
else:
|
|
|
|
|
"""Liste des commandes avec cogs."""
|
|
|
|
|
|
|
|
|
|
cog = [item.capitalize() for item in cog]
|
2020-10-14 02:50:24 +02:00
|
|
|
|
|
2020-10-14 03:02:43 +02:00
|
|
|
|
found = False
|
|
|
|
|
for x in self.bot.cogs:
|
|
|
|
|
for y in cog:
|
|
|
|
|
if x == y:
|
|
|
|
|
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:
|
2020-11-09 09:56:57 +01:00
|
|
|
|
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)
|
2020-10-14 03:02:43 +02:00
|
|
|
|
found = True
|
|
|
|
|
if not found:
|
|
|
|
|
"""Rappel si le cog n'existe pas."""
|
|
|
|
|
await ctx.message.add_reaction(emoji = '❌')
|
|
|
|
|
halp = discord.Embed(title = 'Erreur !', description = f"Qu'est ce que {cog[0]} ?", color = 0xC41B1B)
|
|
|
|
|
else:
|
|
|
|
|
await ctx.message.add_reaction(emoji = '✅')
|
2020-11-24 14:19:31 +01:00
|
|
|
|
await ctx.send('', embed = halp)
|