telegrinder 0.3.4.post1__py3-none-any.whl → 0.4.1__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.

Potentially problematic release.


This version of telegrinder might be problematic. Click here for more details.

Files changed (169) hide show
  1. telegrinder/__init__.py +30 -31
  2. telegrinder/api/__init__.py +2 -1
  3. telegrinder/api/api.py +28 -20
  4. telegrinder/api/error.py +8 -4
  5. telegrinder/api/response.py +2 -2
  6. telegrinder/api/token.py +2 -2
  7. telegrinder/bot/__init__.py +6 -0
  8. telegrinder/bot/bot.py +38 -31
  9. telegrinder/bot/cute_types/__init__.py +2 -0
  10. telegrinder/bot/cute_types/base.py +55 -129
  11. telegrinder/bot/cute_types/callback_query.py +76 -61
  12. telegrinder/bot/cute_types/chat_join_request.py +4 -3
  13. telegrinder/bot/cute_types/chat_member_updated.py +28 -31
  14. telegrinder/bot/cute_types/inline_query.py +5 -4
  15. telegrinder/bot/cute_types/message.py +555 -602
  16. telegrinder/bot/cute_types/pre_checkout_query.py +42 -0
  17. telegrinder/bot/cute_types/update.py +20 -12
  18. telegrinder/bot/cute_types/utils.py +3 -36
  19. telegrinder/bot/dispatch/__init__.py +4 -0
  20. telegrinder/bot/dispatch/abc.py +8 -9
  21. telegrinder/bot/dispatch/context.py +5 -7
  22. telegrinder/bot/dispatch/dispatch.py +85 -33
  23. telegrinder/bot/dispatch/handler/abc.py +5 -6
  24. telegrinder/bot/dispatch/handler/audio_reply.py +2 -2
  25. telegrinder/bot/dispatch/handler/base.py +3 -3
  26. telegrinder/bot/dispatch/handler/document_reply.py +2 -2
  27. telegrinder/bot/dispatch/handler/func.py +36 -42
  28. telegrinder/bot/dispatch/handler/media_group_reply.py +5 -4
  29. telegrinder/bot/dispatch/handler/message_reply.py +2 -2
  30. telegrinder/bot/dispatch/handler/photo_reply.py +2 -2
  31. telegrinder/bot/dispatch/handler/sticker_reply.py +2 -2
  32. telegrinder/bot/dispatch/handler/video_reply.py +2 -2
  33. telegrinder/bot/dispatch/middleware/abc.py +83 -8
  34. telegrinder/bot/dispatch/middleware/global_middleware.py +70 -0
  35. telegrinder/bot/dispatch/process.py +44 -50
  36. telegrinder/bot/dispatch/return_manager/__init__.py +2 -0
  37. telegrinder/bot/dispatch/return_manager/abc.py +6 -10
  38. telegrinder/bot/dispatch/return_manager/pre_checkout_query.py +20 -0
  39. telegrinder/bot/dispatch/view/__init__.py +2 -0
  40. telegrinder/bot/dispatch/view/abc.py +10 -6
  41. telegrinder/bot/dispatch/view/base.py +81 -50
  42. telegrinder/bot/dispatch/view/box.py +20 -9
  43. telegrinder/bot/dispatch/view/callback_query.py +3 -4
  44. telegrinder/bot/dispatch/view/chat_join_request.py +2 -7
  45. telegrinder/bot/dispatch/view/chat_member.py +3 -5
  46. telegrinder/bot/dispatch/view/inline_query.py +3 -4
  47. telegrinder/bot/dispatch/view/message.py +3 -4
  48. telegrinder/bot/dispatch/view/pre_checkout_query.py +16 -0
  49. telegrinder/bot/dispatch/view/raw.py +42 -40
  50. telegrinder/bot/dispatch/waiter_machine/actions.py +5 -4
  51. telegrinder/bot/dispatch/waiter_machine/hasher/__init__.py +0 -0
  52. telegrinder/bot/dispatch/waiter_machine/hasher/callback.py +0 -0
  53. telegrinder/bot/dispatch/waiter_machine/hasher/hasher.py +9 -7
  54. telegrinder/bot/dispatch/waiter_machine/hasher/message.py +0 -0
  55. telegrinder/bot/dispatch/waiter_machine/hasher/state.py +3 -2
  56. telegrinder/bot/dispatch/waiter_machine/machine.py +113 -34
  57. telegrinder/bot/dispatch/waiter_machine/middleware.py +15 -10
  58. telegrinder/bot/dispatch/waiter_machine/short_state.py +7 -18
  59. telegrinder/bot/polling/polling.py +62 -54
  60. telegrinder/bot/rules/__init__.py +24 -1
  61. telegrinder/bot/rules/abc.py +17 -10
  62. telegrinder/bot/rules/callback_data.py +20 -61
  63. telegrinder/bot/rules/chat_join.py +6 -4
  64. telegrinder/bot/rules/command.py +4 -4
  65. telegrinder/bot/rules/enum_text.py +1 -4
  66. telegrinder/bot/rules/func.py +5 -3
  67. telegrinder/bot/rules/fuzzy.py +1 -1
  68. telegrinder/bot/rules/id.py +24 -0
  69. telegrinder/bot/rules/inline.py +6 -4
  70. telegrinder/bot/rules/integer.py +2 -1
  71. telegrinder/bot/rules/logic.py +18 -0
  72. telegrinder/bot/rules/markup.py +5 -6
  73. telegrinder/bot/rules/message.py +2 -4
  74. telegrinder/bot/rules/message_entities.py +1 -3
  75. telegrinder/bot/rules/node.py +15 -9
  76. telegrinder/bot/rules/payload.py +81 -0
  77. telegrinder/bot/rules/payment_invoice.py +29 -0
  78. telegrinder/bot/rules/regex.py +5 -6
  79. telegrinder/bot/rules/state.py +1 -3
  80. telegrinder/bot/rules/text.py +10 -5
  81. telegrinder/bot/rules/update.py +0 -0
  82. telegrinder/bot/scenario/abc.py +2 -4
  83. telegrinder/bot/scenario/checkbox.py +12 -14
  84. telegrinder/bot/scenario/choice.py +6 -9
  85. telegrinder/client/__init__.py +9 -1
  86. telegrinder/client/abc.py +35 -10
  87. telegrinder/client/aiohttp.py +28 -24
  88. telegrinder/client/form_data.py +31 -0
  89. telegrinder/client/sonic.py +212 -0
  90. telegrinder/model.py +38 -145
  91. telegrinder/modules.py +3 -1
  92. telegrinder/msgspec_utils.py +136 -68
  93. telegrinder/node/__init__.py +74 -13
  94. telegrinder/node/attachment.py +92 -16
  95. telegrinder/node/base.py +196 -68
  96. telegrinder/node/callback_query.py +17 -16
  97. telegrinder/node/command.py +3 -2
  98. telegrinder/node/composer.py +40 -75
  99. telegrinder/node/container.py +13 -7
  100. telegrinder/node/either.py +82 -0
  101. telegrinder/node/event.py +20 -31
  102. telegrinder/node/file.py +51 -0
  103. telegrinder/node/me.py +4 -5
  104. telegrinder/node/payload.py +78 -0
  105. telegrinder/node/polymorphic.py +28 -9
  106. telegrinder/node/rule.py +2 -6
  107. telegrinder/node/scope.py +4 -6
  108. telegrinder/node/source.py +37 -21
  109. telegrinder/node/text.py +20 -8
  110. telegrinder/node/tools/generator.py +7 -11
  111. telegrinder/py.typed +0 -0
  112. telegrinder/rules.py +0 -61
  113. telegrinder/tools/__init__.py +97 -38
  114. telegrinder/tools/adapter/__init__.py +19 -0
  115. telegrinder/tools/adapter/abc.py +49 -0
  116. telegrinder/tools/adapter/dataclass.py +56 -0
  117. telegrinder/{bot/rules → tools}/adapter/event.py +8 -10
  118. telegrinder/{bot/rules → tools}/adapter/node.py +8 -10
  119. telegrinder/{bot/rules → tools}/adapter/raw_event.py +2 -2
  120. telegrinder/{bot/rules → tools}/adapter/raw_update.py +2 -2
  121. telegrinder/tools/buttons.py +52 -26
  122. telegrinder/tools/callback_data_serilization/__init__.py +5 -0
  123. telegrinder/tools/callback_data_serilization/abc.py +51 -0
  124. telegrinder/tools/callback_data_serilization/json_ser.py +60 -0
  125. telegrinder/tools/callback_data_serilization/msgpack_ser.py +172 -0
  126. telegrinder/tools/error_handler/abc.py +4 -7
  127. telegrinder/tools/error_handler/error.py +0 -0
  128. telegrinder/tools/error_handler/error_handler.py +34 -48
  129. telegrinder/tools/formatting/__init__.py +57 -37
  130. telegrinder/tools/formatting/deep_links.py +541 -0
  131. telegrinder/tools/formatting/{html.py → html_formatter.py} +51 -79
  132. telegrinder/tools/formatting/spec_html_formats.py +14 -60
  133. telegrinder/tools/functional.py +1 -5
  134. telegrinder/tools/global_context/global_context.py +26 -51
  135. telegrinder/tools/global_context/telegrinder_ctx.py +3 -3
  136. telegrinder/tools/i18n/abc.py +0 -0
  137. telegrinder/tools/i18n/middleware/abc.py +3 -6
  138. telegrinder/tools/input_file_directory.py +30 -0
  139. telegrinder/tools/keyboard.py +9 -9
  140. telegrinder/tools/lifespan.py +105 -0
  141. telegrinder/tools/limited_dict.py +5 -10
  142. telegrinder/tools/loop_wrapper/abc.py +7 -2
  143. telegrinder/tools/loop_wrapper/loop_wrapper.py +40 -95
  144. telegrinder/tools/magic.py +236 -60
  145. telegrinder/tools/state_storage/__init__.py +0 -0
  146. telegrinder/tools/state_storage/abc.py +5 -9
  147. telegrinder/tools/state_storage/memory.py +1 -1
  148. telegrinder/tools/strings.py +13 -0
  149. telegrinder/types/__init__.py +8 -0
  150. telegrinder/types/enums.py +31 -21
  151. telegrinder/types/input_file.py +51 -0
  152. telegrinder/types/methods.py +531 -109
  153. telegrinder/types/objects.py +934 -826
  154. telegrinder/verification_utils.py +0 -2
  155. {telegrinder-0.3.4.post1.dist-info → telegrinder-0.4.1.dist-info}/LICENSE +2 -2
  156. telegrinder-0.4.1.dist-info/METADATA +143 -0
  157. telegrinder-0.4.1.dist-info/RECORD +182 -0
  158. {telegrinder-0.3.4.post1.dist-info → telegrinder-0.4.1.dist-info}/WHEEL +1 -1
  159. telegrinder/bot/rules/adapter/__init__.py +0 -17
  160. telegrinder/bot/rules/adapter/abc.py +0 -31
  161. telegrinder/node/message.py +0 -14
  162. telegrinder/node/update.py +0 -15
  163. telegrinder/tools/formatting/links.py +0 -38
  164. telegrinder/tools/kb_set/__init__.py +0 -4
  165. telegrinder/tools/kb_set/base.py +0 -15
  166. telegrinder/tools/kb_set/yaml.py +0 -63
  167. telegrinder-0.3.4.post1.dist-info/METADATA +0 -110
  168. telegrinder-0.3.4.post1.dist-info/RECORD +0 -165
  169. /telegrinder/{bot/rules → tools}/adapter/errors.py +0 -0
@@ -4,8 +4,9 @@ from datetime import datetime
4
4
  from fntypes.result import Result
5
5
 
6
6
  from telegrinder.api.api import API, APIError
7
- from telegrinder.bot.cute_types.base import BaseCute, compose_method_params, shortcut
7
+ from telegrinder.bot.cute_types.base import BaseCute, compose_method_params
8
8
  from telegrinder.model import get_params
9
+ from telegrinder.tools.magic import shortcut
9
10
  from telegrinder.types.objects import *
10
11
 
11
12
 
@@ -14,8 +15,6 @@ async def chat_member_interaction(
14
15
  method_name: str,
15
16
  params: dict[str, typing.Any],
16
17
  ) -> Result[typing.Any, APIError]:
17
- if isinstance(params.get("permissions"), dict):
18
- params["permissions"] = ChatPermissions(**params["permissions"])
19
18
  params = compose_method_params(
20
19
  get_params(locals()),
21
20
  update,
@@ -30,10 +29,11 @@ class ChatMemberShortcuts:
30
29
  @shortcut("ban_chat_member", executor=chat_member_interaction, custom_params={"chat_id", "user_id"})
31
30
  async def ban_chat_member(
32
31
  self,
32
+ *,
33
33
  chat_id: int | str | None = None,
34
- user_id: int | None = None,
35
- until_date: datetime | int | None = None,
36
34
  revoke_messages: bool | None = None,
35
+ until_date: datetime | int | None = None,
36
+ user_id: int | None = None,
37
37
  **other: typing.Any,
38
38
  ) -> Result[bool, APIError]:
39
39
  """Shortcut `API.ban_chat_member()`, see the [documentation](https://core.telegram.org/bots/api#banchatmember)
@@ -43,15 +43,15 @@ class ChatMemberShortcuts:
43
43
  on their own using invite links, etc., unless unbanned first. The bot must
44
44
  be an administrator in the chat for this to work and must have the appropriate
45
45
  administrator rights. Returns True on success."""
46
-
47
46
  ...
48
47
 
49
48
  @shortcut("unban_chat_member", executor=chat_member_interaction, custom_params={"chat_id", "user_id"})
50
49
  async def unban_chat_member(
51
50
  self,
51
+ *,
52
52
  chat_id: int | str | None = None,
53
- user_id: int | None = None,
54
53
  only_if_banned: bool | None = None,
54
+ user_id: int | None = None,
55
55
  **other: typing.Any,
56
56
  ) -> Result[bool, APIError]:
57
57
  """Shortcut `API.unban_chat_member()`, see the [documentation](https://core.telegram.org/bots/api#unbanchatmember)
@@ -63,21 +63,21 @@ class ChatMemberShortcuts:
63
63
  not a member of the chat, but will be able to join it. So if the user is a member
64
64
  of the chat they will also be removed from the chat. If you don't want this,
65
65
  use the parameter only_if_banned. Returns True on success."""
66
-
67
66
  ...
68
67
 
69
68
  @shortcut(
70
69
  "restrict_chat_member",
71
70
  executor=chat_member_interaction,
72
- custom_params={"permissions", "chat_id", "user_id"},
71
+ custom_params={"chat_id", "user_id"},
73
72
  )
74
73
  async def restrict_chat_member(
75
74
  self,
76
- permissions: ChatPermissions | dict[str, typing.Any],
75
+ *,
76
+ permissions: ChatPermissions,
77
77
  chat_id: int | str | None = None,
78
- user_id: int | None = None,
79
- use_independent_chat_permissions: bool | None = None,
80
78
  until_date: datetime | int | None = None,
79
+ use_independent_chat_permissions: bool | None = None,
80
+ user_id: int | None = None,
81
81
  **other: typing.Any,
82
82
  ) -> Result[bool, APIError]:
83
83
  """Shortcut `API.restrict_chat_member()`, see the [documentation](https://core.telegram.org/bots/api#restrictchatmember)
@@ -86,29 +86,29 @@ class ChatMemberShortcuts:
86
86
  in the supergroup for this to work and must have the appropriate administrator
87
87
  rights. Pass True for all permissions to lift restrictions from a user.
88
88
  Returns True on success."""
89
-
90
89
  ...
91
90
 
92
91
  @shortcut("promote_chat_member", executor=chat_member_interaction, custom_params={"chat_id", "user_id"})
93
92
  async def promote_chat_member(
94
93
  self,
95
- chat_id: int | str | None = None,
96
- user_id: int | None = None,
97
- is_anonymous: bool | None = None,
98
- can_manage_chat: bool | None = None,
99
- can_delete_messages: bool | None = None,
100
- can_manage_video_chats: bool | None = None,
101
- can_restrict_members: bool | None = None,
102
- can_promote_members: bool | None = None,
94
+ *,
103
95
  can_change_info: bool | None = None,
104
- can_invite_users: bool | None = None,
105
- can_post_stories: bool | None = None,
106
- can_edit_stories: bool | None = None,
96
+ can_delete_messages: bool | None = None,
107
97
  can_delete_stories: bool | None = None,
108
- can_post_messages: bool | None = None,
109
98
  can_edit_messages: bool | None = None,
110
- can_pin_messages: bool | None = None,
99
+ can_edit_stories: bool | None = None,
100
+ can_invite_users: bool | None = None,
101
+ can_manage_chat: bool | None = None,
111
102
  can_manage_topics: bool | None = None,
103
+ can_manage_video_chats: bool | None = None,
104
+ can_pin_messages: bool | None = None,
105
+ can_post_messages: bool | None = None,
106
+ can_post_stories: bool | None = None,
107
+ can_promote_members: bool | None = None,
108
+ can_restrict_members: bool | None = None,
109
+ chat_id: int | str | None = None,
110
+ is_anonymous: bool | None = None,
111
+ user_id: int | None = None,
112
112
  **other: typing.Any,
113
113
  ) -> Result[bool, APIError]:
114
114
  """Shortcut `API.promote_chat_member()`, see the [documentation](https://core.telegram.org/bots/api#promotechatmember)
@@ -117,7 +117,6 @@ class ChatMemberShortcuts:
117
117
  bot must be an administrator in the chat for this to work and must have the
118
118
  appropriate administrator rights. Pass False for all boolean parameters
119
119
  to demote a user. Returns True on success."""
120
-
121
120
  ...
122
121
 
123
122
  @shortcut(
@@ -127,6 +126,7 @@ class ChatMemberShortcuts:
127
126
  )
128
127
  async def set_chat_administrator_custom_title(
129
128
  self,
129
+ *,
130
130
  custom_title: str,
131
131
  chat_id: int | str | None = None,
132
132
  user_id: int | None = None,
@@ -136,13 +136,10 @@ class ChatMemberShortcuts:
136
136
 
137
137
  Use this method to set a custom title for an administrator in a supergroup
138
138
  promoted by the bot. Returns True on success."""
139
-
140
139
  ...
141
140
 
142
141
 
143
- class ChatMemberUpdatedCute(
144
- BaseCute[ChatMemberUpdated], ChatMemberUpdated, ChatMemberShortcuts, kw_only=True
145
- ):
142
+ class ChatMemberUpdatedCute(BaseCute[ChatMemberUpdated], ChatMemberUpdated, ChatMemberShortcuts, kw_only=True):
146
143
  api: API
147
144
 
148
145
  @property
@@ -3,8 +3,9 @@ import typing
3
3
  from fntypes.result import Result
4
4
 
5
5
  from telegrinder.api.api import API, APIError
6
- from telegrinder.bot.cute_types.base import BaseCute, compose_method_params, shortcut
6
+ from telegrinder.bot.cute_types.base import BaseCute, compose_method_params
7
7
  from telegrinder.model import get_params
8
+ from telegrinder.tools.magic import shortcut
8
9
  from telegrinder.types.objects import *
9
10
 
10
11
 
@@ -19,18 +20,18 @@ class InlineQueryCute(BaseCute[InlineQuery], InlineQuery, kw_only=True):
19
20
  async def answer(
20
21
  self,
21
22
  results: InlineQueryResult | list[InlineQueryResult],
22
- inline_query_id: str | None = None,
23
+ *,
24
+ button: InlineQueryResultsButton | None = None,
23
25
  cache_time: int | None = None,
26
+ inline_query_id: str | None = None,
24
27
  is_personal: bool | None = None,
25
28
  next_offset: str | None = None,
26
- button: InlineQueryResultsButton | None = None,
27
29
  **other: typing.Any,
28
30
  ) -> Result[bool, APIError]:
29
31
  """Shortcut `API.answer_inline_query()`, see the [documentation](https://core.telegram.org/bots/api#answerinlinequery)
30
32
 
31
33
  Use this method to send answers to an inline query. On success, True is returned.
32
34
  No more than 50 results per query are allowed."""
33
-
34
35
  params = compose_method_params(
35
36
  get_params(locals()),
36
37
  self,