@@ -123,7 +123,6 @@ def __init__(self, name, cmd): # Let's reuse old command formatting.
123
123
self .allowed_guild_ids = cmd ["guild_ids" ] or []
124
124
self .options = cmd ["api_options" ] or []
125
125
self .connector = cmd ["connector" ] or {}
126
- self .has_subcommands = cmd ["has_subcommands" ]
127
126
# Ref https://github.com/Rapptz/discord.py/blob/master/discord/ext/commands/core.py#L1447
128
127
# Since this isn't inherited from `discord.ext.commands.Command`, discord.py's check decorator will
129
128
# add checks at this var.
@@ -176,6 +175,28 @@ async def can_run(self, ctx) -> bool:
176
175
return False not in res
177
176
178
177
178
+ class BaseCommandObject (CommandObject ):
179
+ """
180
+ BaseCommand object of this extension.
181
+
182
+ .. note::
183
+ This model inherits :class:`.model.CommandObject`, so this has every variables from that.
184
+
185
+ .. warning::
186
+ Do not manually init this model.
187
+
188
+ :ivar has_subcommands: Indicates whether this base command has subcommands.
189
+ :ivar default_permission: Indicates whether users should have permissions to run this command by default.
190
+ :ivar permissions: Permissions to restrict use of this command.
191
+ """
192
+
193
+ def __init__ (self , name , cmd ): # Let's reuse old command formatting.
194
+ super ().__init__ (name , cmd )
195
+ self .has_subcommands = cmd ["has_subcommands" ]
196
+ self .default_permission = cmd ["default_permission" ]
197
+ self .permissions = cmd ["api_permissions" ] or []
198
+
199
+
179
200
class SubcommandObject (CommandObject ):
180
201
"""
181
202
Subcommand object of this extension.
@@ -193,15 +214,14 @@ class SubcommandObject(CommandObject):
193
214
"""
194
215
195
216
def __init__ (self , sub , base , name , sub_group = None ):
196
- sub ["has_subcommands" ] = True # For the inherited class.
197
217
super ().__init__ (name , sub )
198
218
self .base = base .lower ()
199
219
self .subcommand_group = sub_group .lower () if sub_group else sub_group
200
220
self .base_description = sub ["base_desc" ]
201
221
self .subcommand_group_description = sub ["sub_group_desc" ]
202
222
203
223
204
- class CogCommandObject ( CommandObject ):
224
+ class CogBaseCommandObject ( BaseCommandObject ):
205
225
"""
206
226
Slash command object but for Cog.
207
227
@@ -235,8 +255,9 @@ class CogSubcommandObject(SubcommandObject):
235
255
Do not manually init this model.
236
256
"""
237
257
238
- def __init__ (self , * args ):
239
- super ().__init__ (* args )
258
+ def __init__ (self , base , cmd , sub_group , name , sub ):
259
+ super ().__init__ (sub , base , name , sub_group )
260
+ self .base_command_data = cmd
240
261
self .cog = None # Manually set this later.
241
262
242
263
async def invoke (self , * args , ** kwargs ):
@@ -358,3 +379,67 @@ async def wrap():
358
379
await self ._http .delete (self .__interaction_token , self .id )
359
380
360
381
self ._state .loop .create_task (wrap ())
382
+
383
+
384
+ class PermissionData :
385
+ """
386
+ Single slash permission data.
387
+
388
+ :ivar id: User or role id, based on following type specfic.
389
+ :ivar type: The ``SlashCommandPermissionsType`` type of this permission.
390
+ :ivar permission: State of permission. ``True`` to allow, ``False`` to disallow.
391
+ """
392
+ def __init__ (self , id , type , permission , ** kwargs ):
393
+ self .id = id
394
+ self .type = type
395
+ self .permission = permission
396
+
397
+ def __eq__ (self , other ):
398
+ if isinstance (other , PermissionData ):
399
+ return (
400
+ self .id == other .id
401
+ and self .type == other .id
402
+ and self .permission == other .permission
403
+ )
404
+ else :
405
+ return False
406
+
407
+
408
+ class GuildPermissionsData :
409
+ """
410
+ Slash permissions data for a command in a guild.
411
+
412
+ :ivar id: Command id, provided by discord.
413
+ :ivar guild_id: Guild id that the permissions are in.
414
+ :ivar permissions: List of permissions dict.
415
+ """
416
+ def __init__ (self , id , guild_id , permissions , ** kwargs ):
417
+ self .id = id
418
+ self .guild_id = guild_id
419
+ self .permissions = []
420
+ if permissions :
421
+ for permission in permissions :
422
+ self .permissions .append (PermissionData (** permission ))
423
+
424
+ def __eq__ (self , other ):
425
+ if isinstance (other , GuildPermissionsData ):
426
+ return (
427
+ self .id == other .id
428
+ and self .guild_id == other .guild_id
429
+ and self .permissions == other .permissions
430
+ )
431
+ else :
432
+ return False
433
+
434
+
435
+ class SlashCommandPermissionType (IntEnum ):
436
+ """
437
+ Equivalent of `ApplicationCommandPermissionType <https://discord.com/developers/docs/interactions/slash-commands#applicationcommandpermissiontype>`_ in the Discord API.
438
+ """
439
+ ROLE = 1
440
+ USER = 2
441
+
442
+ @classmethod
443
+ def from_type (cls , t : type ):
444
+ if issubclass (t , discord .abc .Role ): return cls .ROLE
445
+ if issubclass (t , discord .abc .User ): return cls .USER
0 commit comments