PycordViews 1.2.7__py3-none-any.whl → 1.2.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycordViews/modal/__init__.py +2 -0
- pycordViews/modal/easy_modal_view.py +100 -0
- pycordViews/modal/errors.py +12 -0
- {pycordviews-1.2.7.dist-info → pycordviews-1.2.9.dist-info}/METADATA +1 -1
- {pycordviews-1.2.7.dist-info → pycordviews-1.2.9.dist-info}/RECORD +8 -5
- {pycordviews-1.2.7.dist-info → pycordviews-1.2.9.dist-info}/WHEEL +1 -1
- {pycordviews-1.2.7.dist-info → pycordviews-1.2.9.dist-info}/top_level.txt +1 -0
- {pycordviews-1.2.7.dist-info → pycordviews-1.2.9.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,100 @@
|
|
1
|
+
from discord.ui import Modal, InputText
|
2
|
+
from discord import InputTextStyle, Interaction
|
3
|
+
from typing import Optional, Callable, Union
|
4
|
+
from functools import partial
|
5
|
+
from asyncio import iscoroutinefunction
|
6
|
+
|
7
|
+
from .errors import CoroutineError, CustomIDNotFound
|
8
|
+
|
9
|
+
class EasyModal(Modal):
|
10
|
+
|
11
|
+
def __init__(self, title: str, custom_id: Optional[str] = None, timeout: Optional[float] = None, global_callable: Optional[Callable] = None):
|
12
|
+
"""
|
13
|
+
Init EasyModal instance.
|
14
|
+
:param title: The title set to the Modal
|
15
|
+
:param custom_id: ID set to the Modal
|
16
|
+
:param timeout: Timeout before the view don't allow response.
|
17
|
+
:param global_callable: Asynchronous function called when user submit the modal. Called before all subcoroutine function set for each inputText. Get the instance modal and user interaction in parameters
|
18
|
+
"""
|
19
|
+
super().__init__(title=title, custom_id=custom_id, timeout=timeout)
|
20
|
+
|
21
|
+
self.__callback: dict[str, Union[Callable, None]] = {}
|
22
|
+
|
23
|
+
if global_callable is not None and not iscoroutinefunction(global_callable):
|
24
|
+
raise CoroutineError(global_callable)
|
25
|
+
|
26
|
+
self.__global_callable: Optional[Callable] = global_callable
|
27
|
+
|
28
|
+
def add_input_text(self, label: str,
|
29
|
+
style: InputTextStyle = InputTextStyle.short,
|
30
|
+
custom_id: Optional[str] = None,
|
31
|
+
placeholder: Optional[str] = None,
|
32
|
+
min_length: Optional[int] = None,
|
33
|
+
max_length: Optional[int] = None,
|
34
|
+
required: Optional[bool] = True,
|
35
|
+
value: Optional[str] = None,
|
36
|
+
row: Optional[int] = None) -> Callable:
|
37
|
+
"""
|
38
|
+
Add an input text on the Modal.
|
39
|
+
:return: set_inputText_callable function to set the callable on the inputText. Require an asynchronous function in parameters.
|
40
|
+
"""
|
41
|
+
|
42
|
+
x = InputText(label=label, style=style, custom_id=custom_id, placeholder=placeholder, min_length=min_length, max_length=max_length, required=required, row=row, value=value)
|
43
|
+
self.__callback[x.custom_id] = None
|
44
|
+
self.add_item(x)
|
45
|
+
return partial(self.set_inputText_callable, x.custom_id)
|
46
|
+
|
47
|
+
def set_inputText_callable(self, inputText_id: str, _callable: Callable) -> "EasyModal":
|
48
|
+
"""
|
49
|
+
Set an asynchronous function to a single inputText. _callable function was called when modal is completed by the user
|
50
|
+
|
51
|
+
x = EasyModal(title="test")
|
52
|
+
# init '8878' custom_id for one inputtext
|
53
|
+
|
54
|
+
x.set_inputText_callable(inputText_id='8878', _callable=set_any)
|
55
|
+
|
56
|
+
async def set_any(data: InputText, interaction: Interaction):
|
57
|
+
...
|
58
|
+
"""
|
59
|
+
if not iscoroutinefunction(_callable):
|
60
|
+
raise CoroutineError(_callable)
|
61
|
+
|
62
|
+
if inputText_id not in self.__callback.keys():
|
63
|
+
raise CustomIDNotFound(inputText_id)
|
64
|
+
|
65
|
+
self.__callback[inputText_id] = _callable
|
66
|
+
return self
|
67
|
+
|
68
|
+
def del_inputText_callable(self, inputText_id: str) -> "EasyModal":
|
69
|
+
"""
|
70
|
+
Delete callable object link to the inputText ID
|
71
|
+
:param inputText_id: ID to the inputText
|
72
|
+
"""
|
73
|
+
if inputText_id not in self.__callback.keys():
|
74
|
+
raise CustomIDNotFound(inputText_id)
|
75
|
+
|
76
|
+
self.__callback[inputText_id] = None
|
77
|
+
|
78
|
+
async def callback(self, interaction: Interaction):
|
79
|
+
"""
|
80
|
+
Call when the user submit the modal.
|
81
|
+
All callable function set to the user get the 'interaction' parameter.
|
82
|
+
"""
|
83
|
+
|
84
|
+
if self.__global_callable is not None:
|
85
|
+
await self.__global_callable(self, interaction)
|
86
|
+
|
87
|
+
for inputTextID, _callable in self.__callback.items():
|
88
|
+
if _callable is not None:
|
89
|
+
await _callable(self.get_input_text(inputTextID),interaction)
|
90
|
+
|
91
|
+
def get_input_text(self, inputText_id: str) -> InputText:
|
92
|
+
"""
|
93
|
+
Return the inputText associated to the inputText_id
|
94
|
+
:param inputText_id: ID inputText
|
95
|
+
"""
|
96
|
+
for i in self.children:
|
97
|
+
if i.custom_id == inputText_id:
|
98
|
+
return i
|
99
|
+
|
100
|
+
raise CustomIDNotFound(inputText_id)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class ModalError(Exception):
|
2
|
+
pass
|
3
|
+
|
4
|
+
|
5
|
+
class CustomIDNotFound(ModalError):
|
6
|
+
def __init__(self, customID: str):
|
7
|
+
super().__init__(f"'{customID}' ID not found !")
|
8
|
+
|
9
|
+
|
10
|
+
class CoroutineError(ModalError):
|
11
|
+
def __init__(self, coro):
|
12
|
+
super().__init__(f"{coro} is not a coroutine !")
|
@@ -6,6 +6,9 @@ pycordViews/menu/__init__.py,sha256=QUXA9ezyeTScvS1kxMNFgKEbZMsPq5yUnWWgbXCytCk,
|
|
6
6
|
pycordViews/menu/errors.py,sha256=0Um-oH5qMdWSZB_bGlqILsf9WSDtC4n_HwkheekiMV4,480
|
7
7
|
pycordViews/menu/menu.py,sha256=3D13C5Vs69w9SlrnixBfF0riY48jORi8JcYte65YFPs,4306
|
8
8
|
pycordViews/menu/selectMenu.py,sha256=oYydLtoQm7YRjnFII2af5cUfIZ8ci_86lk0Il5TGYTw,10459
|
9
|
+
pycordViews/modal/__init__.py,sha256=TFUX3z25oInBhBzoOQhnLbKmwArXo4IVVqBfN6y11Bo,61
|
10
|
+
pycordViews/modal/easy_modal_view.py,sha256=n8shCQD5z1BQ7uv_sWvyk4hjZsX6l-VyN624GocWV0E,4277
|
11
|
+
pycordViews/modal/errors.py,sha256=nIGYyOS_oWH49Dj8ZGW53nnzaPmbvFbAo7ydikD5xWE,307
|
9
12
|
pycordViews/multibot/__init__.py,sha256=93Q_URiRUMsvwQJIqUnb75aq6SPM83yteSMrH0rmXMg,30
|
10
13
|
pycordViews/multibot/bot.py,sha256=UrRqSSmtFpkQKAqeunHxIy_O5DgO1gcW-nMEQ9yNdAo,8267
|
11
14
|
pycordViews/multibot/errors.py,sha256=_xawL8jQZTajx253F4JKywFGVPdYf8vTALOMiNqJ9hs,1176
|
@@ -18,8 +21,8 @@ pycordViews/pagination/pagination_view.py,sha256=T9kN_-hj2bD4ia4NI2CIkzJCgdp_6xx
|
|
18
21
|
pycordViews/views/__init__.py,sha256=yligptZmw-np8tjKLr76SVmi0807Nk6jCyKkKYLhbCY,89
|
19
22
|
pycordViews/views/easy_modified_view.py,sha256=EFtVQnbQTYkq-iF7Dzb4u1Libra8M22f-SkeiJsGulA,11005
|
20
23
|
pycordViews/views/errors.py,sha256=AkhGskuBjbFs0ZQdTDlVyfvAJ1WRMMQx2sAXUnYjmog,360
|
21
|
-
pycordviews-1.2.
|
22
|
-
pycordviews-1.2.
|
23
|
-
pycordviews-1.2.
|
24
|
-
pycordviews-1.2.
|
25
|
-
pycordviews-1.2.
|
24
|
+
pycordviews-1.2.9.dist-info/licenses/LICENSE,sha256=lNgcw1_xb7QENAQi3uHGymaFtbs0RV-ihiCd7AoLQjA,1082
|
25
|
+
pycordviews-1.2.9.dist-info/METADATA,sha256=_bahF12GRtEKqlBvEja6sxlyL3-yD5-QqF61YlhGkgQ,11824
|
26
|
+
pycordviews-1.2.9.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
|
27
|
+
pycordviews-1.2.9.dist-info/top_level.txt,sha256=3NvgH6MjESe7Q6jb6aqHgdYrYb5NhxwxnoDyE6PkThY,125
|
28
|
+
pycordviews-1.2.9.dist-info/RECORD,,
|
File without changes
|