2020-11-29 11:39:41 +01:00
import discord
from discord . ext import commands
2021-05-31 23:17:21 +02:00
from discord_slash import cog_ext
2020-11-29 11:39:41 +01:00
def setup ( client ) :
client . add_cog ( Help ( client ) )
class Help ( commands . Cog ) :
2021-05-31 23:47:02 +02:00
""" Commandes relatives à l ' aide utilisateur. """
2020-11-29 11:39:41 +01:00
def __init__ ( self , client ) :
self . client = client
self . client . remove_command ( " help " )
@commands.command ( name = ' help ' )
async def _help ( self , ctx , * cog ) :
2021-05-15 20:22:14 +02:00
""" Affiche toutes les commandes du bot. \n ➡ Syntaxe: {PREFIX} help [catégorie] """
2021-05-31 23:17:21 +02:00
fromSlash = False
if len ( cog ) > 0 :
if cog [ - 1 ] == True :
fromSlash = cog [ - 1 ]
cog = cog [ : - 1 ]
if not cog : # Liste des Cog
halp = discord . Embed ( title = ' Liste des catégories et commandes sans catégorie ' ,
2020-11-29 11:39:41 +01:00
description = f ' Utilisez ` { ctx . prefix } help [catégorie]` pour en savoir plus sur elles et leur commande. ' ,
2021-02-22 02:39:01 +01:00
color = discord . Colour . random ( ) )
2020-11-29 11:39:41 +01:00
for name_cog in self . client . cogs :
liste_cmds = " "
nb_cmds = 0
for cmds in self . client . get_cog ( name_cog ) . get_commands ( ) :
if not cmds . hidden :
liste_cmds + = f " , ` { ctx . prefix } { cmds . name } ` "
nb_cmds + = 1
2020-12-11 11:58:31 +01:00
if name_cog != " Help " and nb_cmds > 0 :
2021-05-31 23:17:21 +02:00
halp . add_field ( name = f ' ** { name_cog } ( { nb_cmds } ) — { self . client . cogs [ name_cog ] . __doc__ } ** ' , value = liste_cmds [ 2 : ] , inline = False )
2020-11-29 11:39:41 +01:00
cmds_desc = ' '
for y in self . client . walk_commands ( ) :
if not y . cog_name and not y . hidden :
cmds_desc + = ( f ' { ctx . prefix } { y . name } - { y . help } \n ' )
if len ( cmds_desc ) > 1 :
halp . add_field ( name = ' Commandes sans catégorie ' , value = cmds_desc [ 0 : len ( cmds_desc ) - 1 ] , inline = False )
2021-05-31 23:17:21 +02:00
if fromSlash != True :
await ctx . message . add_reaction ( emoji = ' ✅ ' )
2020-11-29 11:39:41 +01:00
await ctx . send ( embed = halp )
2021-05-31 23:17:21 +02:00
else : # Avertissement si il y a trop d'arguments dans la variable cog
2020-11-29 11:39:41 +01:00
if len ( cog ) > 1 :
halp = discord . Embed ( title = ' Erreur ! ' , description = " Tu as renseigné trop d ' arguments ! " , color = 0xC41B1B )
await ctx . send ( embed = halp )
2021-05-31 23:17:21 +02:00
else : # Liste des commandes avec cogs.
2020-11-29 11:39:41 +01:00
cog = [ item . capitalize ( ) for item in cog ]
found = False
for x in self . client . cogs :
for y in cog :
if x == y :
2021-02-22 02:39:01 +01:00
halp = discord . Embed ( title = f ' { cog [ 0 ] } - Liste des commandes ' , description = self . client . cogs [ cog [ 0 ] ] . __doc__ , color = discord . Colour . random ( ) )
2020-11-29 11:39:41 +01:00
for c in self . client . get_cog ( y ) . get_commands ( ) :
if not c . hidden :
2021-05-15 20:22:14 +02:00
cmds_help = str ( c . help ) . replace ( " {PREFIX} " , ctx . prefix ) . split ( " \n " )
2020-11-29 11:39:41 +01:00
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
2021-05-31 23:17:21 +02:00
if not found : # Rappel si le cog n'existe pas.
2020-11-29 11:39:41 +01:00
await ctx . message . add_reaction ( emoji = ' ❌ ' )
halp = discord . Embed ( title = ' Erreur ! ' , description = f " Qu ' est ce que { cog [ 0 ] } ? " , color = 0xC41B1B )
else :
2021-05-31 23:17:21 +02:00
if fromSlash != True :
await ctx . message . add_reaction ( emoji = ' ✅ ' )
2020-11-29 11:59:49 +01:00
await ctx . send ( ' ' , embed = halp )
2021-05-31 23:17:21 +02:00
@cog_ext.cog_slash ( name = " help " , description = " Envois un meme de reddit. " )
async def __help ( self , ctx , cog = None ) :
ctx . prefix = " / "
if cog == None :
return await self . _help ( ctx , True )
else :
return await self . _help ( ctx , cog , True )
2021-05-31 23:47:02 +02:00
@commands.command ( name = ' invite ' )
async def _invite ( self , ctx , fromSlash = None ) :
""" Invite ce bot sur ton serveur ! """
if fromSlash == None :
fromSlash = False
2021-05-31 23:51:02 +02:00
embed = discord . Embed ( description = f " [Lien vers l ' invitation Discord](https://discord.com/api/oauth2/authorize?client_id= { self . client . user . id } &permissions=8&scope=bot%20applications.commands) " ) . set_author ( name = " Invite moi ! " )
2021-05-31 23:47:02 +02:00
if fromSlash != True :
await ctx . message . add_reaction ( emoji = ' ✅ ' )
return await ctx . send ( embed = embed )
@cog_ext.cog_slash ( name = " invite " , description = " Invite ce bot sur ton serveur ! " )
async def __invite ( self , ctx ) :
return await self . _invite ( ctx , True )