PycordViews 1.2.4__tar.gz → 1.2.5__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 (28) hide show
  1. {pycordviews-1.2.4 → pycordviews-1.2.5}/PKG-INFO +1 -1
  2. {pycordviews-1.2.4 → pycordviews-1.2.5}/PycordViews.egg-info/PKG-INFO +1 -1
  3. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/__init__.py +1 -0
  4. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/views/easy_modified_view.py +29 -15
  5. pycordviews-1.2.5/pycordViews/views/errors.py +13 -0
  6. {pycordviews-1.2.4 → pycordviews-1.2.5}/setup.py +1 -1
  7. pycordviews-1.2.4/pycordViews/views/errors.py +0 -9
  8. {pycordviews-1.2.4 → pycordviews-1.2.5}/LICENSE +0 -0
  9. {pycordviews-1.2.4 → pycordviews-1.2.5}/PycordViews.egg-info/SOURCES.txt +0 -0
  10. {pycordviews-1.2.4 → pycordviews-1.2.5}/PycordViews.egg-info/dependency_links.txt +0 -0
  11. {pycordviews-1.2.4 → pycordviews-1.2.5}/PycordViews.egg-info/requires.txt +0 -0
  12. {pycordviews-1.2.4 → pycordviews-1.2.5}/PycordViews.egg-info/top_level.txt +0 -0
  13. {pycordviews-1.2.4 → pycordviews-1.2.5}/README.md +0 -0
  14. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/menu/__init__.py +0 -0
  15. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/menu/errors.py +0 -0
  16. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/menu/menu.py +0 -0
  17. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/menu/selectMenu.py +0 -0
  18. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/multibot/__init__.py +0 -0
  19. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/multibot/bot.py +0 -0
  20. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/multibot/errors.py +0 -0
  21. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/multibot/multibot.py +0 -0
  22. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/multibot/process.py +0 -0
  23. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/pagination/__init__.py +0 -0
  24. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/pagination/errors.py +0 -0
  25. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/pagination/pagination_view.py +0 -0
  26. {pycordviews-1.2.4 → pycordviews-1.2.5}/pycordViews/views/__init__.py +0 -0
  27. {pycordviews-1.2.4 → pycordviews-1.2.5}/pyproject.toml +0 -0
  28. {pycordviews-1.2.4 → pycordviews-1.2.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PycordViews
3
- Version: 1.2.4
3
+ Version: 1.2.5
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.4
3
+ Version: 1.2.5
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)
@@ -3,3 +3,4 @@ from .pagination.pagination_view import Pagination
3
3
  from .multibot import Multibot
4
4
  from .menu.selectMenu import SelectMenu
5
5
  from .menu.menu import Menu, CustomSelect
6
+ from .kit import *
@@ -1,13 +1,16 @@
1
1
  from __future__ import annotations
2
- from discord import Interaction, ApplicationContext, Message, Member, TextChannel
2
+ from discord import Interaction, ApplicationContext, Message, Member
3
+ from discord.abc import GuildChannel
3
4
  from discord.ui import View, Item
4
- from typing import Union, Callable, TYPE_CHECKING
5
+ from typing import Union, Callable, TYPE_CHECKING, Optional, Any
6
+ from asyncio import iscoroutinefunction, create_task, get_event_loop, Future
5
7
 
6
- from .errors import CustomIDNotFound
8
+ from .errors import CustomIDNotFound, CoroutineError
7
9
 
8
10
  if TYPE_CHECKING:
9
11
  from ..menu.selectMenu import SelectMenu
10
12
  from ..pagination.pagination_view import Pagination
13
+ from ..kit import Poll, Confirm
11
14
 
12
15
 
13
16
  class EasyModifiedViews(View):
@@ -17,16 +20,19 @@ class EasyModifiedViews(View):
17
20
  Allows you to easily modify and replace an ui.
18
21
  """
19
22
 
20
- def __init__(self, timeout: Union[float, None] = None, disabled_on_timeout: bool = False, *items: Item):
23
+ def __init__(self, timeout: Optional[float] = None, disabled_on_timeout: bool = False, call_on_timeout: Optional[Callable] = None, *items: Item):
21
24
  """
22
25
  Init a Class view for Discord UI
23
26
  :param timeout: The time before ui disable
27
+ :param disabled_on_timeout: disable view if timeout is reached
28
+ :param call_on_timeout: asynchronous function to call after view timed-out
24
29
  """
25
30
  super().__init__(*items, timeout=timeout)
26
- self.__timeout: Union[float, None] = timeout
31
+ self.__timeout: Optional[float] = timeout
27
32
  self.__disabled_on_timeout: bool = disabled_on_timeout
28
33
  self.__callback: dict[str, dict[str, Union[Callable[[Interaction], None], Item]]] = {}
29
34
  self.__ctx: Union[Message, Interaction] = None
35
+ self.__call_on_timeout: Callable = call_on_timeout
30
36
 
31
37
  def __check_custom_id(self, custom_id: str) -> None:
32
38
  """
@@ -43,21 +49,21 @@ class EasyModifiedViews(View):
43
49
  """
44
50
  self.__ctx = await ctx.respond(*args, **kwargs)
45
51
 
46
- async def send(self, target: Union[Member, TextChannel], *args, **kwargs) -> None:
52
+ async def send(self, target: Union[Member, GuildChannel], *args, **kwargs) -> None:
47
53
  """
48
54
  Send at the target
49
55
  """
50
56
  self.__ctx = await target.send(*args, **kwargs)
51
57
 
52
58
  def add_items(self,
53
- *items: Union[Item, SelectMenu, Pagination]) -> "EasyModifiedViews":
59
+ *items: Union[Item, SelectMenu, Pagination, Poll, Confirm]) -> "EasyModifiedViews":
54
60
  """
55
61
  Add all items in the View.
56
62
  """
57
63
 
58
64
  for ui in items:
59
65
 
60
- if type(ui).__name__ in ('SelectMenu', 'Pagination'):
66
+ if type(ui).__name__ in ('SelectMenu', 'Pagination', 'Confirm', 'Poll'):
61
67
  for item in ui.get_view.items:
62
68
  self.add_items(item)
63
69
  self.set_callable(item.custom_id, _callable=ui.get_callable(item.custom_id))
@@ -118,7 +124,7 @@ class EasyModifiedViews(View):
118
124
  """
119
125
  set up a callable for items
120
126
  :param custom_ids: items IDs of the view
121
- :param _callable: The callable linked
127
+ :param _callable: The asynchronous callable linked. Take UI (Button, Select...) and Interaction parameters.
122
128
 
123
129
  **UI and Interaction parameter is required in callable function !**
124
130
 
@@ -230,7 +236,6 @@ class EasyModifiedViews(View):
230
236
 
231
237
  return True
232
238
 
233
-
234
239
  async def delete_items(self, clear_all: bool = False, *custom_ids: str) -> None:
235
240
  """
236
241
  Delete an item on the view
@@ -254,13 +259,25 @@ class EasyModifiedViews(View):
254
259
  Called if timeout view is finished
255
260
  """
256
261
  if self.__disabled_on_timeout:
257
- self.shutdown()
262
+ create_task(self.shutdown())
263
+ if self.__call_on_timeout is not None:
264
+ create_task(self.__call_on_timeout(self.__ctx))
265
+
266
+ def call_on_timeout(self, _callable: Callable) -> None:
267
+ """
268
+ Call asynchronous function passed when the timeout is reached.
269
+ :param _callable: asynchronous function to call. It takes one argument : ctx
270
+ """
271
+ if iscoroutinefunction(_callable):
272
+ self.__call_on_timeout = _callable
273
+ else:
274
+ raise CoroutineError(_callable)
258
275
 
259
276
  async def _update(self) -> None:
260
277
  """
261
278
  Update the View on the attached message.
262
279
  """
263
- if self.is_finished():
280
+ if self.is_finished() and not self.__disabled_on_timeout:
264
281
  return
265
282
 
266
283
  if self.message:
@@ -269,9 +286,6 @@ class EasyModifiedViews(View):
269
286
  elif self.__ctx:
270
287
  await self.__ctx.edit(view=self)
271
288
 
272
- else:
273
- return
274
-
275
289
  @property
276
290
  def get_uis(self) -> list[Item]:
277
291
  """
@@ -0,0 +1,13 @@
1
+ class Py_cordEasyModifiedViews(Exception):
2
+ """
3
+ Main class exception
4
+ """
5
+
6
+
7
+ class CustomIDNotFound(Py_cordEasyModifiedViews):
8
+ def __init__(self):
9
+ super().__init__(f"custom_id not found !")
10
+
11
+ class CoroutineError(Py_cordEasyModifiedViews):
12
+ def __init__(self, coro):
13
+ 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.4",
8
+ version="1.2.5",
9
9
  url="https://github.com/BOXERRMD/Py-cord_Views",
10
10
  author="Chronos (alias BOXERRMD)",
11
11
  author_email="vagabonwalybi@gmail.com",
@@ -1,9 +0,0 @@
1
- class Py_cordEasyModifiedViews(Exception):
2
- """
3
- Main class exception
4
- """
5
-
6
-
7
- class CustomIDNotFound(Py_cordEasyModifiedViews):
8
- def __init__(self):
9
- super().__init__(f"custom_id not found !")
File without changes
File without changes
File without changes
File without changes