PycordViews 1.2.7__tar.gz → 1.2.8__tar.gz

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.
Files changed (34) hide show
  1. {pycordviews-1.2.7 → pycordviews-1.2.8}/PKG-INFO +1 -1
  2. {pycordviews-1.2.7 → pycordviews-1.2.8}/PycordViews.egg-info/PKG-INFO +1 -1
  3. {pycordviews-1.2.7 → pycordviews-1.2.8}/PycordViews.egg-info/SOURCES.txt +6 -0
  4. {pycordviews-1.2.7 → pycordviews-1.2.8}/PycordViews.egg-info/top_level.txt +1 -0
  5. pycordviews-1.2.8/pycordViews/modal/__init__.py +2 -0
  6. pycordviews-1.2.8/pycordViews/modal/easy_modal_view.py +99 -0
  7. pycordviews-1.2.8/pycordViews/modal/errors.py +12 -0
  8. {pycordviews-1.2.7 → pycordviews-1.2.8}/setup.py +2 -2
  9. {pycordviews-1.2.7 → pycordviews-1.2.8}/LICENSE +0 -0
  10. {pycordviews-1.2.7 → pycordviews-1.2.8}/PycordViews.egg-info/dependency_links.txt +0 -0
  11. {pycordviews-1.2.7 → pycordviews-1.2.8}/PycordViews.egg-info/requires.txt +0 -0
  12. {pycordviews-1.2.7 → pycordviews-1.2.8}/README.md +0 -0
  13. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/__init__.py +0 -0
  14. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/kit/__init__.py +0 -0
  15. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/kit/confirm.py +0 -0
  16. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/kit/poll.py +0 -0
  17. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/menu/__init__.py +0 -0
  18. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/menu/errors.py +0 -0
  19. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/menu/menu.py +0 -0
  20. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/menu/selectMenu.py +0 -0
  21. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/multibot/__init__.py +0 -0
  22. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/multibot/bot.py +0 -0
  23. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/multibot/errors.py +0 -0
  24. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/multibot/multibot.py +0 -0
  25. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/multibot/process.py +0 -0
  26. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/pagination/__init__.py +0 -0
  27. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/pagination/errors.py +0 -0
  28. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/pagination/page.py +0 -0
  29. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/pagination/pagination_view.py +0 -0
  30. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/views/__init__.py +0 -0
  31. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/views/easy_modified_view.py +0 -0
  32. {pycordviews-1.2.7 → pycordviews-1.2.8}/pycordViews/views/errors.py +0 -0
  33. {pycordviews-1.2.7 → pycordviews-1.2.8}/pyproject.toml +0 -0
  34. {pycordviews-1.2.7 → pycordviews-1.2.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PycordViews
3
- Version: 1.2.7
3
+ Version: 1.2.8
4
4
  Summary: Views and multibot for py-cord library
5
5
  Home-page: https://github.com/BOXERRMD/Py-cord_Views
6
6
  Author: Chronos (alias BOXERRMD)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PycordViews
3
- Version: 1.2.7
3
+ Version: 1.2.8
4
4
  Summary: Views and multibot for py-cord library
5
5
  Home-page: https://github.com/BOXERRMD/Py-cord_Views
6
6
  Author: Chronos (alias BOXERRMD)
@@ -15,6 +15,9 @@ pycordViews/menu/__init__.py
15
15
  pycordViews/menu/errors.py
16
16
  pycordViews/menu/menu.py
17
17
  pycordViews/menu/selectMenu.py
18
+ pycordViews/modal/__init__.py
19
+ pycordViews/modal/easy_modal_view.py
20
+ pycordViews/modal/errors.py
18
21
  pycordViews/multibot/__init__.py
19
22
  pycordViews/multibot/bot.py
20
23
  pycordViews/multibot/errors.py
@@ -34,6 +37,9 @@ pycordViews/menu/__init__.py
34
37
  pycordViews/menu/errors.py
35
38
  pycordViews/menu/menu.py
36
39
  pycordViews/menu/selectMenu.py
40
+ pycordViews/modal/__init__.py
41
+ pycordViews/modal/easy_modal_view.py
42
+ pycordViews/modal/errors.py
37
43
  pycordViews/multibot/__init__.py
38
44
  pycordViews/multibot/bot.py
39
45
  pycordViews/multibot/errors.py
@@ -1,6 +1,7 @@
1
1
  pycordViews
2
2
  pycordViews/kit
3
3
  pycordViews/menu
4
+ pycordViews/modal
4
5
  pycordViews/multibot
5
6
  pycordViews/pagination
6
7
  pycordViews/views
@@ -0,0 +1,2 @@
1
+ from .easy_modal_view import EasyModal
2
+ from .errors import *
@@ -0,0 +1,99 @@
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
+ return partial(self.set_inputText_callable, x.custom_id)
45
+
46
+ def set_inputText_callable(self, inputText_id: str, _callable: Callable) -> "EasyModal":
47
+ """
48
+ Set an asynchronous function to a single inputText. _callable function was called when modal is completed by the user
49
+
50
+ x = EasyModal(title="test")
51
+ # init '8878' custom_id for one inputtext
52
+
53
+ x.set_inputText_callable(inputText_id='8878', _callable=set_any)
54
+
55
+ async def set_any(data: InputText, interaction: Interaction):
56
+ ...
57
+ """
58
+ if not iscoroutinefunction(_callable):
59
+ raise CoroutineError(_callable)
60
+
61
+ if inputText_id not in self.__callback.keys():
62
+ raise CustomIDNotFound(inputText_id)
63
+
64
+ self.__callback[inputText_id] = _callable
65
+ return self
66
+
67
+ def del_inputText_callable(self, inputText_id: str) -> "EasyModal":
68
+ """
69
+ Delete callable object link to the inputText ID
70
+ :param inputText_id: ID to the inputText
71
+ """
72
+ if inputText_id not in self.__callback.keys():
73
+ raise CustomIDNotFound(inputText_id)
74
+
75
+ self.__callback[inputText_id] = None
76
+
77
+ async def callback(self, interaction: Interaction):
78
+ """
79
+ Call when the user submit the modal.
80
+ All callable function set to the user get the 'interaction' parameter.
81
+ """
82
+
83
+ if self.__global_callable is not None:
84
+ await self.__global_callable(self, interaction)
85
+
86
+ for inputTextID, _callable in self.__callback.items():
87
+ if _callable is not None:
88
+ await _callable(self.get_input_text(inputTextID),interaction)
89
+
90
+ def get_input_text(self, inputText_id: str) -> InputText:
91
+ """
92
+ Return the inputText associated to the inputText_id
93
+ :param inputText_id: ID inputText
94
+ """
95
+ for i in self.children:
96
+ if i.custom_id == inputText_id:
97
+ return i
98
+
99
+ 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 !")
@@ -5,7 +5,7 @@ with open("README.md", encoding='utf-8') as file:
5
5
 
6
6
  setup(
7
7
  name="PycordViews",
8
- version="1.2.7",
8
+ version="1.2.8",
9
9
  url="https://github.com/BOXERRMD/Py-cord_Views",
10
10
  author="Chronos (alias BOXERRMD)",
11
11
  author_email="vagabonwalybi@gmail.com",
@@ -27,6 +27,6 @@ setup(
27
27
  install_requires=[
28
28
  "immutable-Python-type"
29
29
  ],
30
- packages=['pycordViews', 'pycordViews/pagination', 'pycordViews/views', 'pycordViews/menu', 'pycordViews/multibot', 'pycordViews/kit'],
30
+ packages=['pycordViews', 'pycordViews/pagination', 'pycordViews/views', 'pycordViews/menu', 'pycordViews/multibot', 'pycordViews/kit', 'pycordViews/modal'],
31
31
  python_requires='>=3.9'
32
32
  )
File without changes
File without changes
File without changes
File without changes