Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.

Commit 9259a12

Browse files
author
kuso-senpai
committed
added types for properties
1 parent 3e2dc5a commit 9259a12

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

discord_ui/components.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class Component():
169169
def __init__(self, component_type) -> None:
170170
self._json = {"type": component_type}
171171
@property
172-
def component_type(self):
172+
def component_type(self) -> int:
173173
"""
174174
The message component type
175175
@@ -370,7 +370,7 @@ def disabled(self, value):
370370
self._json["disabled"] = value
371371

372372
@property
373-
def hash(self):
373+
def hash(self) -> str:
374374
"""Hash for the selectmenu
375375
376376
:type: :class:`str`

discord_ui/receive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def __init__(self, *, state, channel, data):
380380

381381
# region attributes
382382
@property
383-
def buttons(self):
383+
def buttons(self) -> typing.List[typing.Union[Button, LinkButton]]:
384384
"""The button components in the message
385385
386386
:type: List[:class:`~Button` | :class:`~LinkButton`]
@@ -389,7 +389,7 @@ def buttons(self):
389389
return [x for x in self.components if type(x) in [Button, LinkButton]]
390390
return []
391391
@property
392-
def select_menus(self):
392+
def select_menus(self) -> typing.List[SelectMenu]:
393393
"""The select menus components in the message
394394
395395
:type: List[:class:`~SelectMenu`]

discord_ui/slash/tools.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,21 @@ async def handle_thing(value, typ, data, method, _discord, auto=False) -> typing
183183
return value
184184
else:
185185
logging.warning("Unkonw parsemethod: " + str(method) + "\nReturning raw value")
186-
return value
186+
return value
187+
188+
def create_choice(name, value) -> dict:
189+
"""A function that will create a choice for a :class:`~SlashOption`
190+
191+
Parameters
192+
----------
193+
name: :class:`str`
194+
The name of the choice
195+
value: :class:`Any`
196+
The value that will be received when the user selected this choice
197+
Returns
198+
-------
199+
:returns: The created choice
200+
:type: :class:`dict`
201+
202+
"""
203+
return {"name": name, "value": value}

discord_ui/slash/types.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ def __repr__(self) -> str:
330330
USER = User = 2
331331

332332
@property
333-
def allowed(self) -> typing.List[typing.Union[str, int]]:
333+
def allowed(self) -> dict:
334334
return [x for x in self._json if x["permission"] == True]
335335
@property
336-
def forbidden(self) -> typing.List[typing.Union[str, int]]:
336+
def forbidden(self) -> dict:
337337
return [x for x in self._json if x["permission"] == False]
338338

339339

@@ -453,7 +453,7 @@ def __ne__(self, o: object) -> bool:
453453

454454
# region command
455455
@property
456-
def command_type(self):
456+
def command_type(self) -> int:
457457
return self._json["type"]
458458

459459
@property
@@ -508,7 +508,7 @@ def options(self, options):
508508
# endregion
509509
# region permissions
510510
@property
511-
def default_permission(self):
511+
def default_permission(self) -> bool:
512512
return self._json.get("default_permission", False)
513513
@default_permission.setter
514514
def default_permission(self, value):
@@ -544,13 +544,13 @@ def __init__(self, callback, name, guild_ids, default_permission = True, guild_p
544544
super().__init__(callback, name, guild_ids=guild_ids, default_permission=default_permission, guild_permissions=guild_permissions)
545545

546546
@property
547-
def description(self):
547+
def description(self) -> str:
548548
return ""
549549
@description.setter
550550
def description(self, value):
551551
pass
552552
@property
553-
def options(self):
553+
def options(self) -> list:
554554
return []
555555
@options.setter
556556
def options(self, value):

0 commit comments

Comments
 (0)