Skip to content

Commit 65819cc

Browse files
authored
Include Type on command obj enum + default values
1 parent c896a9c commit 65819cc

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

discord_slash/model.py

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ class CommandData:
8080
"""
8181

8282
def __init__(
83-
self,
84-
name,
85-
description,
86-
options=None,
87-
default_permission=True,
88-
id=None,
89-
application_id=None,
90-
version=None,
91-
**kwargs,
83+
self,
84+
name,
85+
description,
86+
options=None,
87+
default_permission=True,
88+
id=None,
89+
application_id=None,
90+
version=None,
91+
**kwargs,
9292
):
9393
self.name = name
9494
self.description = description
@@ -106,10 +106,10 @@ def __init__(
106106
def __eq__(self, other):
107107
if isinstance(other, CommandData):
108108
return (
109-
self.name == other.name
110-
and self.description == other.description
111-
and self.options == other.options
112-
and self.default_permission == other.default_permission
109+
self.name == other.name
110+
and self.description == other.description
111+
and self.options == other.options
112+
and self.default_permission == other.default_permission
113113
)
114114
else:
115115
return False
@@ -309,13 +309,14 @@ class CommandObject(CallbackObject):
309309
:ivar connector: Kwargs connector of the command.
310310
"""
311311

312-
def __init__(self, name, cmd): # Let's reuse old command formatting.
312+
def __init__(self, name, cmd, type): # Let's reuse old command formatting.
313313
super().__init__(cmd["func"])
314314
self.name = name.lower()
315315
self.description = cmd["description"]
316316
self.allowed_guild_ids = cmd["guild_ids"] or []
317317
self.options = cmd["api_options"] or []
318318
self.connector = cmd["connector"] or {}
319+
self.type = type or 1
319320

320321

321322
class BaseCommandObject(CommandObject):
@@ -333,8 +334,8 @@ class BaseCommandObject(CommandObject):
333334
:ivar permissions: Permissions to restrict use of this command.
334335
"""
335336

336-
def __init__(self, name, cmd): # Let's reuse old command formatting.
337-
super().__init__(name, cmd)
337+
def __init__(self, name, cmd, type=1): # Let's reuse old command formatting.
338+
super().__init__(name, cmd, type)
338339
self.has_subcommands = cmd["has_subcommands"]
339340
self.default_permission = cmd["default_permission"]
340341
self.permissions = cmd["api_permissions"] or {}
@@ -404,11 +405,11 @@ class ComponentCallbackObject(CallbackObject):
404405
"""
405406

406407
def __init__(
407-
self,
408-
func,
409-
message_ids,
410-
custom_ids,
411-
component_type,
408+
self,
409+
func,
410+
message_ids,
411+
custom_ids,
412+
component_type,
412413
):
413414
if component_type not in (2, 3, None):
414415
raise error.IncorrectFormat(f"Invalid component type `{component_type}`")
@@ -484,10 +485,10 @@ def from_type(cls, t: type):
484485
return cls.ROLE
485486
# Here's the issue. Typechecking for a **Union** somewhat differs per version (from 3.6.8+)
486487
if (
487-
hasattr(typing, "_GenericAlias")
488-
and isinstance(t, typing._UnionGenericAlias) # noqa
489-
or not hasattr(typing, "_GenericAlias")
490-
and isinstance(t, typing._Union) # noqa
488+
hasattr(typing, "_GenericAlias")
489+
and isinstance(t, typing._UnionGenericAlias) # noqa
490+
or not hasattr(typing, "_GenericAlias")
491+
and isinstance(t, typing._Union) # noqa
491492
):
492493
return cls.MENTIONABLE
493494
if issubclass(t, float):
@@ -626,9 +627,9 @@ def __init__(self, id, type, permission, **kwargs):
626627
def __eq__(self, other):
627628
if isinstance(other, PermissionData):
628629
return (
629-
self.id == other.id
630-
and self.type == other.id
631-
and self.permission == other.permission
630+
self.id == other.id
631+
and self.type == other.id
632+
and self.permission == other.permission
632633
)
633634
else:
634635
return False
@@ -654,9 +655,9 @@ def __init__(self, id, guild_id, permissions, **kwargs):
654655
def __eq__(self, other):
655656
if isinstance(other, GuildPermissionsData):
656657
return (
657-
self.id == other.id
658-
and self.guild_id == other.guild_id
659-
and self.permissions == other.permissions
658+
self.id == other.id
659+
and self.guild_id == other.guild_id
660+
and self.permissions == other.permissions
660661
)
661662
else:
662663
return False
@@ -697,12 +698,13 @@ class ButtonStyle(IntEnum):
697698
secondary = 2
698699
success = 3
699700
danger = 4
700-
701+
702+
701703
class ContextMenuType(IntEnum):
702704
CHAT_INPUT = 1
703705
USER = 2
704706
MESSAGE = 3
705-
707+
706708
@classmethod
707709
def from_type(cls, t: type):
708710
if issubclass(t, discord.abc.User):

0 commit comments

Comments
 (0)