telegrinder 0.1.dev165__py3-none-any.whl → 0.1.dev166__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 (88) hide show
  1. telegrinder/__init__.py +22 -0
  2. telegrinder/api/abc.py +1 -1
  3. telegrinder/api/api.py +8 -6
  4. telegrinder/api/error.py +2 -3
  5. telegrinder/bot/__init__.py +14 -0
  6. telegrinder/bot/bot.py +5 -3
  7. telegrinder/bot/cute_types/__init__.py +4 -0
  8. telegrinder/bot/cute_types/base.py +22 -13
  9. telegrinder/bot/cute_types/chat_join_request.py +63 -0
  10. telegrinder/bot/cute_types/chat_member_updated.py +244 -0
  11. telegrinder/bot/cute_types/message.py +34 -7
  12. telegrinder/bot/cute_types/update.py +5 -4
  13. telegrinder/bot/cute_types/utils.py +39 -17
  14. telegrinder/bot/dispatch/__init__.py +9 -1
  15. telegrinder/bot/dispatch/composition.py +10 -8
  16. telegrinder/bot/dispatch/context.py +9 -10
  17. telegrinder/bot/dispatch/dispatch.py +29 -19
  18. telegrinder/bot/dispatch/handler/abc.py +1 -0
  19. telegrinder/bot/dispatch/handler/func.py +29 -6
  20. telegrinder/bot/dispatch/handler/message_reply.py +2 -3
  21. telegrinder/bot/dispatch/middleware/abc.py +2 -4
  22. telegrinder/bot/dispatch/process.py +4 -3
  23. telegrinder/bot/dispatch/return_manager/__init__.py +1 -1
  24. telegrinder/bot/dispatch/return_manager/abc.py +33 -21
  25. telegrinder/bot/dispatch/return_manager/callback_query.py +4 -2
  26. telegrinder/bot/dispatch/return_manager/inline_query.py +4 -2
  27. telegrinder/bot/dispatch/return_manager/message.py +12 -6
  28. telegrinder/bot/dispatch/view/__init__.py +8 -2
  29. telegrinder/bot/dispatch/view/abc.py +26 -20
  30. telegrinder/bot/dispatch/view/box.py +72 -1
  31. telegrinder/bot/dispatch/view/callback_query.py +1 -3
  32. telegrinder/bot/dispatch/view/chat_join_request.py +17 -0
  33. telegrinder/bot/dispatch/view/chat_member.py +26 -0
  34. telegrinder/bot/dispatch/view/message.py +23 -1
  35. telegrinder/bot/dispatch/view/raw.py +116 -0
  36. telegrinder/bot/dispatch/waiter_machine/__init__.py +2 -1
  37. telegrinder/bot/dispatch/waiter_machine/machine.py +73 -19
  38. telegrinder/bot/dispatch/waiter_machine/middleware.py +3 -3
  39. telegrinder/bot/dispatch/waiter_machine/short_state.py +6 -3
  40. telegrinder/bot/polling/polling.py +4 -2
  41. telegrinder/bot/rules/__init__.py +20 -12
  42. telegrinder/bot/rules/abc.py +0 -9
  43. telegrinder/bot/rules/adapter/event.py +31 -22
  44. telegrinder/bot/rules/callback_data.py +15 -20
  45. telegrinder/bot/rules/chat_join.py +47 -0
  46. telegrinder/bot/rules/enum_text.py +7 -2
  47. telegrinder/bot/rules/inline.py +3 -3
  48. telegrinder/bot/rules/is_from.py +36 -50
  49. telegrinder/bot/rules/message.py +17 -0
  50. telegrinder/bot/rules/message_entities.py +1 -1
  51. telegrinder/bot/rules/start.py +6 -4
  52. telegrinder/bot/rules/text.py +2 -1
  53. telegrinder/bot/rules/update.py +16 -0
  54. telegrinder/bot/scenario/checkbox.py +9 -7
  55. telegrinder/client/aiohttp.py +4 -4
  56. telegrinder/model.py +33 -19
  57. telegrinder/modules.py +16 -32
  58. telegrinder/msgspec_utils.py +37 -36
  59. telegrinder/node/__init__.py +12 -12
  60. telegrinder/node/attachment.py +15 -5
  61. telegrinder/node/base.py +24 -16
  62. telegrinder/node/composer.py +8 -6
  63. telegrinder/node/container.py +1 -1
  64. telegrinder/node/rule.py +4 -4
  65. telegrinder/node/source.py +4 -2
  66. telegrinder/node/tools/generator.py +1 -1
  67. telegrinder/tools/__init__.py +1 -1
  68. telegrinder/tools/error_handler/abc.py +4 -3
  69. telegrinder/tools/error_handler/error_handler.py +22 -16
  70. telegrinder/tools/formatting/html.py +15 -7
  71. telegrinder/tools/formatting/spec_html_formats.py +1 -1
  72. telegrinder/tools/global_context/abc.py +5 -1
  73. telegrinder/tools/global_context/telegrinder_ctx.py +1 -1
  74. telegrinder/tools/i18n/base.py +4 -3
  75. telegrinder/tools/i18n/simple.py +1 -3
  76. telegrinder/tools/keyboard.py +1 -1
  77. telegrinder/tools/loop_wrapper/loop_wrapper.py +24 -16
  78. telegrinder/tools/magic.py +1 -1
  79. telegrinder/types/__init__.py +206 -0
  80. telegrinder/types/enums.py +34 -0
  81. telegrinder/types/methods.py +52 -47
  82. telegrinder/types/objects.py +531 -88
  83. telegrinder/verification_utils.py +3 -1
  84. {telegrinder-0.1.dev165.dist-info → telegrinder-0.1.dev166.dist-info}/METADATA +1 -1
  85. telegrinder-0.1.dev166.dist-info/RECORD +136 -0
  86. telegrinder-0.1.dev165.dist-info/RECORD +0 -128
  87. {telegrinder-0.1.dev165.dist-info → telegrinder-0.1.dev166.dist-info}/LICENSE +0 -0
  88. {telegrinder-0.1.dev165.dist-info → telegrinder-0.1.dev166.dist-info}/WHEEL +0 -0
telegrinder/__init__.py CHANGED
@@ -52,6 +52,10 @@ from .bot import (
52
52
  CallbackQueryCute,
53
53
  CallbackQueryReturnManager,
54
54
  CallbackQueryView,
55
+ ChatJoinRequestCute,
56
+ ChatJoinRequestView,
57
+ ChatMemberUpdatedCute,
58
+ ChatMemberView,
55
59
  Checkbox,
56
60
  Dispatch,
57
61
  FuncHandler,
@@ -63,8 +67,12 @@ from .bot import (
63
67
  MessageRule,
64
68
  MessageView,
65
69
  Polling,
70
+ RawEventView,
71
+ ShortState,
72
+ ShortStateStorage,
66
73
  SingleChoice,
67
74
  Telegrinder,
75
+ UpdateCute,
68
76
  ViewBox,
69
77
  WaiterMachine,
70
78
  register_manager,
@@ -102,7 +110,10 @@ from .tools import (
102
110
  magic_bundle,
103
111
  )
104
112
 
113
+ Update: typing.TypeAlias = UpdateCute
105
114
  Message: typing.TypeAlias = MessageCute
115
+ ChatJoinRequest: typing.TypeAlias = ChatJoinRequestCute
116
+ ChatMemberUpdated: typing.TypeAlias = ChatMemberUpdatedCute
106
117
  CallbackQuery: typing.TypeAlias = CallbackQueryCute
107
118
  InlineQuery: typing.TypeAlias = InlineQueryCute
108
119
  Bot: typing.TypeAlias = Telegrinder
@@ -140,6 +151,12 @@ __all__ = (
140
151
  "CallbackQueryCute",
141
152
  "CallbackQueryReturnManager",
142
153
  "CallbackQueryView",
154
+ "ChatJoinRequest",
155
+ "ChatJoinRequestCute",
156
+ "ChatJoinRequestView",
157
+ "ChatMemberUpdated",
158
+ "ChatMemberUpdatedCute",
159
+ "ChatMemberView",
143
160
  "Checkbox",
144
161
  "CtxVar",
145
162
  "DelayedTask",
@@ -169,12 +186,17 @@ __all__ = (
169
186
  "Model",
170
187
  "ParseMode",
171
188
  "Polling",
189
+ "RawEventView",
172
190
  "RowButtons",
191
+ "ShortState",
192
+ "ShortStateStorage",
173
193
  "SimpleI18n",
174
194
  "SimpleTranslator",
175
195
  "SingleChoice",
176
196
  "Telegrinder",
177
197
  "Token",
198
+ "Update",
199
+ "UpdateCute",
178
200
  "ViewBox",
179
201
  "WaiterMachine",
180
202
  "ctx_var",
telegrinder/api/abc.py CHANGED
@@ -17,7 +17,7 @@ class Token(str):
17
17
  if token.count(":") != 1 or not token.split(":")[0].isdigit():
18
18
  raise InvalidTokenError("Invalid token, it should look like this '123:ABC'.")
19
19
  return super().__new__(cls, token)
20
-
20
+
21
21
  def __repr__(self) -> str:
22
22
  return f"<Token: {self.bot_id}:{''.join(self.split(':')[-1])[:6]}...>"
23
23
 
telegrinder/api/api.py CHANGED
@@ -32,7 +32,7 @@ class API(ABCAPI, APIMethods):
32
32
  self.token = token
33
33
  self.http = http or AiohttpClient()
34
34
  super().__init__(self)
35
-
35
+
36
36
  def __repr__(self) -> str:
37
37
  return "<{}: token={!r}, http={!r}>".format(
38
38
  self.__class__.__name__,
@@ -56,15 +56,17 @@ class API(ABCAPI, APIMethods):
56
56
  ) -> Result[dict[str, typing.Any] | list[typing.Any] | bool, APIError]:
57
57
  response = await self.http.request_json(
58
58
  url=self.request_url + method,
59
- data=compose_data(self.http, data or {}, files or {})
59
+ data=compose_data(self.http, data or {}, files or {}),
60
60
  )
61
61
  if response.get("ok"):
62
62
  assert "result" in response
63
63
  return Ok(response["result"])
64
- return Error(APIError(
65
- code=response.get("error_code", 400),
66
- error=response.get("description"),
67
- ))
64
+ return Error(
65
+ APIError(
66
+ code=response.get("error_code", 400),
67
+ error=response.get("description"),
68
+ )
69
+ )
68
70
 
69
71
  async def request_raw(
70
72
  self,
telegrinder/api/error.py CHANGED
@@ -1,7 +1,7 @@
1
1
  class APIError(BaseException):
2
2
  def __init__(self, code: int, error: str | None = None) -> None:
3
3
  self.code, self.error = code, error
4
-
4
+
5
5
  def __str__(self) -> str:
6
6
  return f"[{self.code}] {self.error or 'Something went wrong'}"
7
7
 
@@ -9,8 +9,7 @@ class APIError(BaseException):
9
9
  return f"<APIError: {self.__str__()}>"
10
10
 
11
11
 
12
- class InvalidTokenError(BaseException):
13
- ...
12
+ class InvalidTokenError(BaseException): ...
14
13
 
15
14
 
16
15
  __all__ = ("APIError", "InvalidTokenError")
@@ -2,6 +2,8 @@ from .bot import Telegrinder
2
2
  from .cute_types import (
3
3
  BaseCute,
4
4
  CallbackQueryCute,
5
+ ChatJoinRequestCute,
6
+ ChatMemberUpdatedCute,
5
7
  InlineQueryCute,
6
8
  MessageCute,
7
9
  UpdateCute,
@@ -18,6 +20,8 @@ from .dispatch import (
18
20
  BaseView,
19
21
  CallbackQueryReturnManager,
20
22
  CallbackQueryView,
23
+ ChatJoinRequestView,
24
+ ChatMemberView,
21
25
  CompositionDispatch,
22
26
  Context,
23
27
  Dispatch,
@@ -27,6 +31,9 @@ from .dispatch import (
27
31
  MessageReplyHandler,
28
32
  MessageReturnManager,
29
33
  MessageView,
34
+ RawEventView,
35
+ ShortState,
36
+ ShortStateStorage,
30
37
  ViewBox,
31
38
  WaiterMachine,
32
39
  register_manager,
@@ -53,6 +60,10 @@ __all__ = (
53
60
  "CallbackQueryReturnManager",
54
61
  "CallbackQueryRule",
55
62
  "CallbackQueryView",
63
+ "ChatJoinRequestCute",
64
+ "ChatJoinRequestView",
65
+ "ChatMemberUpdatedCute",
66
+ "ChatMemberView",
56
67
  "Checkbox",
57
68
  "CompositionDispatch",
58
69
  "Context",
@@ -67,6 +78,9 @@ __all__ = (
67
78
  "MessageRule",
68
79
  "MessageView",
69
80
  "Polling",
81
+ "RawEventView",
82
+ "ShortState",
83
+ "ShortStateStorage",
70
84
  "SingleChoice",
71
85
  "Telegrinder",
72
86
  "UpdateCute",
telegrinder/bot/bot.py CHANGED
@@ -11,7 +11,7 @@ PollingT = typing.TypeVar("PollingT", bound=ABCPolling, default=Polling)
11
11
  LoopWrapperT = typing.TypeVar("LoopWrapperT", bound=ABCLoopWrapper, default=LoopWrapper)
12
12
 
13
13
 
14
- class Telegrinder(typing.Generic[DispatchT, PollingT, LoopWrapperT]):
14
+ class Telegrinder(typing.Generic[DispatchT, PollingT, LoopWrapperT]):
15
15
  def __init__(
16
16
  self,
17
17
  api: API,
@@ -24,7 +24,7 @@ class Telegrinder(typing.Generic[DispatchT, PollingT, LoopWrapperT]):
24
24
  self.dispatch = typing.cast(DispatchT, dispatch or Dispatch())
25
25
  self.polling = typing.cast(PollingT, polling or Polling(api))
26
26
  self.loop_wrapper = typing.cast(LoopWrapperT, loop_wrapper or LoopWrapper())
27
-
27
+
28
28
  def __repr__(self) -> str:
29
29
  return "<{}: api={!r}, dispatch={!r}, polling={!r}, loop_wrapper={!r}>".format(
30
30
  self.__class__.__name__,
@@ -57,7 +57,9 @@ class Telegrinder(typing.Generic[DispatchT, PollingT, LoopWrapperT]):
57
57
 
58
58
  def run_forever(self, *, offset: int = 0, skip_updates: bool = False) -> None:
59
59
  logger.debug("Running blocking polling (id={})", self.api.id)
60
- self.loop_wrapper.add_task(self.run_polling(offset=offset, skip_updates=skip_updates))
60
+ self.loop_wrapper.add_task(
61
+ self.run_polling(offset=offset, skip_updates=skip_updates)
62
+ )
61
63
  self.loop_wrapper.run_event_loop()
62
64
 
63
65
 
@@ -1,5 +1,7 @@
1
1
  from .base import BaseCute
2
2
  from .callback_query import CallbackQueryCute
3
+ from .chat_join_request import ChatJoinRequestCute
4
+ from .chat_member_updated import ChatMemberUpdatedCute
3
5
  from .inline_query import InlineQueryCute
4
6
  from .message import MessageCute
5
7
  from .update import UpdateCute
@@ -7,6 +9,8 @@ from .update import UpdateCute
7
9
  __all__ = (
8
10
  "BaseCute",
9
11
  "CallbackQueryCute",
12
+ "ChatJoinRequestCute",
13
+ "ChatMemberUpdatedCute",
10
14
  "InlineQueryCute",
11
15
  "MessageCute",
12
16
  "UpdateCute",
@@ -23,12 +23,10 @@ if typing.TYPE_CHECKING:
23
23
  api: ABCAPI
24
24
 
25
25
  @classmethod
26
- def from_update(cls, update: UpdateT, bound_api: ABCAPI) -> typing.Self:
27
- ...
26
+ def from_update(cls, update: UpdateT, bound_api: ABCAPI) -> typing.Self: ...
28
27
 
29
28
  @property
30
- def ctx_api(self) -> API:
31
- ...
29
+ def ctx_api(self) -> API: ...
32
30
 
33
31
  else:
34
32
 
@@ -76,7 +74,9 @@ def compose_method_params(
76
74
  if param_name not in params:
77
75
  if param_name in validators and not validators[param_name](update):
78
76
  continue
79
- params[param_name] = getattr(update, param if isinstance(param, str) else param[1])
77
+ params[param_name] = getattr(
78
+ update, param if isinstance(param, str) else param[1]
79
+ )
80
80
 
81
81
  return params
82
82
 
@@ -91,36 +91,45 @@ def shortcut(
91
91
  ):
92
92
  def wrapper(func: F) -> F:
93
93
  @wraps(func)
94
- async def inner(self: CuteT, *args: typing.Any, **kwargs: typing.Any) -> typing.Any:
94
+ async def inner(
95
+ self: CuteT,
96
+ *args: typing.Any,
97
+ **kwargs: typing.Any,
98
+ ) -> typing.Any:
95
99
  if executor is None:
96
100
  return await func(self, *args, **kwargs)
97
101
  signature_params = {
98
- k: p
99
- for k, p in inspect.signature(func).parameters.items()
100
- if k != "self"
102
+ k: p for k, p in inspect.signature(func).parameters.items() if k != "self"
101
103
  }
102
104
  params: dict[str, typing.Any] = {}
103
105
  index = 0
104
106
 
105
107
  for k, p in signature_params.items():
106
- if p.kind in (p.POSITIONAL_OR_KEYWORD, p.POSITIONAL_ONLY) and len(args) > index:
108
+ if (
109
+ p.kind in (p.POSITIONAL_OR_KEYWORD, p.POSITIONAL_ONLY)
110
+ and len(args) > index
111
+ ):
107
112
  params[k] = args[index]
108
113
  index += 1
109
114
  continue
110
115
  if p.kind in (p.VAR_KEYWORD, p.VAR_POSITIONAL):
111
116
  params[k] = kwargs.copy() if p.kind is p.VAR_KEYWORD else args[index:]
112
117
  continue
113
- params[k] = kwargs.pop(k, p.default) if p.default is not p.empty else kwargs.pop(k)
118
+ params[k] = (
119
+ kwargs.pop(k, p.default)
120
+ if p.default is not p.empty
121
+ else kwargs.pop(k)
122
+ )
114
123
 
115
124
  return await executor(self, method_name, get_params(params))
116
-
125
+
117
126
  inner.__shortcut__ = Shortcut( # type: ignore
118
127
  method_name=method_name,
119
128
  executor=executor,
120
129
  custom_params=custom_params or set(),
121
130
  )
122
131
  return inner # type: ignore
123
-
132
+
124
133
  return wrapper
125
134
 
126
135
 
@@ -0,0 +1,63 @@
1
+ import typing
2
+
3
+ from fntypes.result import Result
4
+
5
+ from telegrinder.api.abc import ABCAPI, APIError
6
+ from telegrinder.types.objects import ChatJoinRequest, User
7
+
8
+ from .base import BaseCute, shortcut
9
+ from .chat_member_updated import ChatMemberShortcuts, chat_member_interaction
10
+
11
+
12
+ class ChatJoinRequestCute(BaseCute[ChatJoinRequest], ChatJoinRequest, ChatMemberShortcuts, kw_only=True):
13
+ api: ABCAPI
14
+
15
+ @property
16
+ def from_user(self) -> User:
17
+ return self.from_
18
+
19
+ @property
20
+ def user_id(self) -> int:
21
+ return self.from_user.id
22
+
23
+ @shortcut("approve_chat_join_request", executor=chat_member_interaction)
24
+ async def approve(
25
+ self,
26
+ chat_id: int | str | None = None,
27
+ user_id: int | None = None,
28
+ **other: typing.Any,
29
+ ) -> Result[bool, APIError]:
30
+ """Shortcut `API.approve_chat_join_request()`, see the [documentation](https://core.telegram.org/bots/api#approvechatjoinrequest)
31
+
32
+ Use this method to approve a chat join request. The bot must be an administrator
33
+ in the chat for this to work and must have the can_invite_users administrator
34
+ right. Returns True on success.
35
+
36
+ :param chat_id: Unique identifier for the target chat or username of the target channel \
37
+ (in the format @channelusername).
38
+
39
+ :param user_id: Unique identifier of the target user.
40
+ """
41
+
42
+ ...
43
+
44
+ @shortcut("decline_chat_join_request", executor=chat_member_interaction)
45
+ async def decline(
46
+ self,
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
+ :param chat_id: Unique identifier for the target chat or username of the target channel \
58
+ (in the format @channelusername).
59
+
60
+ :param user_id: Unique identifier of the target user.
61
+ """
62
+
63
+ ...
@@ -0,0 +1,244 @@
1
+ import typing
2
+ from datetime import datetime
3
+
4
+ from fntypes.result import Result
5
+
6
+ from telegrinder.api import ABCAPI, APIError
7
+ from telegrinder.model import get_params
8
+ from telegrinder.types.objects import ChatMemberUpdated, ChatPermissions, User
9
+
10
+ from .base import BaseCute, compose_method_params, shortcut
11
+ from .utils import compose_chat_permissions
12
+
13
+
14
+ async def chat_member_interaction(
15
+ update: BaseCute[typing.Any],
16
+ method_name: str,
17
+ params: dict[str, typing.Any],
18
+ ) -> Result[typing.Any, APIError]:
19
+ if isinstance(params.get("permissions"), dict):
20
+ params["permissions"] = compose_chat_permissions(**params["permissions"])
21
+ params = compose_method_params(
22
+ get_params(locals()),
23
+ update,
24
+ default_params={"chat_id", "user_id"},
25
+ )
26
+ return await getattr(update.ctx_api, method_name)(**params)
27
+
28
+
29
+ class ChatMemberShortcuts:
30
+ """Shortcut methods for `ChatMemberUpdatedCute`, `ChatJoinRequestCute` objects."""
31
+
32
+ @shortcut("ban_chat_member", executor=chat_member_interaction)
33
+ async def ban_chat_member(
34
+ self,
35
+ chat_id: int | str | None = None,
36
+ user_id: int | None = None,
37
+ until_date: datetime | int | None = None,
38
+ revoke_messages: bool | 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
+ :param chat_id: Unique identifier for the target group or username of the target supergroup \
50
+ or channel (in the format @channelusername).
51
+
52
+ :param user_id: Unique identifier of the target user.
53
+
54
+ :param until_date: Date when the user will be unbanned; Unix time. If user is banned for more \
55
+ than 366 days or less than 30 seconds from the current time they are considered \
56
+ to be banned forever. Applied for supergroups and channels only.
57
+
58
+ :param revoke_messages: Pass True to delete all messages from the chat for the user that is being removed. \
59
+ If False, the user will be able to see messages in the group that were sent \
60
+ before the user was removed. Always True for supergroups and channels. \
61
+ """
62
+
63
+ ...
64
+
65
+ @shortcut("unban_chat_member", executor=chat_member_interaction)
66
+ async def unban_chat_member(
67
+ self,
68
+ chat_id: int | str | None = None,
69
+ user_id: int | None = None,
70
+ only_if_banned: bool | None = None,
71
+ **other: typing.Any,
72
+ ) -> Result[bool, APIError]:
73
+ """Shortcut `API.unban_chat_member()`, see the [documentation](https://core.telegram.org/bots/api#unbanchatmember)
74
+
75
+ Use this method to unban a previously banned user in a supergroup or channel.
76
+ The user will not return to the group or channel automatically, but will
77
+ be able to join via link, etc. The bot must be an administrator for this to
78
+ work. By default, this method guarantees that after the call the user is
79
+ not a member of the chat, but will be able to join it. So if the user is a member
80
+ of the chat they will also be removed from the chat. If you don't want this,
81
+ use the parameter only_if_banned. Returns True on success.
82
+
83
+ :param chat_id: Unique identifier for the target group or username of the target supergroup \
84
+ or channel (in the format @channelusername).
85
+
86
+ :param user_id: Unique identifier of the target user.
87
+
88
+ :param only_if_banned: Do nothing if the user is not banned.
89
+ """
90
+
91
+ ...
92
+
93
+ @shortcut(
94
+ "restrict_chat_member",
95
+ executor=chat_member_interaction,
96
+ custom_params={"permissions"},
97
+ )
98
+ async def restrict_chat_member(
99
+ self,
100
+ permissions: ChatPermissions | dict[str, typing.Any],
101
+ chat_id: int | str | None = None,
102
+ user_id: int | None = None,
103
+ use_independent_chat_permissions: bool | None = None,
104
+ until_date: datetime | int | None = None,
105
+ **other: typing.Any,
106
+ ) -> Result[bool, APIError]:
107
+ """Shortcut `API.restrict_chat_member()`, see the [documentation](https://core.telegram.org/bots/api#restrictchatmember)
108
+
109
+ Use this method to restrict a user in a supergroup. The bot must be an administrator
110
+ in the supergroup for this to work and must have the appropriate administrator
111
+ rights. Pass True for all permissions to lift restrictions from a user.
112
+ Returns True on success.
113
+
114
+ :param chat_id: Unique identifier for the target chat or username of the target supergroup \
115
+ (in the format @supergroupusername).
116
+
117
+ :param user_id: Unique identifier of the target user.
118
+
119
+ :param permissions: A JSON-serialized object for new user permissions.
120
+
121
+ :param use_independent_chat_permissions: Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages \
122
+ and can_add_web_page_previews permissions will imply the can_send_messages, \
123
+ can_send_audios, can_send_documents, can_send_photos, can_send_videos, \
124
+ can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls \
125
+ permission will imply the can_send_messages permission.
126
+
127
+ :param until_date: Date when restrictions will be lifted for the user; Unix time. If user is \
128
+ restricted for more than 366 days or less than 30 seconds from the current \
129
+ time, they are considered to be restricted forever.
130
+ """
131
+
132
+ ...
133
+
134
+ @shortcut("promote_chat_member", executor=chat_member_interaction)
135
+ async def promote_chat_member(
136
+ self,
137
+ chat_id: int | str | None = None,
138
+ user_id: int | None = None,
139
+ is_anonymous: bool | None = None,
140
+ can_manage_chat: bool | None = None,
141
+ can_delete_messages: bool | None = None,
142
+ can_manage_video_chats: bool | None = None,
143
+ can_restrict_members: bool | None = None,
144
+ can_promote_members: bool | None = None,
145
+ can_change_info: bool | None = None,
146
+ can_invite_users: bool | None = None,
147
+ can_post_stories: bool | None = None,
148
+ can_edit_stories: bool | None = None,
149
+ can_delete_stories: bool | None = None,
150
+ can_post_messages: bool | None = None,
151
+ can_edit_messages: bool | None = None,
152
+ can_pin_messages: bool | None = None,
153
+ can_manage_topics: bool | None = None,
154
+ **other: typing.Any,
155
+ ) -> Result[bool, APIError]:
156
+ """Shortcut `API.promote_chat_member()`, see the [documentation](https://core.telegram.org/bots/api#promotechatmember)
157
+
158
+ Use this method to promote or demote a user in a supergroup or a channel. The
159
+ bot must be an administrator in the chat for this to work and must have the
160
+ appropriate administrator rights. Pass False for all boolean parameters
161
+ to demote a user. Returns True on success.
162
+
163
+ :param chat_id: Unique identifier for the target chat or username of the target channel \
164
+ (in the format @channelusername).
165
+
166
+ :param user_id: Unique identifier of the target user.
167
+
168
+ :param is_anonymous: Pass True if the administrator's presence in the chat is hidden.
169
+
170
+ :param can_manage_chat: Pass True if the administrator can access the chat event log, get boost list, \
171
+ see hidden supergroup and channel members, report spam messages and ignore \
172
+ slow mode. Implied by any other administrator privilege.
173
+
174
+ :param can_delete_messages: Pass True if the administrator can delete messages of other users.
175
+
176
+ :param can_manage_video_chats: Pass True if the administrator can manage video chats.
177
+
178
+ :param can_restrict_members: Pass True if the administrator can restrict, ban or unban chat members, \
179
+ or access supergroup statistics.
180
+
181
+ :param can_promote_members: Pass True if the administrator can add new administrators with a subset \
182
+ of their own privileges or demote administrators that they have promoted, \
183
+ directly or indirectly (promoted by administrators that were appointed \
184
+ by him).
185
+
186
+ :param can_change_info: Pass True if the administrator can change chat title, photo and other settings. \
187
+
188
+ :param can_invite_users: Pass True if the administrator can invite new users to the chat.
189
+
190
+ :param can_post_stories: Pass True if the administrator can post stories to the chat.
191
+
192
+ :param can_edit_stories: Pass True if the administrator can edit stories posted by other users.
193
+
194
+ :param can_delete_stories: Pass True if the administrator can delete stories posted by other users. \
195
+
196
+ :param can_post_messages: Pass True if the administrator can post messages in the channel, or access \
197
+ channel statistics; for channels only.
198
+
199
+ :param can_edit_messages: Pass True if the administrator can edit messages of other users and can pin \
200
+ messages; for channels only.
201
+
202
+ :param can_pin_messages: Pass True if the administrator can pin messages; for supergroups only. \
203
+
204
+ :param can_manage_topics: Pass True if the user is allowed to create, rename, close, and reopen forum \
205
+ topics; for supergroups only.
206
+ """
207
+
208
+ ...
209
+
210
+ @shortcut("set_chat_administrator_custom_title", executor=chat_member_interaction)
211
+ async def set_chat_administrator_custom_title(
212
+ self,
213
+ custom_title: str,
214
+ chat_id: int | str | None = None,
215
+ user_id: int | None = None,
216
+ **other: typing.Any,
217
+ ) -> Result[bool, APIError]:
218
+ """Shortcut `API.set_chat_administrator_custom_title()`, see the [documentation](https://core.telegram.org/bots/api#setchatadministratorcustomtitle)
219
+
220
+ Use this method to set a custom title for an administrator in a supergroup
221
+ promoted by the bot. Returns True on success.
222
+
223
+ :param chat_id: Unique identifier for the target chat or username of the target supergroup \
224
+ (in the format @supergroupusername).
225
+
226
+ :param user_id: Unique identifier of the target user.
227
+
228
+ :param custom_title: New custom title for the administrator; 0-16 characters, emoji are not \
229
+ allowed.
230
+ """
231
+
232
+ ...
233
+
234
+
235
+ class ChatMemberUpdatedCute(BaseCute[ChatMemberUpdated], ChatMemberUpdated, ChatMemberShortcuts, kw_only=True):
236
+ api: ABCAPI
237
+
238
+ @property
239
+ def from_user(self) -> User:
240
+ return self.from_
241
+
242
+ @property
243
+ def user_id(self) -> int:
244
+ return self.from_user.id