|
|
@@ -1,11 +1,12 @@
|
|
1
|
1
|
"""
|
|
2
|
2
|
Cog for handling most ungrouped commands and basic behaviors.
|
|
3
|
3
|
"""
|
|
|
4
|
+import re
|
|
4
|
5
|
from datetime import datetime, timedelta, timezone
|
|
5
|
6
|
from typing import Optional, Union
|
|
6
|
7
|
|
|
7
|
|
-from discord import Interaction, Message, User, Permissions
|
|
8
|
|
-from discord.app_commands import Command, Group, command, default_permissions, guild_only, Transform, rename, Choice, \
|
|
|
8
|
+from discord import Interaction, Message, User, Permissions, AppCommandType
|
|
|
9
|
+from discord.app_commands import Command, Group, command, default_permissions, guild_only, Transform, Choice, \
|
|
9
|
10
|
autocomplete
|
|
10
|
11
|
from discord.errors import DiscordException
|
|
11
|
12
|
from discord.ext.commands import Cog
|
|
|
@@ -13,9 +14,16 @@ from discord.ext.commands import Cog
|
|
13
|
14
|
from config import CONFIG
|
|
14
|
15
|
from rocketbot.bot import Rocketbot
|
|
15
|
16
|
from rocketbot.cogs.basecog import BaseCog, BotMessage
|
|
16
|
|
-from rocketbot.utils import describe_timedelta, TimeDeltaTransformer, dump_stacktrace
|
|
|
17
|
+from rocketbot.utils import describe_timedelta, TimeDeltaTransformer, dump_stacktrace, MOD_PERMISSIONS
|
|
17
|
18
|
from rocketbot.storage import ConfigKey, Storage
|
|
18
|
19
|
|
|
|
20
|
+
|
|
|
21
|
+trivial_words = {
|
|
|
22
|
+ 'a', 'an', 'and', 'are', "aren't", 'as', 'by', 'can', 'for', 'have', 'if', 'in',
|
|
|
23
|
+ 'is', 'it', 'its', "it's", 'not', 'of', 'on', 'or', 'than', 'that', 'the', 'then',
|
|
|
24
|
+ 'there', 'them', 'they', "they're", 'this', 'to', 'when', 'with',
|
|
|
25
|
+}
|
|
|
26
|
+
|
|
19
|
27
|
async def command_autocomplete(interaction: Interaction, current: str) -> list[Choice[str]]:
|
|
20
|
28
|
choices: list[Choice] = []
|
|
21
|
29
|
try:
|
|
|
@@ -25,10 +33,10 @@ async def command_autocomplete(interaction: Interaction, current: str) -> list[C
|
|
25
|
33
|
user_permissions = interaction.permissions
|
|
26
|
34
|
cmds = GeneralCog.shared.get_command_list(user_permissions)
|
|
27
|
35
|
return [
|
|
28
|
|
- Choice(name=f'/{cmdname}', value=f'/{cmdname}')
|
|
|
36
|
+ Choice(name=f'/{cmdname} command', value=f'cmd:{cmdname}')
|
|
29
|
37
|
for cmdname in sorted(cmds.keys())
|
|
30
|
|
- if len(current) == 0 or cmdname.startswith(current)
|
|
31
|
|
- ]
|
|
|
38
|
+ if len(current) == 0 or current in cmdname
|
|
|
39
|
+ ][:25]
|
|
32
|
40
|
except BaseException as e:
|
|
33
|
41
|
dump_stacktrace(e)
|
|
34
|
42
|
return choices
|
|
|
@@ -36,11 +44,11 @@ async def command_autocomplete(interaction: Interaction, current: str) -> list[C
|
|
36
|
44
|
async def subcommand_autocomplete(interaction: Interaction, current: str) -> list[Choice[str]]:
|
|
37
|
45
|
try:
|
|
38
|
46
|
current = current.lower().strip()
|
|
39
|
|
- cmd_name = interaction.namespace['command']
|
|
40
|
|
- if cmd_name.startswith('/'):
|
|
41
|
|
- cmd_name = cmd_name[1:]
|
|
|
47
|
+ cmd_name = interaction.namespace['topic']
|
|
|
48
|
+ cmd = GeneralCog.shared.object_for_help_symbol(cmd_name)
|
|
|
49
|
+ if not isinstance(cmd, Group):
|
|
|
50
|
+ return []
|
|
42
|
51
|
user_permissions = interaction.permissions
|
|
43
|
|
- cmd = GeneralCog.shared.get_command_list(user_permissions).get(cmd_name)
|
|
44
|
52
|
if cmd is None or not isinstance(cmd, Group):
|
|
45
|
53
|
print(f'No command found named {cmd_name}')
|
|
46
|
54
|
return []
|
|
|
@@ -50,17 +58,47 @@ async def subcommand_autocomplete(interaction: Interaction, current: str) -> lis
|
|
50
|
58
|
print(f'Subcommands for {cmd_name} was None')
|
|
51
|
59
|
return []
|
|
52
|
60
|
return [
|
|
53
|
|
- Choice(name=subcmd_name, value=subcmd_name)
|
|
|
61
|
+ Choice(name=f'{subcmd_name} subcommand', value=f'subcmd:{cmd_name}.{subcmd_name}')
|
|
54
|
62
|
for subcmd_name in sorted(subcmds.keys())
|
|
55
|
|
- if len(current) == 0 or subcmd_name.startswith(current)
|
|
|
63
|
+ if len(current) == 0 or current in subcmd_name
|
|
|
64
|
+ ][:25]
|
|
|
65
|
+ except BaseException as e:
|
|
|
66
|
+ dump_stacktrace(e)
|
|
|
67
|
+ return []
|
|
|
68
|
+
|
|
|
69
|
+async def cog_autocomplete(interaction: Interaction, current: str) -> list[Choice[str]]:
|
|
|
70
|
+ try:
|
|
|
71
|
+ current = current.lower().strip()
|
|
|
72
|
+ return [
|
|
|
73
|
+ Choice(name=f'⚙ {cog.qualified_name} module', value=f'cog:{cog.qualified_name}')
|
|
|
74
|
+ for cog in sorted(GeneralCog.shared.bot.cogs.values(), key=lambda c: c.qualified_name)
|
|
|
75
|
+ if isinstance(cog, BaseCog) and
|
|
|
76
|
+ can_use_cog(cog, interaction.permissions) and
|
|
|
77
|
+ (len(cog.get_commands()) > 0 or len(cog.settings) > 0) and \
|
|
|
78
|
+ (len(current) == 0 or current in cog.qualified_name.lower())
|
|
56
|
79
|
]
|
|
57
|
80
|
except BaseException as e:
|
|
58
|
81
|
dump_stacktrace(e)
|
|
59
|
82
|
return []
|
|
60
|
83
|
|
|
|
84
|
+async def topic_autocomplete(interaction: Interaction, current: str) -> list[Choice[str]]:
|
|
|
85
|
+ command_choices = await command_autocomplete(interaction, current)
|
|
|
86
|
+ cog_choices = await cog_autocomplete(interaction, current)
|
|
|
87
|
+ return (command_choices + cog_choices)[:25]
|
|
|
88
|
+
|
|
|
89
|
+async def subtopic_autocomplete(interaction: Interaction, current: str) -> list[Choice[str]]:
|
|
|
90
|
+ subcommand_choices = await subcommand_autocomplete(interaction, current)
|
|
|
91
|
+ return subcommand_choices[:25]
|
|
|
92
|
+
|
|
61
|
93
|
def can_use_command(cmd: Union[Group, Command], user_permissions: Optional[Permissions]) -> bool:
|
|
62
|
|
- return user_permissions is not None and \
|
|
63
|
|
- (cmd.default_permissions is None or cmd.default_permissions.is_subset(user_permissions))
|
|
|
94
|
+ if user_permissions is None:
|
|
|
95
|
+ return False
|
|
|
96
|
+ if cmd.parent and not can_use_command(cmd.parent, user_permissions):
|
|
|
97
|
+ return False
|
|
|
98
|
+ return cmd.default_permissions is None or cmd.default_permissions.is_subset(user_permissions)
|
|
|
99
|
+
|
|
|
100
|
+def can_use_cog(cog: BaseCog, user_permissions: Optional[Permissions]) -> bool:
|
|
|
101
|
+ return user_permissions is not None and MOD_PERMISSIONS.is_subset(user_permissions)
|
|
64
|
102
|
|
|
65
|
103
|
class GeneralCog(BaseCog, name='General'):
|
|
66
|
104
|
"""
|
|
|
@@ -74,7 +112,6 @@ class GeneralCog(BaseCog, name='General'):
|
|
74
|
112
|
super().__init__(
|
|
75
|
113
|
bot,
|
|
76
|
114
|
config_prefix=None,
|
|
77
|
|
- name='',
|
|
78
|
115
|
short_description='',
|
|
79
|
116
|
)
|
|
80
|
117
|
self.is_connected = False
|
|
|
@@ -196,15 +233,59 @@ class GeneralCog(BaseCog, name='General'):
|
|
196
|
233
|
ephemeral=True,
|
|
197
|
234
|
)
|
|
198
|
235
|
|
|
|
236
|
+ def __create_help_index(self) -> None:
|
|
|
237
|
+ if getattr(self, 'obj_index', None) is not None:
|
|
|
238
|
+ return
|
|
|
239
|
+ self.obj_index: dict[str, Union[Command, Group, BaseCog]] = {}
|
|
|
240
|
+ self.keyword_index: dict[str, set[Union[Command, Group, BaseCog]]] = {}
|
|
|
241
|
+
|
|
|
242
|
+ def add_text_to_index(obj, text: str):
|
|
|
243
|
+ words = [
|
|
|
244
|
+ word
|
|
|
245
|
+ for word in re.split(r"[^a-zA-Z']+", text.lower())
|
|
|
246
|
+ if len(word) > 1 and word not in trivial_words
|
|
|
247
|
+ ]
|
|
|
248
|
+ for word in words:
|
|
|
249
|
+ matches = self.keyword_index.get(word, set())
|
|
|
250
|
+ matches.add(obj)
|
|
|
251
|
+ self.keyword_index[word] = matches
|
|
|
252
|
+
|
|
|
253
|
+ for cmd in self.bot.tree.get_commands(type=AppCommandType.chat_input):
|
|
|
254
|
+ key = f'cmd:{cmd.name}'
|
|
|
255
|
+ self.obj_index[key] = cmd
|
|
|
256
|
+ add_text_to_index(cmd, cmd.name)
|
|
|
257
|
+ if cmd.description:
|
|
|
258
|
+ add_text_to_index(cmd, cmd.description)
|
|
|
259
|
+ if isinstance(cmd, Group):
|
|
|
260
|
+ for subcmd in cmd.commands:
|
|
|
261
|
+ key = f'subcmd:{cmd.name}.{subcmd.name}'
|
|
|
262
|
+ self.obj_index[key] = subcmd
|
|
|
263
|
+ add_text_to_index(subcmd, subcmd.name)
|
|
|
264
|
+ if subcmd.description:
|
|
|
265
|
+ add_text_to_index(subcmd, subcmd.description)
|
|
|
266
|
+ for cog_qname, cog in self.bot.cogs.items():
|
|
|
267
|
+ if not isinstance(cog, BaseCog):
|
|
|
268
|
+ continue
|
|
|
269
|
+ key = f'cog:{cog_qname}'
|
|
|
270
|
+ self.obj_index[key] = cog
|
|
|
271
|
+ add_text_to_index(cog, cog.qualified_name)
|
|
|
272
|
+ if cog.description:
|
|
|
273
|
+ add_text_to_index(cog, cog.description)
|
|
|
274
|
+ print(self.obj_index.keys())
|
|
|
275
|
+ print(self.keyword_index.keys())
|
|
|
276
|
+
|
|
|
277
|
+ def object_for_help_symbol(self, symbol: str) -> Optional[Union[Command, Group, BaseCog]]:
|
|
|
278
|
+ self.__create_help_index()
|
|
|
279
|
+ return self.obj_index.get(symbol, None)
|
|
|
280
|
+
|
|
199
|
281
|
@command(name='help')
|
|
200
|
282
|
@guild_only()
|
|
201
|
|
- @rename(command_name='command', subcommand_name='subcommand')
|
|
202
|
|
- @autocomplete(command_name=command_autocomplete, subcommand_name=subcommand_autocomplete)
|
|
203
|
|
- async def help_command(self, interaction: Interaction, command_name: Optional[str] = None, subcommand_name: Optional[str] = None) -> None:
|
|
|
283
|
+ @autocomplete(topic=topic_autocomplete, subtopic=subtopic_autocomplete)
|
|
|
284
|
+ async def help_command(self, interaction: Interaction, topic: Optional[str] = None, subtopic: Optional[str] = None) -> None:
|
|
204
|
285
|
"""
|
|
205
|
|
- Shows help for using commands and subcommands.
|
|
|
286
|
+ Shows help for using commands and subcommands and configuring modules.
|
|
206
|
287
|
|
|
207
|
|
- `/help` will show a list of top-level commands.
|
|
|
288
|
+ `/help` will show a list of top-level topics.
|
|
208
|
289
|
|
|
209
|
290
|
`/help /<command_name>` will show help about a specific command or
|
|
210
|
291
|
list a command's subcommands.
|
|
|
@@ -212,55 +293,158 @@ class GeneralCog(BaseCog, name='General'):
|
|
212
|
293
|
`/help /<command_name> <subcommand_name>` will show help about a
|
|
213
|
294
|
specific subcommand.
|
|
214
|
295
|
|
|
|
296
|
+ `/help <module_name>` will show help about configuring a module.
|
|
|
297
|
+
|
|
|
298
|
+ `/help <keywords>` will do a text search for topics.
|
|
|
299
|
+
|
|
215
|
300
|
Parameters
|
|
216
|
301
|
----------
|
|
217
|
302
|
interaction: Interaction
|
|
218
|
|
- command_name: Optional[str]
|
|
219
|
|
- Optional name of a command to get specific help for. With or without the leading slash.
|
|
220
|
|
- subcommand_name: Optional[str]
|
|
221
|
|
- Optional name of a subcommand to get specific help for.
|
|
|
303
|
+ topic: Optional[str]
|
|
|
304
|
+ Optional topic to get specific help for. Getting help on a command can optionally start with a leading slash.
|
|
|
305
|
+ subtopic: Optional[str]
|
|
|
306
|
+ Optional subtopic to get specific help for.
|
|
222
|
307
|
"""
|
|
223
|
|
- print(f'help_command(interaction, {command_name}, {subcommand_name})')
|
|
224
|
|
- cmds: list[Command] = self.bot.tree.get_commands()
|
|
225
|
|
- if command_name is None:
|
|
|
308
|
+ print(f'help_command(interaction, {topic}, {subtopic})')
|
|
|
309
|
+
|
|
|
310
|
+ # General help
|
|
|
311
|
+ if topic is None:
|
|
226
|
312
|
await self.__send_general_help(interaction)
|
|
227
|
313
|
return
|
|
228
|
314
|
|
|
229
|
|
- if command_name.startswith('/'):
|
|
230
|
|
- command_name = command_name[1:]
|
|
231
|
|
- cmd = next((c for c in cmds if c.name == command_name), None)
|
|
232
|
|
- if cmd is None:
|
|
233
|
|
- interaction.response.send_message(
|
|
234
|
|
- f'Command `{command_name}` not found!',
|
|
235
|
|
- ephemeral=True,
|
|
236
|
|
- )
|
|
237
|
|
- return
|
|
238
|
|
- if subcommand_name is None:
|
|
239
|
|
- await self.__send_command_help(interaction, cmd)
|
|
|
315
|
+ # Specific object reference
|
|
|
316
|
+ obj = self.object_for_help_symbol(subtopic) if subtopic else self.object_for_help_symbol(topic)
|
|
|
317
|
+ if obj:
|
|
|
318
|
+ await self.__send_object_help(interaction, obj)
|
|
240
|
319
|
return
|
|
241
|
320
|
|
|
242
|
|
- if not isinstance(cmd, Group):
|
|
243
|
|
- await self.__send_command_help(interaction, cmd, addendum=f'{CONFIG["warning_emoji"]} Command does not have subcommands. Showing help for base command.')
|
|
|
321
|
+ # Text search
|
|
|
322
|
+ keywords = [
|
|
|
323
|
+ word
|
|
|
324
|
+ for word in re.split(r"[^a-zA-Z']+", topic.lower())
|
|
|
325
|
+ if len(word) > 0 and word not in trivial_words
|
|
|
326
|
+ ]
|
|
|
327
|
+ matching_objects_set = None
|
|
|
328
|
+ for keyword in keywords:
|
|
|
329
|
+ objs = self.keyword_index.get(keyword, None)
|
|
|
330
|
+ if objs is not None:
|
|
|
331
|
+ if matching_objects_set is None:
|
|
|
332
|
+ matching_objects_set = objs
|
|
|
333
|
+ else:
|
|
|
334
|
+ matching_objects_set = matching_objects_set & objs
|
|
|
335
|
+ accessible_objects = [
|
|
|
336
|
+ obj
|
|
|
337
|
+ for obj in matching_objects_set or {}
|
|
|
338
|
+ if ((isinstance(obj, Command) or isinstance(obj, Group)) and can_use_command(obj, interaction.permissions)) or \
|
|
|
339
|
+ (isinstance(obj, BaseCog) and can_use_cog(obj, interaction.permissions))
|
|
|
340
|
+ ]
|
|
|
341
|
+ await self.__send_keyword_help(interaction, accessible_objects)
|
|
|
342
|
+
|
|
|
343
|
+ async def __send_object_help(self, interaction: Interaction, obj: Union[Command, Group, BaseCog]) -> None:
|
|
|
344
|
+ if isinstance(obj, Command):
|
|
|
345
|
+ if obj.parent:
|
|
|
346
|
+ await self.__send_subcommand_help(interaction, obj.parent, obj)
|
|
|
347
|
+ else:
|
|
|
348
|
+ await self.__send_command_help(interaction, obj)
|
|
244
|
349
|
return
|
|
245
|
|
- grp: Group = cmd
|
|
246
|
|
- subcmd: Command = next((c for c in grp.commands if c.name == subcommand_name), None)
|
|
247
|
|
- if subcmd is None:
|
|
248
|
|
- await self.__send_command_help(interaction, cmd, addendum=f'{CONFIG["warning_emoji"]} Command `/{command_name}` does not have a subcommand "{subcommand_name}". Showing help for base command.')
|
|
|
350
|
+ if isinstance(obj, Group):
|
|
|
351
|
+ await self.__send_command_help(interaction, obj)
|
|
249
|
352
|
return
|
|
250
|
|
- await self.__send_subcommand_help(interaction, grp, subcmd)
|
|
251
|
|
- return
|
|
|
353
|
+ if isinstance(obj, BaseCog):
|
|
|
354
|
+ await self.__send_cog_help(interaction, obj)
|
|
|
355
|
+ return
|
|
|
356
|
+ print(f'No help for object {obj}')
|
|
|
357
|
+ await interaction.response.send_message(
|
|
|
358
|
+ f'{CONFIG["failure_emoji"]} Failed to get help info.',
|
|
|
359
|
+ ephemeral=True,
|
|
|
360
|
+ delete_after=10,
|
|
|
361
|
+ )
|
|
252
|
362
|
|
|
253
|
363
|
def get_command_list(self, permissions: Optional[Permissions] = None) -> dict[str, Union[Command, Group]]:
|
|
254
|
364
|
return { cmd.name: cmd for cmd in self.bot.tree.get_commands() if can_use_command(cmd, permissions) }
|
|
255
|
365
|
|
|
256
|
366
|
def get_subcommand_list(self, cmd: Group, permissions: Optional[Permissions] = None) -> dict[str, Command]:
|
|
257
|
|
- return { subcmd.name: subcmd for subcmd in cmd.commands if can_use_command(subcmd, permissions) }
|
|
|
367
|
+ return {
|
|
|
368
|
+ subcmd.name: subcmd
|
|
|
369
|
+ for subcmd in cmd.commands
|
|
|
370
|
+ if can_use_command(subcmd, permissions)
|
|
|
371
|
+ } if can_use_command(cmd, permissions) else {}
|
|
258
|
372
|
|
|
259
|
373
|
async def __send_general_help(self, interaction: Interaction) -> None:
|
|
260
|
374
|
user_permissions: Permissions = interaction.permissions
|
|
261
|
|
- text = f'## :information_source: Commands'
|
|
262
|
|
- for cmd_name, cmd in sorted(self.get_command_list(user_permissions).items()):
|
|
263
|
|
- text += f'\n- `/{cmd_name}`: {cmd.description}'
|
|
|
375
|
+ all_commands = sorted(self.get_command_list(user_permissions).items())
|
|
|
376
|
+ all_cog_tuples = [
|
|
|
377
|
+ cog_tuple
|
|
|
378
|
+ for cog_tuple in sorted(self.bot.cogs.items())
|
|
|
379
|
+ if isinstance(cog_tuple[1], BaseCog) and \
|
|
|
380
|
+ can_use_cog(cog_tuple[1], user_permissions) and \
|
|
|
381
|
+ (len(cog_tuple[1].settings) > 0)
|
|
|
382
|
+ ]
|
|
|
383
|
+
|
|
|
384
|
+ text = f'## :information_source: Help'
|
|
|
385
|
+ if len(all_commands) + len(all_cog_tuples) == 0:
|
|
|
386
|
+ text = 'Nothing available for your permissions!'
|
|
|
387
|
+
|
|
|
388
|
+ if len(all_commands) > 0:
|
|
|
389
|
+ text += '\n### Commands'
|
|
|
390
|
+ text += '\nType `/help /commandname` for more information.'
|
|
|
391
|
+ for cmd_name, cmd in sorted(self.get_command_list(user_permissions).items()):
|
|
|
392
|
+ text += f'\n- `/{cmd_name}`: {cmd.description}'
|
|
|
393
|
+ if isinstance(cmd, Group):
|
|
|
394
|
+ subcommand_count = len(cmd.commands)
|
|
|
395
|
+ text += f' ({subcommand_count} subcommands)'
|
|
|
396
|
+
|
|
|
397
|
+ if len(all_cog_tuples) > 0:
|
|
|
398
|
+ text += '\n### Module Configuration'
|
|
|
399
|
+ for cog_name, cog in all_cog_tuples:
|
|
|
400
|
+ has_enabled = next((s for s in cog.settings if s.name == 'enabled'), None) is not None
|
|
|
401
|
+ text += f'\n- **{cog_name}**: {cog.short_description}'
|
|
|
402
|
+ if has_enabled:
|
|
|
403
|
+ text += f'\n - `/enable {cog.config_prefix}` or `/disable {cog.config_prefix}`'
|
|
|
404
|
+ for setting in cog.settings:
|
|
|
405
|
+ if setting.name == 'enabled':
|
|
|
406
|
+ continue
|
|
|
407
|
+ text += f'\n - `/get` or `/set {cog.config_prefix}_{setting.name}`'
|
|
|
408
|
+ await interaction.response.send_message(
|
|
|
409
|
+ text,
|
|
|
410
|
+ ephemeral=True,
|
|
|
411
|
+ )
|
|
|
412
|
+
|
|
|
413
|
+ async def __send_keyword_help(self, interaction: Interaction, matching_objects: Optional[list[Union[Command, Group, BaseCog]]]) -> None:
|
|
|
414
|
+ matching_commands = [
|
|
|
415
|
+ cmd
|
|
|
416
|
+ for cmd in matching_objects or []
|
|
|
417
|
+ if isinstance(cmd, Command) or isinstance(cmd, Group)
|
|
|
418
|
+ ]
|
|
|
419
|
+ matching_cogs = [
|
|
|
420
|
+ cog
|
|
|
421
|
+ for cog in matching_objects or []
|
|
|
422
|
+ if isinstance(cog, BaseCog)
|
|
|
423
|
+ ]
|
|
|
424
|
+ if len(matching_commands) + len(matching_cogs) == 0:
|
|
|
425
|
+ await interaction.response.send_message(
|
|
|
426
|
+ f'{CONFIG["failure_emoji"]} No available help topics found.',
|
|
|
427
|
+ ephemeral=True,
|
|
|
428
|
+ delete_after=10,
|
|
|
429
|
+ )
|
|
|
430
|
+ return
|
|
|
431
|
+ if len(matching_objects) == 1:
|
|
|
432
|
+ obj = matching_objects[0]
|
|
|
433
|
+ await self.__send_object_help(interaction, obj)
|
|
|
434
|
+ return
|
|
|
435
|
+
|
|
|
436
|
+ text = '## :information_source: Matching Help Topics'
|
|
|
437
|
+ if len(matching_commands) > 0:
|
|
|
438
|
+ text += '\n### Commands'
|
|
|
439
|
+ for cmd in matching_commands:
|
|
|
440
|
+ if cmd.parent:
|
|
|
441
|
+ text += f'\n- `/{cmd.parent.name} {cmd.name}`'
|
|
|
442
|
+ else:
|
|
|
443
|
+ text += f'\n- `/{cmd.name}`'
|
|
|
444
|
+ if len(matching_cogs) > 0:
|
|
|
445
|
+ text += '\n### Cogs'
|
|
|
446
|
+ for cog in matching_cogs:
|
|
|
447
|
+ text += f'\n- {cog.qualified_name}'
|
|
264
|
448
|
await interaction.response.send_message(
|
|
265
|
449
|
text,
|
|
266
|
450
|
ephemeral=True,
|
|
|
@@ -293,3 +477,22 @@ class GeneralCog(BaseCog, name='General'):
|
|
293
|
477
|
for param in params:
|
|
294
|
478
|
text += f'\n- `{param.name}`: {param.description}'
|
|
295
|
479
|
await interaction.response.send_message(text, ephemeral=True)
|
|
|
480
|
+
|
|
|
481
|
+ async def __send_cog_help(self, interaction: Interaction, cog: BaseCog) -> None:
|
|
|
482
|
+ text = f'## :information_source: Module Help\n{cog.qualified_name}'
|
|
|
483
|
+ if cog.description is not None:
|
|
|
484
|
+ text += f'\n{cog.description}'
|
|
|
485
|
+ settings = cog.settings
|
|
|
486
|
+ if len(settings) > 0:
|
|
|
487
|
+ text += '\n### Configuration'
|
|
|
488
|
+ enabled_setting = next((s for s in settings if s.name == 'enabled'), None)
|
|
|
489
|
+ if enabled_setting is not None:
|
|
|
490
|
+ text += f'\n- `/enable {cog.config_prefix}` or `/disable {cog.config_prefix}`'
|
|
|
491
|
+ for setting in sorted(settings, key=lambda s: s.name):
|
|
|
492
|
+ if setting.name == 'enabled':
|
|
|
493
|
+ continue
|
|
|
494
|
+ text += f'\n- `/get` or `/set {cog.config_prefix}_{setting.name}` - {setting.description}'
|
|
|
495
|
+ await interaction.response.send_message(
|
|
|
496
|
+ text,
|
|
|
497
|
+ ephemeral=True,
|
|
|
498
|
+ )
|