|
|
@@ -2,7 +2,7 @@
|
|
2
|
2
|
A guild configuration setting available for editing via bot commands.
|
|
3
|
3
|
"""
|
|
4
|
4
|
from datetime import timedelta
|
|
5
|
|
-from typing import Any, Optional, Type, Literal
|
|
|
5
|
+from typing import Any, Optional, Type, Literal, Union
|
|
6
|
6
|
|
|
7
|
7
|
from discord import Interaction, Permissions
|
|
8
|
8
|
from discord.app_commands import Range, Transform, describe
|
|
|
@@ -14,6 +14,23 @@ from rocketbot.storage import Storage
|
|
14
|
14
|
from rocketbot.utils import bot_log, TimeDeltaTransformer, MOD_PERMISSIONS, dump_stacktrace, str_from_timedelta
|
|
15
|
15
|
|
|
16
|
16
|
|
|
|
17
|
+def describe_type(datatype: Type) -> str:
|
|
|
18
|
+ if datatype is int:
|
|
|
19
|
+ return 'integer'
|
|
|
20
|
+ if datatype is float:
|
|
|
21
|
+ return 'float'
|
|
|
22
|
+ if datatype is str:
|
|
|
23
|
+ return 'string'
|
|
|
24
|
+ if datatype is bool:
|
|
|
25
|
+ return 'boolean'
|
|
|
26
|
+ if datatype is timedelta:
|
|
|
27
|
+ return 'timespan'
|
|
|
28
|
+ if getattr(datatype, '__origin__', None) is Union:
|
|
|
29
|
+ return '|'.join([ describe_type(a) for a in datatype.__args__ ])
|
|
|
30
|
+ if getattr(datatype, '__origin__', None) is Literal:
|
|
|
31
|
+ return '"' + ('"|"'.join(datatype.__args__)) + '"'
|
|
|
32
|
+ return datatype.__class__.__name__
|
|
|
33
|
+
|
|
17
|
34
|
class CogSetting:
|
|
18
|
35
|
"""
|
|
19
|
36
|
Describes a configuration setting for a guild that can be edited by the
|
|
|
@@ -142,7 +159,7 @@ class CogSetting:
|
|
142
|
159
|
ephemeral=True
|
|
143
|
160
|
)
|
|
144
|
161
|
|
|
145
|
|
- bot_log(None, cog.__class__, f"Creating /get {setting_name}")
|
|
|
162
|
+ bot_log(None, cog.__class__, f"Creating command: /get {setting_name}")
|
|
146
|
163
|
command = Command(
|
|
147
|
164
|
name=setting_name,
|
|
148
|
165
|
description=f'Shows {self.brief}.',
|
|
|
@@ -232,7 +249,7 @@ class CogSetting:
|
|
232
|
249
|
elif self.datatype is not None:
|
|
233
|
250
|
raise ValueError(f'Invalid type {self.datatype}')
|
|
234
|
251
|
|
|
235
|
|
- bot_log(None, cog.__class__, f"Creating /set {setting_name} {self.datatype}")
|
|
|
252
|
+ bot_log(None, cog.__class__, f"Creating command: /set {setting_name} <{describe_type(self.datatype)}>")
|
|
236
|
253
|
command = Command(
|
|
237
|
254
|
name=setting_name,
|
|
238
|
255
|
description=f'Sets {self.brief}.',
|
|
|
@@ -258,7 +275,7 @@ class CogSetting:
|
|
258
|
275
|
await cog.on_setting_updated(interaction.guild, setting)
|
|
259
|
276
|
cog.log(interaction.guild, f'{interaction.user.name} enabled {cog.__class__.__name__}')
|
|
260
|
277
|
|
|
261
|
|
- bot_log(None, cog.__class__, f"Creating /enable {cog.config_prefix}")
|
|
|
278
|
+ bot_log(None, cog.__class__, f"Creating command: /enable {cog.config_prefix}")
|
|
262
|
279
|
command = Command(
|
|
263
|
280
|
name=cog.config_prefix,
|
|
264
|
281
|
description=f'Enables {cog.qualified_name} functionality.',
|
|
|
@@ -284,7 +301,7 @@ class CogSetting:
|
|
284
|
301
|
await cog.on_setting_updated(interaction.guild, setting)
|
|
285
|
302
|
cog.log(interaction.guild, f'{interaction.user.name} disabled {cog.__class__.__name__}')
|
|
286
|
303
|
|
|
287
|
|
- bot_log(None, cog.__class__, f"Creating /disable {cog.config_prefix}")
|
|
|
304
|
+ bot_log(None, cog.__class__, f"Creating command: /disable {cog.config_prefix}")
|
|
288
|
305
|
command = Command(
|
|
289
|
306
|
name=cog.config_prefix,
|
|
290
|
307
|
description=f'Disables {cog.config_prefix} functionality',
|
|
|
@@ -313,10 +330,8 @@ class CogSetting:
|
|
313
|
330
|
cls.__set_up_base_commands(bot)
|
|
314
|
331
|
if len(settings) == 0:
|
|
315
|
332
|
return
|
|
316
|
|
- bot_log(None, cog.__class__, f"Setting up slash commands for {cog.__class__.__name__}")
|
|
317
|
333
|
for setting in settings:
|
|
318
|
334
|
setting.set_up(cog)
|
|
319
|
|
- bot_log(None, cog.__class__, f"Done setting up slash commands for {cog.__class__.__name__}")
|
|
320
|
335
|
|
|
321
|
336
|
@classmethod
|
|
322
|
337
|
def __set_up_base_commands(cls, bot: Bot) -> None:
|