Spaces:
Configuration error
Configuration error
File size: 12,800 Bytes
36367b2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2024
# Leandro Toledo de Souza <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains two objects to request chats/users."""
from typing import TYPE_CHECKING, Optional
from telegram._chatadministratorrights import ChatAdministratorRights
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
if TYPE_CHECKING:
from telegram import Bot
class KeyboardButtonRequestUsers(TelegramObject):
"""This object defines the criteria used to request a suitable user. The identifier of the
selected user will be shared with the bot when the corresponding button is pressed. `More
about requesting users » <https://core.telegram.org/bots/features#chat-and-user-selection>`_.
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`request_id` is equal.
.. versionadded:: 20.8
This class was previously named ``KeyboardButtonRequestUser``.
Args:
request_id (:obj:`int`): Signed 32-bit identifier of the request, which will be received
back in the :class:`telegram.UsersShared` object. Must be unique within the message.
user_is_bot (:obj:`bool`, optional): Pass :obj:`True` to request a bot, pass :obj:`False`
to request a regular user. If not specified, no additional restrictions are applied.
user_is_premium (:obj:`bool`, optional): Pass :obj:`True` to request a premium user, pass
:obj:`False` to request a non-premium user. If not specified, no additional
restrictions are applied.
max_quantity (:obj:`int`, optional): The maximum number of users to be selected;
:tg-const:`telegram.constants.KeyboardButtonRequestUsersLimit.MIN_QUANTITY` -
:tg-const:`telegram.constants.KeyboardButtonRequestUsersLimit.MAX_QUANTITY`.
Defaults to :tg-const:`telegram.constants.KeyboardButtonRequestUsersLimit.MIN_QUANTITY`
.
.. versionadded:: 20.8
request_name (:obj:`bool`, optional): Pass :obj:`True` to request the users' first and last
name.
.. versionadded:: 21.1
request_username (:obj:`bool`, optional): Pass :obj:`True` to request the users' username.
.. versionadded:: 21.1
request_photo (:obj:`bool`, optional): Pass :obj:`True` to request the users' photo.
.. versionadded:: 21.1
Attributes:
request_id (:obj:`int`): Identifier of the request.
user_is_bot (:obj:`bool`): Optional. Pass :obj:`True` to request a bot, pass :obj:`False`
to request a regular user. If not specified, no additional restrictions are applied.
user_is_premium (:obj:`bool`): Optional. Pass :obj:`True` to request a premium user, pass
:obj:`False` to request a non-premium user. If not specified, no additional
restrictions are applied.
max_quantity (:obj:`int`): Optional. The maximum number of users to be selected;
:tg-const:`telegram.constants.KeyboardButtonRequestUsersLimit.MIN_QUANTITY` -
:tg-const:`telegram.constants.KeyboardButtonRequestUsersLimit.MAX_QUANTITY`.
Defaults to :tg-const:`telegram.constants.KeyboardButtonRequestUsersLimit.MIN_QUANTITY`
.
.. versionadded:: 20.8
request_name (:obj:`bool`): Optional. Pass :obj:`True` to request the users' first and last
name.
.. versionadded:: 21.1
request_username (:obj:`bool`): Optional. Pass :obj:`True` to request the users' username.
.. versionadded:: 21.1
request_photo (:obj:`bool`): Optional. Pass :obj:`True` to request the users' photo.
.. versionadded:: 21.1
"""
__slots__ = (
"max_quantity",
"request_id",
"request_name",
"request_photo",
"request_username",
"user_is_bot",
"user_is_premium",
)
def __init__(
self,
request_id: int,
user_is_bot: Optional[bool] = None,
user_is_premium: Optional[bool] = None,
max_quantity: Optional[int] = None,
request_name: Optional[bool] = None,
request_username: Optional[bool] = None,
request_photo: Optional[bool] = None,
*,
api_kwargs: Optional[JSONDict] = None,
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.request_id: int = request_id
# Optionals
self.user_is_bot: Optional[bool] = user_is_bot
self.user_is_premium: Optional[bool] = user_is_premium
self.max_quantity: Optional[int] = max_quantity
self.request_name: Optional[bool] = request_name
self.request_username: Optional[bool] = request_username
self.request_photo: Optional[bool] = request_photo
self._id_attrs = (self.request_id,)
self._freeze()
class KeyboardButtonRequestChat(TelegramObject):
"""This object defines the criteria used to request a suitable chat. The identifier of the
selected user will be shared with the bot when the corresponding button is pressed. `More
about requesting users » <https://core.telegram.org/bots/features#chat-and-user-selection>`_.
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`request_id` is equal.
.. versionadded:: 20.1
Args:
request_id (:obj:`int`): Signed 32-bit identifier of the request, which will be received
back in the :class:`telegram.ChatShared` object. Must be unique within the message.
chat_is_channel (:obj:`bool`): Pass :obj:`True` to request a channel chat, pass
:obj:`False` to request a group or a supergroup chat.
chat_is_forum (:obj:`bool`, optional): Pass :obj:`True` to request a forum supergroup, pass
:obj:`False` to request a non-forum chat. If not specified, no additional
restrictions are applied.
chat_has_username (:obj:`bool`, optional): Pass :obj:`True` to request a supergroup or a
channel with a username, pass :obj:`False` to request a chat without a username. If
not specified, no additional restrictions are applied.
chat_is_created (:obj:`bool`, optional): Pass :obj:`True` to request a chat owned by the
user. Otherwise, no additional restrictions are applied.
user_administrator_rights (:class:`ChatAdministratorRights`, optional): Specifies the
required administrator rights of the user in the chat. If not specified, no additional
restrictions are applied.
bot_administrator_rights (:class:`ChatAdministratorRights`, optional): Specifies the
required administrator rights of the bot in the chat. The rights must be a subset of
:paramref:`user_administrator_rights`. If not specified, no additional restrictions are
applied.
bot_is_member (:obj:`bool`, optional): Pass :obj:`True` to request a chat with the bot
as a member. Otherwise, no additional restrictions are applied.
request_title (:obj:`bool`, optional): Pass :obj:`True` to request the chat's title.
.. versionadded:: 21.1
request_username (:obj:`bool`, optional): Pass :obj:`True` to request the chat's username.
.. versionadded:: 21.1
request_photo (:obj:`bool`, optional): Pass :obj:`True` to request the chat's photo.
.. versionadded:: 21.1
Attributes:
request_id (:obj:`int`): Identifier of the request.
chat_is_channel (:obj:`bool`): Pass :obj:`True` to request a channel chat, pass
:obj:`False` to request a group or a supergroup chat.
chat_is_forum (:obj:`bool`): Optional. Pass :obj:`True` to request a forum supergroup, pass
:obj:`False` to request a non-forum chat. If not specified, no additional
restrictions are applied.
chat_has_username (:obj:`bool`): Optional. Pass :obj:`True` to request a supergroup or a
channel with a username, pass :obj:`False` to request a chat without a username. If
not specified, no additional restrictions are applied.
chat_is_created (:obj:`bool`) Optional. Pass :obj:`True` to request a chat owned by the
user. Otherwise, no additional restrictions are applied.
user_administrator_rights (:class:`ChatAdministratorRights`) Optional. Specifies the
required administrator rights of the user in the chat. If not specified, no additional
restrictions are applied.
bot_administrator_rights (:class:`ChatAdministratorRights`) Optional. Specifies the
required administrator rights of the bot in the chat. The rights must be a subset of
:attr:`user_administrator_rights`. If not specified, no additional restrictions are
applied.
bot_is_member (:obj:`bool`) Optional. Pass :obj:`True` to request a chat with the bot
as a member. Otherwise, no additional restrictions are applied.
request_title (:obj:`bool`): Optional. Pass :obj:`True` to request the chat's title.
.. versionadded:: 21.1
request_username (:obj:`bool`): Optional. Pass :obj:`True` to request the chat's username.
.. versionadded:: 21.1
request_photo (:obj:`bool`): Optional. Pass :obj:`True` to request the chat's photo.
.. versionadded:: 21.1
"""
__slots__ = (
"bot_administrator_rights",
"bot_is_member",
"chat_has_username",
"chat_is_channel",
"chat_is_created",
"chat_is_forum",
"request_id",
"request_photo",
"request_title",
"request_username",
"user_administrator_rights",
)
def __init__(
self,
request_id: int,
chat_is_channel: bool,
chat_is_forum: Optional[bool] = None,
chat_has_username: Optional[bool] = None,
chat_is_created: Optional[bool] = None,
user_administrator_rights: Optional[ChatAdministratorRights] = None,
bot_administrator_rights: Optional[ChatAdministratorRights] = None,
bot_is_member: Optional[bool] = None,
request_title: Optional[bool] = None,
request_username: Optional[bool] = None,
request_photo: Optional[bool] = None,
*,
api_kwargs: Optional[JSONDict] = None,
):
super().__init__(api_kwargs=api_kwargs)
# required
self.request_id: int = request_id
self.chat_is_channel: bool = chat_is_channel
# optional
self.chat_is_forum: Optional[bool] = chat_is_forum
self.chat_has_username: Optional[bool] = chat_has_username
self.chat_is_created: Optional[bool] = chat_is_created
self.user_administrator_rights: Optional[ChatAdministratorRights] = (
user_administrator_rights
)
self.bot_administrator_rights: Optional[ChatAdministratorRights] = bot_administrator_rights
self.bot_is_member: Optional[bool] = bot_is_member
self.request_title: Optional[bool] = request_title
self.request_username: Optional[bool] = request_username
self.request_photo: Optional[bool] = request_photo
self._id_attrs = (self.request_id,)
self._freeze()
@classmethod
def de_json(
cls, data: Optional[JSONDict], bot: Optional["Bot"] = None
) -> Optional["KeyboardButtonRequestChat"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
data = cls._parse_data(data)
if not data:
return None
data["user_administrator_rights"] = ChatAdministratorRights.de_json(
data.get("user_administrator_rights"), bot
)
data["bot_administrator_rights"] = ChatAdministratorRights.de_json(
data.get("bot_administrator_rights"), bot
)
return super().de_json(data=data, bot=bot)
|