aiogram_tool 1.2.0__tar.gz → 1.2.1__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 (31) hide show
  1. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/PKG-INFO +2 -2
  2. aiogram_tool-1.2.1/aiogram_tool/callback_data/__init__.py +5 -0
  3. aiogram_tool-1.2.1/aiogram_tool/callback_data/filter.py +67 -0
  4. aiogram_tool-1.2.1/aiogram_tool/callback_data/storage.py +17 -0
  5. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/setup.py +2 -2
  6. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/pyproject.toml +5 -2
  7. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/LICENSE.md +0 -0
  8. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/README.md +0 -0
  9. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/__init__.py +0 -0
  10. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/__init__.py +0 -0
  11. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/components/__init__.py +0 -0
  12. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/components/exit.py +0 -0
  13. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/components/handler.py +0 -0
  14. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/components/inner_middleware.py +0 -0
  15. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/depend.py +0 -0
  16. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/types/__init__.py +0 -0
  17. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/types/enums.py +0 -0
  18. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/types/schema.py +0 -0
  19. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/utils/__init__.py +0 -0
  20. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/utils/depend_scope.py +0 -0
  21. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/utils/explore_obj.py +0 -0
  22. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/depend/utils/inject_callback.py +0 -0
  23. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/limit/__init__.py +0 -0
  24. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/limit/limit.py +0 -0
  25. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/limit/setup.py +0 -0
  26. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/limit/storage/__init__.py +0 -0
  27. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/limit/storage/abstract_storage.py +0 -0
  28. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/limit/storage/memory_storage.py +0 -0
  29. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/limit/storage/redis_storage.py +0 -0
  30. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/limit/utils/__init__.py +0 -0
  31. {aiogram_tool-1.2.0 → aiogram_tool-1.2.1}/aiogram_tool/limit/utils/callback.py +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: aiogram_tool
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: Tools which doing work with aiogram simple
5
5
  License: MIT
6
- Keywords: aiogram,rate,throttling,limit,dependency-injection,depends,cooldown,delay,DI
6
+ Keywords: aiogram,rate,throttling,limit,dependency-injection,depends,cooldown,delay,DI,callback,data,long
7
7
  Author: Vlad_shayzi1
8
8
  Author-email: tecnomega@mail.ru
9
9
  Requires-Python: >=3.10
@@ -0,0 +1,5 @@
1
+ from .filter import LongCallbackData
2
+
3
+ __all__ = [
4
+ "LongCallbackData",
5
+ ]
@@ -0,0 +1,67 @@
1
+ from typing import Any
2
+ from string import digits, ascii_letters
3
+ from random import choice
4
+
5
+ from aiogram.filters.callback_data import CallbackQueryFilter, CallbackData
6
+ from aiogram.types import CallbackQuery
7
+ from magic_filter import MagicFilter
8
+
9
+ from .storage import data_storage
10
+
11
+
12
+
13
+ class UniqueIDCallbackData(CallbackData, prefix="?"):
14
+ mode: str = "__unique_id_callback"
15
+ unique_id: str
16
+
17
+
18
+
19
+ class LongCallbackQueryFilter(CallbackQueryFilter):
20
+
21
+ async def __call__(
22
+ self,
23
+ query: CallbackQuery,
24
+ ) -> bool | dict[str, Any]:
25
+ if not isinstance(query, CallbackQuery) or not query.data:
26
+ return False
27
+ try:
28
+ callback_data_model = (
29
+ UniqueIDCallbackData
30
+ if "__unique_id_callback" in query.data
31
+ else self.callback_data
32
+ )
33
+ callback_data = callback_data_model.unpack(query.data)
34
+ except (TypeError, ValueError):
35
+ return False
36
+
37
+ if isinstance(callback_data, UniqueIDCallbackData):
38
+ callback_data = data_storage.get_value(key=callback_data.unique_id)
39
+ if callback_data is None:
40
+ await query.answer("Button expired")
41
+ return False
42
+
43
+ if self.rule is None or self.rule.resolve(callback_data):
44
+ return {"callback_data": callback_data}
45
+ return False
46
+
47
+
48
+ class LongCallbackData(CallbackData, prefix="?"):
49
+
50
+ def pack(self) -> str:
51
+ try:
52
+ return super().pack()
53
+ except ValueError as ex:
54
+ if "long" in str(ex):
55
+ unique_id = self.__generate_unique_id()
56
+ data_storage.set_value(key=unique_id, value=self)
57
+ return UniqueIDCallbackData(unique_id=unique_id).pack()
58
+ raise ex
59
+
60
+ @classmethod
61
+ def filter(cls, rule: MagicFilter | None = None) -> LongCallbackQueryFilter:
62
+ return LongCallbackQueryFilter(callback_data=cls, rule=rule)
63
+
64
+
65
+ def __generate_unique_id(self) -> str:
66
+ symbols = ascii_letters + digits
67
+ return "".join([choice(symbols) for _ in range(35)])
@@ -0,0 +1,17 @@
1
+ from typing import Any
2
+
3
+
4
+
5
+ class DataStorage:
6
+ def __init__(self):
7
+ self._data: dict[str, Any] = {}
8
+
9
+ def set_value(self, key: str, value: Any) -> None:
10
+ self._data[key] = value
11
+
12
+ def get_value(self, key: str) -> Any:
13
+ return self._data.get(key)
14
+
15
+
16
+ data_storage = DataStorage()
17
+
@@ -31,8 +31,8 @@ def setup_depend_tool(
31
31
  observer.middleware(DependInnerMiddleware())
32
32
 
33
33
  else:
34
- for allow in dispatcher.resolve_used_update_types():
35
- observer: TelegramEventObserver = getattr(dispatcher, allow)
34
+ for update in dispatcher.resolve_used_update_types():
35
+ observer: TelegramEventObserver = dispatcher.observers.get(update)
36
36
  observer.middleware(DependInnerMiddleware())
37
37
 
38
38
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "aiogram_tool"
3
- version = "1.2.0"
3
+ version = "1.2.1"
4
4
  description = "Tools which doing work with aiogram simple"
5
5
  authors = [
6
6
  {name = "Vlad_shayzi1",email = "tecnomega@mail.ru"}
@@ -21,7 +21,10 @@ keywords = [
21
21
  "depends",
22
22
  "cooldown",
23
23
  "delay",
24
- "DI"
24
+ "DI",
25
+ "callback",
26
+ "data",
27
+ "long"
25
28
  ]
26
29
 
27
30
 
File without changes
File without changes