1+ import discord
2+ from discord import app_commands
3+ from discord .ext import commands
4+
5+ from src .utils import Embeds , Error
6+
7+
8+ class Help (commands .Cog ):
9+ """
10+ Sends this help message
11+ """
12+
13+ def __init__ (self , client ):
14+ self .client = client
15+ client .remove_command ('help' )
16+
17+ @commands .hybrid_command (
18+ name = 'help' ,
19+ description = 'Sends the Help Command' ,
20+ with_app_command = True ,
21+ required = True
22+ )
23+ @app_commands .describe (
24+ query = 'Module\' s or Command\' s name'
25+ )
26+ @commands .cooldown (1 , 15 )
27+ async def help (self , ctx , query : str = None ):
28+ """Shows all modules of that bot"""
29+
30+ embed = Embeds (
31+ title = 'Commands' ,
32+ description = f'Use `/help <module>` or `/help <command>` for more information about that module or command\n \u200d '
33+ )
34+ embed .color = discord .Color .blurple ()
35+
36+ if not query :
37+ available_cogs = []
38+ for cog in self .client .cogs :
39+ available_commands = []
40+ for cmd in self .client .get_cog (cog ).walk_commands ():
41+ if not cmd .hidden and not str (cmd .help ).startswith ('hidden' ) and await cmd .can_run (ctx ):
42+ available_commands .append (cmd )
43+
44+ if len (available_commands ) > 0 :
45+ available_cogs .append (cog )
46+
47+ embed .add_field (
48+ name = 'Modules' ,
49+ value = '\n \u200d \n ' .join (
50+ f'**{ cog } **\n ```{ str (self .client .cogs [cog ].__doc__ ).lstrip ().rstrip ()} ```' for cog in available_cogs if (
51+ not str (self .client .cogs [cog ].__doc__ ).startswith ('hidden' )
52+ )
53+ ),
54+ inline = False
55+ )
56+
57+ else :
58+ found = False
59+ async def add_to_embed (cmd ):
60+ if await cmd .can_run (ctx ):
61+ embed .add_field (
62+ name = f'/{ cmd .qualified_name } ' ,
63+ value = f'{ str (cmd .help ).lstrip ().rstrip ()} \n ' ,
64+ inline = False
65+ )
66+
67+ for cog in self .client .cogs :
68+ if query .lower () == cog .lower () and not str (self .client .cogs [cog ].__doc__ ).startswith ('hidden' ):
69+ embed .description += f'\n **{ cog } \' s commands**\n \u200d '
70+ available_commands_cog = []
71+
72+ for cmd in self .client .get_cog (cog ).walk_commands ():
73+ if (not cmd .hidden and not str (cmd .help ).startswith ('hidden' )) and await cmd .can_run (ctx ):
74+ available_commands_cog .append (cmd )
75+
76+ if len (available_commands_cog ) > 0 :
77+ for i in available_commands_cog : await add_to_embed (i )
78+ found = True
79+ break
80+
81+ elif not str (self .client .cogs [cog ].__doc__ ).startswith ('hidden' ):
82+ for cmd in self .client .get_cog (cog ).walk_commands ():
83+ if (not cmd .hidden and not str (cmd .help ).startswith ('hidden' )):
84+ if query .lower ().strip () in cmd .qualified_name .lower ().strip ():
85+ found = True
86+ await add_to_embed (cmd )
87+
88+ if found : break
89+ if not found :
90+ raise Error (description = f'Unable to locate module or command [{ query } ]' )
91+
92+ await ctx .reply (embed = embed )
93+
94+
95+ async def setup (client ):
96+ await client .add_cog (Help (client ))
0 commit comments