@@ -28,41 +28,33 @@ def __init__(self, bot):
28
28
def format_cog_help (self , ctx , cog ):
29
29
"""Formats the text for a cog help"""
30
30
31
- maxlen = 0
32
31
prefix = self .bot .prefix
33
32
34
- for cmd in self .bot .commands :
35
- if cmd .hidden :
36
- continue
37
- if cmd .instance is cog :
38
- len_ = len (cmd .qualified_name ) + len (prefix )
39
- if len_ > maxlen :
40
- maxlen = len_
33
+ fmts = ['' ]
34
+ for cmd in sorted (self .bot .commands ,
35
+ key = lambda cmd : cmd .qualified_name ):
36
+ if cmd .instance is cog and not cmd .hidden :
37
+ new_fmt = f'`{ prefix + cmd .qualified_name } ` - { cmd .short_doc } \n '
38
+ if len (new_fmt ) + len (fmts [- 1 ]) >= 1024 :
39
+ fmts .append (new_fmt )
40
+ else :
41
+ fmts [- 1 ] += new_fmt
41
42
42
- if maxlen == 0 :
43
- return
44
-
45
- fmt = ''
46
- for cmd in self .bot .commands :
47
- if cmd .instance is cog :
48
- if cmd .hidden :
49
- continue
50
-
51
- fmt += f'`{ prefix + cmd .qualified_name :<{maxlen }} ` - '
52
- fmt += f'{ cmd .short_doc :<{maxlen }} \n '
53
-
54
- em = Embed (
55
- description = '*' + inspect .getdoc (cog ) + '*' ,
56
- color = Color .blurple ()
57
- )
58
- em .set_author (name = cog .__class__ .__name__ + ' - Help' ,
59
- icon_url = ctx .bot .user .avatar_url )
43
+ embeds = []
44
+ for fmt in fmts :
45
+ em = Embed (
46
+ description = '*' + inspect .getdoc (cog ) + '*' ,
47
+ color = Color .blurple ()
48
+ )
60
49
61
- em .add_field (name = 'Commands' , value = fmt )
50
+ em .add_field (name = 'Commands' , value = fmt )
51
+ em .set_author (name = cog .__class__ .__name__ + ' - Help' ,
52
+ icon_url = ctx .bot .user .avatar_url )
62
53
63
- em .set_footer (text = f'Type "{ prefix } help command" '
64
- 'for more info on a command.' )
65
- return em
54
+ em .set_footer (text = f'Type "{ prefix } help command" '
55
+ 'for more info on a command.' )
56
+ embeds .append (em )
57
+ return embeds
66
58
67
59
def format_command_help (self , ctx , cmd ):
68
60
"""Formats command help."""
@@ -72,27 +64,22 @@ def format_command_help(self, ctx, cmd):
72
64
description = cmd .help
73
65
)
74
66
75
- if hasattr (cmd , 'invoke_without_command' ) and \
76
- cmd .invoke_without_command :
77
- em .title = f'`Usage: { prefix } { cmd .signature } `'
78
- else :
79
- em .title = f'`{ prefix } { cmd .signature } `'
67
+ em .title = f'`{ prefix } { cmd .signature } `'
80
68
81
- if not hasattr (cmd , ' commands' ):
69
+ if not isinstance (cmd , commands . Group ):
82
70
return em
83
71
84
- maxlen = max (len (prefix + str (c )) for c in cmd .commands )
85
72
fmt = ''
86
-
87
- for i , c in enumerate (cmd .commands ):
88
- if len (cmd .commands ) == i + 1 : # last
89
- branch = '└─ ' + c .name
73
+ length = len (cmd .all_commands )
74
+ for i , (name , c ) in enumerate (sorted (cmd .all_commands .items (),
75
+ key = lambda c : c [0 ])):
76
+ if length == i + 1 : # last
77
+ branch = '└─'
90
78
else :
91
- branch = '├─ ' + c .name
92
- fmt += f"`{ branch :<{maxlen + 1 }} ` - "
93
- fmt += f"{ c .short_doc :<{maxlen }} \n "
79
+ branch = '├─'
80
+ fmt += f"`{ branch } { name } ` - { c .short_doc } \n "
94
81
95
- em .add_field (name = 'Sub-commands ' , value = fmt )
82
+ em .add_field (name = 'Sub Commands ' , value = fmt )
96
83
em .set_footer (
97
84
text = f'Type "{ prefix } help { cmd } command" '
98
85
'for more info on a command.'
@@ -102,21 +89,16 @@ def format_command_help(self, ctx, cmd):
102
89
def format_not_found (self , ctx , command ):
103
90
prefix = ctx .prefix
104
91
em = Embed (
105
- title = 'Could not find a cog or command by that name. ' ,
92
+ title = 'Unable to Find Command or Category ' ,
106
93
color = Color .red ()
107
94
)
108
95
em .set_footer (text = f'Type "{ prefix } help" to get '
109
96
'a full list of commands.' )
110
- cogs = get_close_matches (command , self .bot .cogs .keys ())
111
- cmds = get_close_matches (command , self .bot .all_commands .keys ())
112
- if cogs or cmds :
113
- em .description = 'Did you mean...'
114
- if cogs :
115
- em .add_field (name = 'Cogs' , value = '\n ' .join (f'`{ x } `'
116
- for x in cogs ))
117
- if cmds :
118
- em .add_field (name = 'Commands' , value = '\n ' .join (f'`{ x } `'
119
- for x in cmds ))
97
+
98
+ choices = set (self .bot .cogs .keys ()) | set (self .bot .all_commands .keys ())
99
+ closest = get_close_matches (command , choices , n = 1 , cutoff = 0.45 )
100
+ if closest :
101
+ em .description = f'**Perhaps you meant:**\n \u2000 - `{ closest [0 ]} `'
120
102
return em
121
103
122
104
@commands .command ()
@@ -125,27 +107,24 @@ async def help(self, ctx, *, command: str = None):
125
107
"""Shows the help message."""
126
108
127
109
if command is not None :
128
- cog = self .bot .cogs .get (command )
129
110
cmd = self .bot .get_command (command )
130
- if cog is not None :
131
- em = self .format_cog_help (ctx , cog )
132
- elif cmd is not None :
133
- em = self .format_command_help (ctx , cmd )
111
+ cog = self .bot .cogs .get (command )
112
+ if cmd is not None :
113
+ embeds = [self .format_command_help (ctx , cmd )]
114
+ elif cog is not None :
115
+ embeds = self .format_cog_help (ctx , cog )
134
116
else :
135
- em = self .format_not_found (ctx , command )
136
- if em :
137
- return await ctx .send (embed = em )
138
-
139
- pages = []
117
+ embeds = [self .format_not_found (ctx , command )]
118
+ p_session = PaginatorSession (ctx , * embeds )
119
+ return await p_session .run ()
140
120
141
- for _ , cog in sorted (self .bot .cogs .items ()):
142
- em = self .format_cog_help (ctx , cog )
143
- if em :
144
- pages .append (em )
145
-
146
- p_session = PaginatorSession (ctx , * pages )
121
+ embeds = []
122
+ for cog in sorted (self .bot .cogs .values (),
123
+ key = lambda cog : cog .__class__ .__name__ ):
124
+ embeds .extend (self .format_cog_help (ctx , cog ))
147
125
148
- await p_session .run ()
126
+ p_session = PaginatorSession (ctx , * embeds )
127
+ return await p_session .run ()
149
128
150
129
@commands .command ()
151
130
@trigger_typing
0 commit comments