telegrinder 1.0.0rc1__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.
Files changed (215) hide show
  1. telegrinder/__init__.py +258 -0
  2. telegrinder/__meta__.py +1 -0
  3. telegrinder/api/__init__.py +15 -0
  4. telegrinder/api/api.py +175 -0
  5. telegrinder/api/error.py +50 -0
  6. telegrinder/api/response.py +23 -0
  7. telegrinder/api/token.py +30 -0
  8. telegrinder/api/validators.py +30 -0
  9. telegrinder/bot/__init__.py +144 -0
  10. telegrinder/bot/bot.py +70 -0
  11. telegrinder/bot/cute_types/__init__.py +41 -0
  12. telegrinder/bot/cute_types/base.py +228 -0
  13. telegrinder/bot/cute_types/base.pyi +49 -0
  14. telegrinder/bot/cute_types/business_connection.py +9 -0
  15. telegrinder/bot/cute_types/business_messages_deleted.py +9 -0
  16. telegrinder/bot/cute_types/callback_query.py +248 -0
  17. telegrinder/bot/cute_types/chat_boost_removed.py +9 -0
  18. telegrinder/bot/cute_types/chat_boost_updated.py +9 -0
  19. telegrinder/bot/cute_types/chat_join_request.py +59 -0
  20. telegrinder/bot/cute_types/chat_member_updated.py +158 -0
  21. telegrinder/bot/cute_types/chosen_inline_result.py +11 -0
  22. telegrinder/bot/cute_types/inline_query.py +41 -0
  23. telegrinder/bot/cute_types/message.py +2809 -0
  24. telegrinder/bot/cute_types/message_reaction_count_updated.py +9 -0
  25. telegrinder/bot/cute_types/message_reaction_updated.py +9 -0
  26. telegrinder/bot/cute_types/paid_media_purchased.py +11 -0
  27. telegrinder/bot/cute_types/poll.py +9 -0
  28. telegrinder/bot/cute_types/poll_answer.py +9 -0
  29. telegrinder/bot/cute_types/pre_checkout_query.py +36 -0
  30. telegrinder/bot/cute_types/shipping_query.py +11 -0
  31. telegrinder/bot/cute_types/update.py +209 -0
  32. telegrinder/bot/cute_types/utils.py +141 -0
  33. telegrinder/bot/dispatch/__init__.py +99 -0
  34. telegrinder/bot/dispatch/abc.py +74 -0
  35. telegrinder/bot/dispatch/action.py +99 -0
  36. telegrinder/bot/dispatch/context.py +162 -0
  37. telegrinder/bot/dispatch/dispatch.py +362 -0
  38. telegrinder/bot/dispatch/handler/__init__.py +23 -0
  39. telegrinder/bot/dispatch/handler/abc.py +25 -0
  40. telegrinder/bot/dispatch/handler/audio_reply.py +43 -0
  41. telegrinder/bot/dispatch/handler/base.py +34 -0
  42. telegrinder/bot/dispatch/handler/document_reply.py +43 -0
  43. telegrinder/bot/dispatch/handler/func.py +73 -0
  44. telegrinder/bot/dispatch/handler/media_group_reply.py +43 -0
  45. telegrinder/bot/dispatch/handler/message_reply.py +35 -0
  46. telegrinder/bot/dispatch/handler/photo_reply.py +43 -0
  47. telegrinder/bot/dispatch/handler/sticker_reply.py +36 -0
  48. telegrinder/bot/dispatch/handler/video_reply.py +43 -0
  49. telegrinder/bot/dispatch/middleware/__init__.py +13 -0
  50. telegrinder/bot/dispatch/middleware/abc.py +112 -0
  51. telegrinder/bot/dispatch/middleware/box.py +32 -0
  52. telegrinder/bot/dispatch/middleware/filter.py +88 -0
  53. telegrinder/bot/dispatch/middleware/media_group.py +69 -0
  54. telegrinder/bot/dispatch/process.py +93 -0
  55. telegrinder/bot/dispatch/return_manager/__init__.py +21 -0
  56. telegrinder/bot/dispatch/return_manager/abc.py +107 -0
  57. telegrinder/bot/dispatch/return_manager/callback_query.py +19 -0
  58. telegrinder/bot/dispatch/return_manager/inline_query.py +14 -0
  59. telegrinder/bot/dispatch/return_manager/message.py +34 -0
  60. telegrinder/bot/dispatch/return_manager/pre_checkout_query.py +19 -0
  61. telegrinder/bot/dispatch/return_manager/utils.py +20 -0
  62. telegrinder/bot/dispatch/router/__init__.py +4 -0
  63. telegrinder/bot/dispatch/router/abc.py +15 -0
  64. telegrinder/bot/dispatch/router/base.py +154 -0
  65. telegrinder/bot/dispatch/view/__init__.py +15 -0
  66. telegrinder/bot/dispatch/view/abc.py +15 -0
  67. telegrinder/bot/dispatch/view/base.py +226 -0
  68. telegrinder/bot/dispatch/view/box.py +207 -0
  69. telegrinder/bot/dispatch/view/media_group.py +25 -0
  70. telegrinder/bot/dispatch/waiter_machine/__init__.py +25 -0
  71. telegrinder/bot/dispatch/waiter_machine/actions.py +16 -0
  72. telegrinder/bot/dispatch/waiter_machine/hasher/__init__.py +13 -0
  73. telegrinder/bot/dispatch/waiter_machine/hasher/callback.py +53 -0
  74. telegrinder/bot/dispatch/waiter_machine/hasher/hasher.py +61 -0
  75. telegrinder/bot/dispatch/waiter_machine/hasher/message.py +49 -0
  76. telegrinder/bot/dispatch/waiter_machine/machine.py +264 -0
  77. telegrinder/bot/dispatch/waiter_machine/middleware.py +77 -0
  78. telegrinder/bot/dispatch/waiter_machine/short_state.py +105 -0
  79. telegrinder/bot/polling/__init__.py +4 -0
  80. telegrinder/bot/polling/abc.py +25 -0
  81. telegrinder/bot/polling/error_handler.py +93 -0
  82. telegrinder/bot/polling/polling.py +167 -0
  83. telegrinder/bot/polling/utils.py +12 -0
  84. telegrinder/bot/rules/__init__.py +166 -0
  85. telegrinder/bot/rules/abc.py +150 -0
  86. telegrinder/bot/rules/button.py +20 -0
  87. telegrinder/bot/rules/callback_data.py +109 -0
  88. telegrinder/bot/rules/chat_join.py +28 -0
  89. telegrinder/bot/rules/chat_member_updated.py +145 -0
  90. telegrinder/bot/rules/command.py +137 -0
  91. telegrinder/bot/rules/enum_text.py +29 -0
  92. telegrinder/bot/rules/func.py +21 -0
  93. telegrinder/bot/rules/fuzzy.py +21 -0
  94. telegrinder/bot/rules/inline.py +45 -0
  95. telegrinder/bot/rules/integer.py +19 -0
  96. telegrinder/bot/rules/is_from.py +213 -0
  97. telegrinder/bot/rules/logic.py +22 -0
  98. telegrinder/bot/rules/magic.py +60 -0
  99. telegrinder/bot/rules/markup.py +51 -0
  100. telegrinder/bot/rules/media.py +13 -0
  101. telegrinder/bot/rules/mention.py +15 -0
  102. telegrinder/bot/rules/message_entities.py +37 -0
  103. telegrinder/bot/rules/node.py +43 -0
  104. telegrinder/bot/rules/payload.py +89 -0
  105. telegrinder/bot/rules/payment_invoice.py +14 -0
  106. telegrinder/bot/rules/regex.py +34 -0
  107. telegrinder/bot/rules/rule_enum.py +71 -0
  108. telegrinder/bot/rules/start.py +73 -0
  109. telegrinder/bot/rules/state.py +35 -0
  110. telegrinder/bot/rules/text.py +27 -0
  111. telegrinder/bot/rules/update.py +14 -0
  112. telegrinder/bot/scenario/__init__.py +5 -0
  113. telegrinder/bot/scenario/abc.py +16 -0
  114. telegrinder/bot/scenario/checkbox.py +183 -0
  115. telegrinder/bot/scenario/choice.py +44 -0
  116. telegrinder/client/__init__.py +11 -0
  117. telegrinder/client/abc.py +136 -0
  118. telegrinder/client/form_data.py +34 -0
  119. telegrinder/client/rnet.py +198 -0
  120. telegrinder/model.py +133 -0
  121. telegrinder/model.pyi +57 -0
  122. telegrinder/modules.py +1081 -0
  123. telegrinder/msgspec_utils/__init__.py +42 -0
  124. telegrinder/msgspec_utils/abc.py +16 -0
  125. telegrinder/msgspec_utils/custom_types/__init__.py +6 -0
  126. telegrinder/msgspec_utils/custom_types/datetime.py +24 -0
  127. telegrinder/msgspec_utils/custom_types/enum_meta.py +61 -0
  128. telegrinder/msgspec_utils/custom_types/literal.py +25 -0
  129. telegrinder/msgspec_utils/custom_types/option.py +17 -0
  130. telegrinder/msgspec_utils/decoder.py +388 -0
  131. telegrinder/msgspec_utils/encoder.py +204 -0
  132. telegrinder/msgspec_utils/json.py +15 -0
  133. telegrinder/msgspec_utils/tools.py +80 -0
  134. telegrinder/node/__init__.py +80 -0
  135. telegrinder/node/compose.py +193 -0
  136. telegrinder/node/nodes/__init__.py +96 -0
  137. telegrinder/node/nodes/attachment.py +169 -0
  138. telegrinder/node/nodes/callback_query.py +25 -0
  139. telegrinder/node/nodes/channel.py +97 -0
  140. telegrinder/node/nodes/command.py +33 -0
  141. telegrinder/node/nodes/error.py +43 -0
  142. telegrinder/node/nodes/event.py +70 -0
  143. telegrinder/node/nodes/file.py +39 -0
  144. telegrinder/node/nodes/global_node.py +66 -0
  145. telegrinder/node/nodes/i18n.py +110 -0
  146. telegrinder/node/nodes/me.py +26 -0
  147. telegrinder/node/nodes/message_entities.py +15 -0
  148. telegrinder/node/nodes/payload.py +84 -0
  149. telegrinder/node/nodes/reply_message.py +14 -0
  150. telegrinder/node/nodes/source.py +172 -0
  151. telegrinder/node/nodes/state_mutator.py +71 -0
  152. telegrinder/node/nodes/text.py +62 -0
  153. telegrinder/node/scope.py +88 -0
  154. telegrinder/node/utils.py +38 -0
  155. telegrinder/py.typed +0 -0
  156. telegrinder/rules.py +1 -0
  157. telegrinder/tools/__init__.py +183 -0
  158. telegrinder/tools/aio.py +147 -0
  159. telegrinder/tools/final.py +21 -0
  160. telegrinder/tools/formatting/__init__.py +85 -0
  161. telegrinder/tools/formatting/deep_links/__init__.py +39 -0
  162. telegrinder/tools/formatting/deep_links/links.py +468 -0
  163. telegrinder/tools/formatting/deep_links/parsing.py +88 -0
  164. telegrinder/tools/formatting/deep_links/validators.py +8 -0
  165. telegrinder/tools/formatting/html.py +241 -0
  166. telegrinder/tools/fullname.py +82 -0
  167. telegrinder/tools/global_context/__init__.py +13 -0
  168. telegrinder/tools/global_context/abc.py +63 -0
  169. telegrinder/tools/global_context/builtin_context.py +45 -0
  170. telegrinder/tools/global_context/global_context.py +614 -0
  171. telegrinder/tools/input_file_directory.py +30 -0
  172. telegrinder/tools/keyboard/__init__.py +6 -0
  173. telegrinder/tools/keyboard/abc.py +84 -0
  174. telegrinder/tools/keyboard/base.py +108 -0
  175. telegrinder/tools/keyboard/button.py +181 -0
  176. telegrinder/tools/keyboard/data.py +31 -0
  177. telegrinder/tools/keyboard/keyboard.py +160 -0
  178. telegrinder/tools/keyboard/utils.py +95 -0
  179. telegrinder/tools/lifespan.py +188 -0
  180. telegrinder/tools/limited_dict.py +35 -0
  181. telegrinder/tools/loop_wrapper.py +271 -0
  182. telegrinder/tools/magic/__init__.py +29 -0
  183. telegrinder/tools/magic/annotations.py +172 -0
  184. telegrinder/tools/magic/descriptors.py +57 -0
  185. telegrinder/tools/magic/function.py +254 -0
  186. telegrinder/tools/magic/inspect.py +16 -0
  187. telegrinder/tools/magic/shortcut.py +107 -0
  188. telegrinder/tools/member_descriptor_proxy.py +95 -0
  189. telegrinder/tools/parse_mode.py +12 -0
  190. telegrinder/tools/serialization/__init__.py +5 -0
  191. telegrinder/tools/serialization/abc.py +34 -0
  192. telegrinder/tools/serialization/json_ser.py +60 -0
  193. telegrinder/tools/serialization/msgpack_ser.py +197 -0
  194. telegrinder/tools/serialization/utils.py +18 -0
  195. telegrinder/tools/singleton/__init__.py +4 -0
  196. telegrinder/tools/singleton/abc.py +14 -0
  197. telegrinder/tools/singleton/singleton.py +18 -0
  198. telegrinder/tools/state_mutator/__init__.py +4 -0
  199. telegrinder/tools/state_mutator/mutation.py +85 -0
  200. telegrinder/tools/state_storage/__init__.py +4 -0
  201. telegrinder/tools/state_storage/abc.py +38 -0
  202. telegrinder/tools/state_storage/memory.py +27 -0
  203. telegrinder/tools/strings.py +22 -0
  204. telegrinder/types/__init__.py +323 -0
  205. telegrinder/types/enums.py +754 -0
  206. telegrinder/types/input_file.py +51 -0
  207. telegrinder/types/methods.py +6143 -0
  208. telegrinder/types/methods_utils.py +66 -0
  209. telegrinder/types/objects.py +8184 -0
  210. telegrinder/types/webapp.py +129 -0
  211. telegrinder/verification_utils.py +35 -0
  212. telegrinder-1.0.0rc1.dist-info/METADATA +166 -0
  213. telegrinder-1.0.0rc1.dist-info/RECORD +215 -0
  214. telegrinder-1.0.0rc1.dist-info/WHEEL +4 -0
  215. telegrinder-1.0.0rc1.dist-info/licenses/LICENSE +22 -0
@@ -0,0 +1,248 @@
1
+ import base64
2
+ import typing
3
+ from contextlib import suppress
4
+ from datetime import timedelta
5
+
6
+ import msgspec
7
+ from kungfu.library import Nothing, Result, Some, Sum, unwrapping
8
+ from kungfu.library.monad.option import NOTHING
9
+
10
+ from telegrinder.api.api import APIError
11
+ from telegrinder.bot.cute_types.base import BaseCute, compose_method_params, shortcut
12
+ from telegrinder.bot.cute_types.message import (
13
+ MessageCute,
14
+ MessageEditShortcuts,
15
+ ReplyMarkup,
16
+ execute_method_edit,
17
+ )
18
+ from telegrinder.model import UNSET, From, field
19
+ from telegrinder.msgspec_utils import Option, decoder
20
+ from telegrinder.types.methods_utils import get_params
21
+ from telegrinder.types.objects import *
22
+
23
+ CACHED_CALLBACK_DATA_KEY: typing.Final = "cached_callback_data"
24
+
25
+
26
+ class CallbackQueryCute(BaseCute[CallbackQuery], MessageEditShortcuts, CallbackQuery, kw_only=True):
27
+ message: Option[Sum[MessageCute, InaccessibleMessage]] = field(
28
+ default=UNSET,
29
+ converter=From[MessageCute | InaccessibleMessage | None],
30
+ )
31
+ """Optional. Message sent by the bot with the callback button that originated
32
+ the query."""
33
+
34
+ @property
35
+ def from_user(self) -> User:
36
+ return self.from_
37
+
38
+ @property
39
+ @unwrapping
40
+ def message_cute(self) -> Option[MessageCute]:
41
+ return self.message.unwrap().only().cast(Some, Nothing)
42
+
43
+ @property
44
+ def chat_id(self) -> Option[int]:
45
+ """Optional. Message from chat ID. This will be present if the message is sent
46
+ by the bot with the callback button that originated the query.
47
+ """
48
+ return self.message.map(lambda m: m.v.chat.id)
49
+
50
+ @property
51
+ def is_topic_message(self) -> Option[bool]:
52
+ """Optional. True, if the message is a topic message with a name,
53
+ color and icon. This will be present if the message is sent
54
+ by the bot with the callback button that originated the query.
55
+ """
56
+ return self.message.map(
57
+ lambda m: m.only().map(lambda m: m.is_topic_message.unwrap_or(False)).unwrap_or(False),
58
+ )
59
+
60
+ @property
61
+ @unwrapping
62
+ def message_thread_id(self) -> Option[int]:
63
+ """Optional. Unique identifier of the target message thread (for forum supergroups only).
64
+ This will be present if the message is sent
65
+ by the bot with the callback button that originated the query.
66
+ """
67
+ return self.message.unwrap().only().map(lambda m: m.message_thread_id.unwrap()).cast(Some, Nothing)
68
+
69
+ @property
70
+ def message_id(self) -> Option[int]:
71
+ """Optional. Unique message identifier inside this chat. This will be present
72
+ if the message is sent by the bot with the callback button that originated the query.
73
+ """
74
+ return self.message.map(lambda m: m.v.message_id)
75
+
76
+ @property
77
+ def chat(self) -> Option[Chat]:
78
+ """Optional. Chat the callback query originated from. This will be present
79
+ if the message is sent by the bot with the callback button that originated the query.
80
+ """
81
+ return self.message.map(lambda m: m.v.chat)
82
+
83
+ @typing.overload
84
+ def decode_data(self) -> Option[dict[str, typing.Any]]: ...
85
+
86
+ @typing.overload
87
+ def decode_data[T](self, *, to: type[T]) -> Option[T]: ...
88
+
89
+ def decode_data[T](self, *, to: type[T] = dict[str, typing.Any]) -> Option[T]:
90
+ if not self.data:
91
+ return NOTHING
92
+
93
+ keys = typing.cast(
94
+ "dict[type[typing.Any], typing.Any]",
95
+ self.__dict__.setdefault(CACHED_CALLBACK_DATA_KEY, {}), # type: ignore
96
+ )
97
+ if to in keys:
98
+ return keys[to]
99
+
100
+ data = NOTHING
101
+ orig_to = typing.get_origin(to) or to
102
+
103
+ with suppress(msgspec.ValidationError, msgspec.DecodeError):
104
+ data = (
105
+ Some(decoder.decode(self.data.unwrap(), type=to))
106
+ if not issubclass(orig_to, str | bytes)
107
+ else self.data
108
+ if issubclass(orig_to, str)
109
+ else Some(base64.urlsafe_b64decode(self.data.unwrap()))
110
+ )
111
+
112
+ keys[to] = data
113
+ return data # type: ignore
114
+
115
+ @shortcut("answer_callback_query", custom_params={"callback_query_id"})
116
+ async def answer(
117
+ self,
118
+ text: str | None = None,
119
+ *,
120
+ cache_time: timedelta | int | None = None,
121
+ callback_query_id: str | None = None,
122
+ show_alert: bool | None = None,
123
+ url: str | None = None,
124
+ **other: typing.Any,
125
+ ) -> Result[bool, APIError]:
126
+ """Shortcut `API.answer_callback_query()`, see the [documentation](https://core.telegram.org/bots/api#answercallbackquery)
127
+
128
+ Use this method to send answers to callback queries sent from inline keyboards.
129
+ The answer will be displayed to the user as a notification at the top of the
130
+ chat screen or as an alert. On success, True is returned."""
131
+ params = compose_method_params(get_params(locals()), self, default_params={("callback_query_id", "id")})
132
+ return await self.ctx_api.answer_callback_query(**params)
133
+
134
+ @shortcut(
135
+ "copy_message",
136
+ custom_params={
137
+ "message_thread_id",
138
+ "chat_id",
139
+ "message_id",
140
+ "from_chat_id",
141
+ "reply_markup",
142
+ },
143
+ )
144
+ async def copy(
145
+ self,
146
+ chat_id: int | str | None = None,
147
+ *,
148
+ allow_paid_broadcast: bool | None = None,
149
+ caption: str | None = None,
150
+ caption_entities: list[MessageEntity] | None = None,
151
+ direct_messages_topic_id: int | None = None,
152
+ disable_notification: bool | None = None,
153
+ from_chat_id: int | str | None = None,
154
+ message_effect_id: str | None = None,
155
+ message_id: int | None = None,
156
+ message_thread_id: str | None = None,
157
+ parse_mode: str | None = None,
158
+ protect_content: bool | None = None,
159
+ reply_markup: ReplyMarkup | None = None,
160
+ reply_parameters: ReplyParameters | None = None,
161
+ show_caption_above_media: bool | None = None,
162
+ suggested_post_parameters: SuggestedPostParameters | None = None,
163
+ video_start_timestamp: timedelta | int | None = None,
164
+ **other: typing.Any,
165
+ ) -> Result[MessageId, APIError]:
166
+ """Shortcut `API.copy_message()`, see the [documentation](https://core.telegram.org/bots/api#copymessage)
167
+
168
+ Use this method to copy messages of any kind. Service messages, paid media
169
+ messages, giveaway messages, giveaway winners messages, and invoice
170
+ messages can't be copied. A quiz poll can be copied only if the value of the
171
+ field correct_option_id is known to the bot. The method is analogous to
172
+ the method forwardMessage, but the copied message doesn't have a link to
173
+ the original message. Returns the MessageId of the sent message on success."""
174
+ return await MessageCute.copy(self, **get_params(locals())) # type: ignore
175
+
176
+ @shortcut("delete_message", custom_params={"message_thread_id", "chat_id", "message_id"})
177
+ async def delete(
178
+ self,
179
+ *,
180
+ chat_id: int | None = None,
181
+ message_id: int | None = None,
182
+ message_thread_id: str | None = None,
183
+ **other: typing.Any,
184
+ ) -> Result[bool, APIError]:
185
+ """Shortcut `API.delete_message()`, see the [documentation](https://core.telegram.org/bots/api#deletemessage)
186
+
187
+ Use this method to delete a message, including service messages, with the
188
+ following limitations: - A message can only be deleted if it was sent less
189
+ than 48 hours ago. - Service messages about a supergroup, channel, or forum
190
+ topic creation can't be deleted. - A dice message in a private chat can only
191
+ be deleted if it was sent more than 24 hours ago. - Bots can delete outgoing
192
+ messages in private chats, groups, and supergroups. - Bots can delete incoming
193
+ messages in private chats. - Bots granted can_post_messages permissions
194
+ can delete outgoing messages in channels. - If the bot is an administrator
195
+ of a group, it can delete any message there. - If the bot has can_delete_messages
196
+ administrator right in a supergroup or a channel, it can delete any message
197
+ there. - If the bot has can_manage_direct_messages administrator right
198
+ in a channel, it can delete any message in the corresponding direct messages
199
+ chat. Returns True on success."""
200
+ return await MessageCute.delete(self, **get_params(locals())) # type: ignore
201
+
202
+ @shortcut(
203
+ "edit_message_text",
204
+ executor=execute_method_edit,
205
+ custom_params={"message_thread_id"},
206
+ )
207
+ async def edit_text(
208
+ self,
209
+ text: str,
210
+ *,
211
+ business_connection_id: str | None = None,
212
+ chat_id: int | str | None = None,
213
+ entities: list[MessageEntity] | None = None,
214
+ inline_message_id: str | None = None,
215
+ link_preview_options: LinkPreviewOptions | None = None,
216
+ message_id: int | None = None,
217
+ message_thread_id: str | None = None,
218
+ parse_mode: str | None = None,
219
+ reply_markup: InlineKeyboardMarkup | None = None,
220
+ **other: typing.Any,
221
+ ) -> Result[Sum[MessageCute, bool], APIError]:
222
+ """Shortcut `API.edit_message_text()`, see the [documentation](https://core.telegram.org/bots/api#editmessagetext)
223
+
224
+ Use this method to edit text and game messages. On success, if the edited
225
+ message is not an inline message, the edited Message is returned, otherwise
226
+ True is returned. Note that business messages that were not sent by the bot
227
+ and do not contain an inline keyboard can only be edited within 48 hours from
228
+ the time they were sent.
229
+ :param business_connection_id: Unique identifier of the business connection on behalf of which the messageto be edited was sent.
230
+
231
+ :param chat_id: Required if inline_message_id is not specified. Unique identifier forthe target chat or username of the target channel (in the format @channelusername).
232
+ :param message_id: Required if inline_message_id is not specified. Identifier of the messageto edit.
233
+
234
+ :param inline_message_id: Required if chat_id and message_id are not specified. Identifier of theinline message.
235
+
236
+ :param text: New text of the message, 1-4096 characters after entities parsing.
237
+
238
+ :param parse_mode: Mode for parsing entities in the message text. See formatting options formore details.
239
+
240
+ :param entities: A JSON-serialized list of special entities that appear in message text,which can be specified instead of parse_mode.
241
+
242
+ :param link_preview_options: Link preview generation options for the message.
243
+
244
+ :param reply_markup: A JSON-serialized object for an inline keyboard."""
245
+ ...
246
+
247
+
248
+ __all__ = ("CallbackQueryCute",)
@@ -0,0 +1,9 @@
1
+ from telegrinder.bot.cute_types.base import BaseCute
2
+ from telegrinder.types.objects import ChatBoostRemoved
3
+
4
+
5
+ class ChatBoostRemovedCute(BaseCute[ChatBoostRemoved], ChatBoostRemoved, kw_only=True):
6
+ pass
7
+
8
+
9
+ __all__ = ("ChatBoostRemovedCute",)
@@ -0,0 +1,9 @@
1
+ from telegrinder.bot.cute_types.base import BaseCute
2
+ from telegrinder.types.objects import ChatBoostUpdated
3
+
4
+
5
+ class ChatBoostUpdatedCute(BaseCute[ChatBoostUpdated], ChatBoostUpdated, kw_only=True):
6
+ pass
7
+
8
+
9
+ __all__ = ("ChatBoostUpdatedCute",)
@@ -0,0 +1,59 @@
1
+ import typing
2
+
3
+ from kungfu.library.monad.result import Result
4
+
5
+ from telegrinder.api.api import APIError
6
+ from telegrinder.bot.cute_types.base import BaseCute, shortcut
7
+ from telegrinder.bot.cute_types.chat_member_updated import ChatMemberShortcuts, chat_member_interaction
8
+ from telegrinder.types.objects import *
9
+
10
+
11
+ class ChatJoinRequestCute(BaseCute[ChatJoinRequest], ChatJoinRequest, ChatMemberShortcuts, kw_only=True):
12
+ @property
13
+ def from_user(self) -> User:
14
+ return self.from_
15
+
16
+ @property
17
+ def user_id(self) -> int:
18
+ return self.from_user.id
19
+
20
+ @shortcut(
21
+ "approve_chat_join_request",
22
+ executor=chat_member_interaction,
23
+ custom_params={"chat_id", "user_id"},
24
+ )
25
+ async def approve(
26
+ self,
27
+ *,
28
+ chat_id: int | str | None = None,
29
+ user_id: int | None = None,
30
+ **other: typing.Any,
31
+ ) -> Result[bool, APIError]:
32
+ """Shortcut `API.approve_chat_join_request()`, see the [documentation](https://core.telegram.org/bots/api#approvechatjoinrequest)
33
+
34
+ Use this method to approve a chat join request. The bot must be an administrator
35
+ in the chat for this to work and must have the can_invite_users administrator
36
+ right. Returns True on success."""
37
+ ...
38
+
39
+ @shortcut(
40
+ "decline_chat_join_request",
41
+ executor=chat_member_interaction,
42
+ custom_params={"chat_id", "user_id"},
43
+ )
44
+ async def decline(
45
+ self,
46
+ *,
47
+ chat_id: int | str | None = None,
48
+ user_id: int | None = None,
49
+ **other: typing.Any,
50
+ ) -> Result[bool, APIError]:
51
+ """Shortcut `API.decline_chat_join_request()`, see the [documentation](https://core.telegram.org/bots/api#declinechatjoinrequest)
52
+
53
+ Use this method to decline a chat join request. The bot must be an administrator
54
+ in the chat for this to work and must have the can_invite_users administrator
55
+ right. Returns True on success."""
56
+ ...
57
+
58
+
59
+ __all__ = ("ChatJoinRequestCute",)
@@ -0,0 +1,158 @@
1
+ import typing
2
+ from datetime import datetime
3
+
4
+ from kungfu.library.monad.result import Result
5
+
6
+ from telegrinder.api.api import APIError
7
+ from telegrinder.bot.cute_types.base import BaseCute, BaseShortcuts, compose_method_params, shortcut
8
+ from telegrinder.types.methods_utils import get_params
9
+ from telegrinder.types.objects import *
10
+
11
+ if typing.TYPE_CHECKING:
12
+ from telegrinder.bot.cute_types.chat_join_request import ChatJoinRequestCute # noqa
13
+
14
+
15
+ async def chat_member_interaction(
16
+ update: typing.Any,
17
+ method_name: str,
18
+ params: dict[str, typing.Any],
19
+ ) -> Result[typing.Any, APIError]:
20
+ params = compose_method_params(
21
+ get_params(params),
22
+ update,
23
+ default_params={"chat_id", "user_id"},
24
+ )
25
+ return await getattr(update.ctx_api, method_name)(**params)
26
+
27
+
28
+ class ChatMemberShortcuts(BaseShortcuts["ChatMemberUpdatedCute | ChatJoinRequestCute"]):
29
+ """Shortcut methods for `ChatMemberUpdatedCute`, `ChatJoinRequestCute` objects."""
30
+
31
+ @shortcut("ban_chat_member", executor=chat_member_interaction, custom_params={"chat_id", "user_id"})
32
+ async def ban_chat_member(
33
+ self,
34
+ *,
35
+ chat_id: int | str | None = None,
36
+ revoke_messages: bool | None = None,
37
+ until_date: datetime | int | None = None,
38
+ user_id: int | None = None,
39
+ **other: typing.Any,
40
+ ) -> Result[bool, APIError]:
41
+ """Shortcut `API.ban_chat_member()`, see the [documentation](https://core.telegram.org/bots/api#banchatmember)
42
+
43
+ Use this method to ban a user in a group, a supergroup or a channel. In the case
44
+ of supergroups and channels, the user will not be able to return to the chat
45
+ on their own using invite links, etc., unless unbanned first. The bot must
46
+ be an administrator in the chat for this to work and must have the appropriate
47
+ administrator rights. Returns True on success."""
48
+ ...
49
+
50
+ @shortcut("unban_chat_member", executor=chat_member_interaction, custom_params={"chat_id", "user_id"})
51
+ async def unban_chat_member(
52
+ self,
53
+ *,
54
+ chat_id: int | str | None = None,
55
+ only_if_banned: bool | None = None,
56
+ user_id: int | None = None,
57
+ **other: typing.Any,
58
+ ) -> Result[bool, APIError]:
59
+ """Shortcut `API.unban_chat_member()`, see the [documentation](https://core.telegram.org/bots/api#unbanchatmember)
60
+
61
+ Use this method to unban a previously banned user in a supergroup or channel.
62
+ The user will not return to the group or channel automatically, but will
63
+ be able to join via link, etc. The bot must be an administrator for this to
64
+ work. By default, this method guarantees that after the call the user is
65
+ not a member of the chat, but will be able to join it. So if the user is a member
66
+ of the chat they will also be removed from the chat. If you don't want this,
67
+ use the parameter only_if_banned. Returns True on success."""
68
+ ...
69
+
70
+ @shortcut(
71
+ "restrict_chat_member",
72
+ executor=chat_member_interaction,
73
+ custom_params={"chat_id", "user_id"},
74
+ )
75
+ async def restrict_chat_member(
76
+ self,
77
+ *,
78
+ permissions: ChatPermissions,
79
+ chat_id: int | str | None = None,
80
+ until_date: datetime | int | None = None,
81
+ use_independent_chat_permissions: bool | None = None,
82
+ user_id: int | None = None,
83
+ **other: typing.Any,
84
+ ) -> Result[bool, APIError]:
85
+ """Shortcut `API.restrict_chat_member()`, see the [documentation](https://core.telegram.org/bots/api#restrictchatmember)
86
+
87
+ Use this method to restrict a user in a supergroup. The bot must be an administrator
88
+ in the supergroup for this to work and must have the appropriate administrator
89
+ rights. Pass True for all permissions to lift restrictions from a user.
90
+ Returns True on success."""
91
+ ...
92
+
93
+ @shortcut("promote_chat_member", executor=chat_member_interaction, custom_params={"chat_id", "user_id"})
94
+ async def promote_chat_member(
95
+ self,
96
+ *,
97
+ can_change_info: bool | None = None,
98
+ can_delete_messages: bool | None = None,
99
+ can_delete_stories: bool | None = None,
100
+ can_edit_messages: bool | None = None,
101
+ can_edit_stories: bool | None = None,
102
+ can_invite_users: bool | None = None,
103
+ can_manage_chat: bool | None = None,
104
+ can_manage_direct_messages: bool | None = None,
105
+ can_manage_topics: bool | None = None,
106
+ can_manage_video_chats: bool | None = None,
107
+ can_pin_messages: bool | None = None,
108
+ can_post_messages: bool | None = None,
109
+ can_post_stories: bool | None = None,
110
+ can_promote_members: bool | None = None,
111
+ can_restrict_members: bool | None = None,
112
+ chat_id: int | str | None = None,
113
+ is_anonymous: bool | None = None,
114
+ user_id: int | None = None,
115
+ **other: typing.Any,
116
+ ) -> Result[bool, APIError]:
117
+ """Shortcut `API.promote_chat_member()`, see the [documentation](https://core.telegram.org/bots/api#promotechatmember)
118
+
119
+ Use this method to promote or demote a user in a supergroup or a channel. The
120
+ bot must be an administrator in the chat for this to work and must have the
121
+ appropriate administrator rights. Pass False for all boolean parameters
122
+ to demote a user. Returns True on success."""
123
+ ...
124
+
125
+ @shortcut(
126
+ "set_chat_administrator_custom_title",
127
+ executor=chat_member_interaction,
128
+ custom_params={"chat_id", "user_id"},
129
+ )
130
+ async def set_chat_administrator_custom_title(
131
+ self,
132
+ *,
133
+ custom_title: str,
134
+ chat_id: int | str | None = None,
135
+ user_id: int | None = None,
136
+ **other: typing.Any,
137
+ ) -> Result[bool, APIError]:
138
+ """Shortcut `API.set_chat_administrator_custom_title()`, see the [documentation](https://core.telegram.org/bots/api#setchatadministratorcustomtitle)
139
+
140
+ Use this method to set a custom title for an administrator in a supergroup
141
+ promoted by the bot. Returns True on success."""
142
+ ...
143
+
144
+
145
+ class ChatMemberUpdatedCute(BaseCute[ChatMemberUpdated], ChatMemberUpdated, ChatMemberShortcuts, kw_only=True):
146
+ @property
147
+ def from_user(self) -> User:
148
+ return self.from_
149
+
150
+ @property
151
+ def user_id(self) -> int:
152
+ return self.from_user.id
153
+
154
+
155
+ __all__ = (
156
+ "ChatMemberShortcuts",
157
+ "ChatMemberUpdatedCute",
158
+ )
@@ -0,0 +1,11 @@
1
+ from telegrinder.bot.cute_types.base import BaseCute
2
+ from telegrinder.types.objects import ChosenInlineResult, User
3
+
4
+
5
+ class ChosenInlineResultCute(BaseCute[ChosenInlineResult], ChosenInlineResult, kw_only=True):
6
+ @property
7
+ def from_user(self) -> User:
8
+ return self.from_
9
+
10
+
11
+ __all__ = ("ChosenInlineResultCute",)
@@ -0,0 +1,41 @@
1
+ import typing
2
+
3
+ from kungfu.library.monad.result import Result
4
+
5
+ from telegrinder.api.api import APIError
6
+ from telegrinder.bot.cute_types.base import BaseCute, compose_method_params, shortcut
7
+ from telegrinder.types.methods_utils import get_params
8
+ from telegrinder.types.objects import *
9
+
10
+
11
+ class InlineQueryCute(BaseCute[InlineQuery], InlineQuery, kw_only=True):
12
+ @property
13
+ def from_user(self) -> User:
14
+ return self.from_
15
+
16
+ @shortcut("answer_inline_query", custom_params={"results", "inline_query_id"})
17
+ async def answer(
18
+ self,
19
+ results: InlineQueryResult | list[InlineQueryResult],
20
+ *,
21
+ button: InlineQueryResultsButton | None = None,
22
+ cache_time: int | None = None,
23
+ inline_query_id: str | None = None,
24
+ is_personal: bool | None = None,
25
+ next_offset: str | None = None,
26
+ **other: typing.Any,
27
+ ) -> Result[bool, APIError]:
28
+ """Shortcut `API.answer_inline_query()`, see the [documentation](https://core.telegram.org/bots/api#answerinlinequery)
29
+
30
+ Use this method to send answers to an inline query. On success, True is returned.
31
+ No more than 50 results per query are allowed."""
32
+ params = compose_method_params(
33
+ get_params(locals()),
34
+ self,
35
+ default_params={("inline_query_id", "id")},
36
+ )
37
+ params["results"] = [results] if not isinstance(results, list) else results
38
+ return await self.ctx_api.answer_inline_query(**params)
39
+
40
+
41
+ __all__ = ("InlineQueryCute",)