2021-03-14 16:41:35 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# A library that provides a Python interface to the Telegram Bot API
|
2023-01-01 21:31:29 +01:00
|
|
|
# Copyright (C) 2015-2023
|
2021-03-14 16:41:35 +01:00
|
|
|
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
|
|
|
#
|
|
|
|
# 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 an object that represents an invite link for a chat."""
|
|
|
|
import datetime
|
2022-10-07 11:51:53 +02:00
|
|
|
from typing import TYPE_CHECKING, Optional
|
2021-03-14 16:41:35 +01:00
|
|
|
|
2022-05-05 09:27:54 +02:00
|
|
|
from telegram._telegramobject import TelegramObject
|
|
|
|
from telegram._user import User
|
2023-04-18 16:16:23 +02:00
|
|
|
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
2021-10-10 15:10:21 +02:00
|
|
|
from telegram._utils.types import JSONDict
|
2021-03-14 16:41:35 +01:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from telegram import Bot
|
|
|
|
|
|
|
|
|
|
|
|
class ChatInviteLink(TelegramObject):
|
|
|
|
"""This object represents an invite link for a chat.
|
|
|
|
|
|
|
|
Objects of this class are comparable in terms of equality. Two objects of this class are
|
2021-08-29 18:17:06 +02:00
|
|
|
considered equal, if their :attr:`invite_link`, :attr:`creator`, :attr:`creates_join_request`,
|
|
|
|
:attr:`is_primary` and :attr:`is_revoked` are equal.
|
2021-03-14 16:41:35 +01:00
|
|
|
|
|
|
|
.. versionadded:: 13.4
|
2022-05-06 17:15:23 +02:00
|
|
|
.. versionchanged:: 20.0
|
2021-08-29 18:17:06 +02:00
|
|
|
|
|
|
|
* The argument & attribute :attr:`creates_join_request` is now required to comply with the
|
|
|
|
Bot API.
|
|
|
|
* Comparing objects of this class now also takes :attr:`creates_join_request` into account.
|
2021-03-14 16:41:35 +01:00
|
|
|
|
|
|
|
Args:
|
|
|
|
invite_link (:obj:`str`): The invite link.
|
|
|
|
creator (:class:`telegram.User`): Creator of the link.
|
2021-08-29 18:17:06 +02:00
|
|
|
creates_join_request (:obj:`bool`): :obj:`True`, if users joining the chat via
|
|
|
|
the link need to be approved by chat administrators.
|
|
|
|
|
|
|
|
.. versionadded:: 13.8
|
2021-03-14 16:41:35 +01:00
|
|
|
is_primary (:obj:`bool`): :obj:`True`, if the link is primary.
|
|
|
|
is_revoked (:obj:`bool`): :obj:`True`, if the link is revoked.
|
|
|
|
expire_date (:class:`datetime.datetime`, optional): Date when the link will expire or
|
|
|
|
has been expired.
|
2023-04-18 16:16:23 +02:00
|
|
|
|
|
|
|
.. versionchanged:: NEXT.VERSION
|
|
|
|
|datetime_localization|
|
2021-03-14 16:41:35 +01:00
|
|
|
member_limit (:obj:`int`, optional): Maximum number of users that can be members of the
|
2021-11-29 20:32:26 +01:00
|
|
|
chat simultaneously after joining the chat via this invite link;
|
2022-11-22 11:07:42 +01:00
|
|
|
:tg-const:`telegram.constants.ChatInviteLinkLimit.MIN_MEMBER_LIMIT`-
|
|
|
|
:tg-const:`telegram.constants.ChatInviteLinkLimit.MAX_MEMBER_LIMIT`.
|
2021-11-08 19:02:20 +01:00
|
|
|
name (:obj:`str`, optional): Invite link name.
|
2021-11-29 20:32:26 +01:00
|
|
|
0-:tg-const:`telegram.constants.ChatInviteLinkLimit.NAME_LENGTH` characters.
|
2021-11-08 19:02:20 +01:00
|
|
|
|
|
|
|
.. versionadded:: 13.8
|
|
|
|
pending_join_request_count (:obj:`int`, optional): Number of pending join requests
|
|
|
|
created using this link.
|
|
|
|
|
|
|
|
.. versionadded:: 13.8
|
2021-03-14 16:41:35 +01:00
|
|
|
Attributes:
|
|
|
|
invite_link (:obj:`str`): The invite link. If the link was created by another chat
|
|
|
|
administrator, then the second part of the link will be replaced with ``'…'``.
|
|
|
|
creator (:class:`telegram.User`): Creator of the link.
|
2021-08-29 18:17:06 +02:00
|
|
|
creates_join_request (:obj:`bool`): :obj:`True`, if users joining the chat via
|
|
|
|
the link need to be approved by chat administrators.
|
|
|
|
|
|
|
|
.. versionadded:: 13.8
|
2021-03-14 16:41:35 +01:00
|
|
|
is_primary (:obj:`bool`): :obj:`True`, if the link is primary.
|
|
|
|
is_revoked (:obj:`bool`): :obj:`True`, if the link is revoked.
|
|
|
|
expire_date (:class:`datetime.datetime`): Optional. Date when the link will expire or
|
|
|
|
has been expired.
|
2023-04-18 16:16:23 +02:00
|
|
|
|
|
|
|
.. versionchanged:: NEXT.VERSION
|
|
|
|
|datetime_localization|
|
2021-03-14 16:41:35 +01:00
|
|
|
member_limit (:obj:`int`): Optional. Maximum number of users that can be members
|
2022-11-22 11:07:42 +01:00
|
|
|
of the chat simultaneously after joining the chat via this invite link;
|
|
|
|
:tg-const:`telegram.constants.ChatInviteLinkLimit.MIN_MEMBER_LIMIT`-
|
|
|
|
:tg-const:`telegram.constants.ChatInviteLinkLimit.MAX_MEMBER_LIMIT`.
|
2021-11-08 19:02:20 +01:00
|
|
|
name (:obj:`str`): Optional. Invite link name.
|
2023-01-01 16:24:00 +01:00
|
|
|
0-:tg-const:`telegram.constants.ChatInviteLinkLimit.NAME_LENGTH` characters.
|
2021-11-08 19:02:20 +01:00
|
|
|
|
|
|
|
.. versionadded:: 13.8
|
|
|
|
pending_join_request_count (:obj:`int`): Optional. Number of pending join requests
|
|
|
|
created using this link.
|
|
|
|
|
|
|
|
.. versionadded:: 13.8
|
2021-03-14 16:41:35 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
2021-05-29 16:18:16 +02:00
|
|
|
__slots__ = (
|
2022-05-05 17:40:22 +02:00
|
|
|
"invite_link",
|
|
|
|
"creator",
|
|
|
|
"is_primary",
|
|
|
|
"is_revoked",
|
|
|
|
"expire_date",
|
|
|
|
"member_limit",
|
|
|
|
"name",
|
|
|
|
"creates_join_request",
|
|
|
|
"pending_join_request_count",
|
2021-05-29 16:18:16 +02:00
|
|
|
)
|
|
|
|
|
2021-03-14 16:41:35 +01:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
invite_link: str,
|
|
|
|
creator: User,
|
2021-08-29 18:17:06 +02:00
|
|
|
creates_join_request: bool,
|
2021-03-14 16:41:35 +01:00
|
|
|
is_primary: bool,
|
|
|
|
is_revoked: bool,
|
|
|
|
expire_date: datetime.datetime = None,
|
|
|
|
member_limit: int = None,
|
2021-11-08 19:02:20 +01:00
|
|
|
name: str = None,
|
|
|
|
pending_join_request_count: int = None,
|
2022-10-07 11:51:53 +02:00
|
|
|
*,
|
|
|
|
api_kwargs: JSONDict = None,
|
2021-03-14 16:41:35 +01:00
|
|
|
):
|
2022-10-07 11:51:53 +02:00
|
|
|
super().__init__(api_kwargs=api_kwargs)
|
2021-03-14 16:41:35 +01:00
|
|
|
# Required
|
2023-02-02 18:55:07 +01:00
|
|
|
self.invite_link: str = invite_link
|
|
|
|
self.creator: User = creator
|
|
|
|
self.creates_join_request: bool = creates_join_request
|
|
|
|
self.is_primary: bool = is_primary
|
|
|
|
self.is_revoked: bool = is_revoked
|
2021-03-14 16:41:35 +01:00
|
|
|
|
|
|
|
# Optionals
|
2023-02-02 18:55:07 +01:00
|
|
|
self.expire_date: Optional[datetime.datetime] = expire_date
|
|
|
|
self.member_limit: Optional[int] = member_limit
|
|
|
|
self.name: Optional[str] = name
|
|
|
|
self.pending_join_request_count: Optional[int] = (
|
2021-11-08 19:02:20 +01:00
|
|
|
int(pending_join_request_count) if pending_join_request_count is not None else None
|
|
|
|
)
|
2021-08-29 18:17:06 +02:00
|
|
|
self._id_attrs = (
|
|
|
|
self.invite_link,
|
|
|
|
self.creates_join_request,
|
|
|
|
self.creator,
|
|
|
|
self.is_primary,
|
|
|
|
self.is_revoked,
|
|
|
|
)
|
2021-03-14 16:41:35 +01:00
|
|
|
|
2022-12-15 15:00:36 +01:00
|
|
|
self._freeze()
|
|
|
|
|
2021-03-14 16:41:35 +01:00
|
|
|
@classmethod
|
2022-05-05 17:40:22 +02:00
|
|
|
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatInviteLink"]:
|
2021-05-27 09:38:17 +02:00
|
|
|
"""See :meth:`telegram.TelegramObject.de_json`."""
|
|
|
|
data = cls._parse_data(data)
|
2021-03-14 16:41:35 +01:00
|
|
|
|
|
|
|
if not data:
|
|
|
|
return None
|
|
|
|
|
2023-04-18 16:16:23 +02:00
|
|
|
# Get the local timezone from the bot if it has defaults
|
|
|
|
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
|
|
|
|
2022-05-05 17:40:22 +02:00
|
|
|
data["creator"] = User.de_json(data.get("creator"), bot)
|
2023-04-18 16:16:23 +02:00
|
|
|
data["expire_date"] = from_timestamp(data.get("expire_date", None), tzinfo=loc_tzinfo)
|
2021-03-14 16:41:35 +01:00
|
|
|
|
2022-10-07 11:51:53 +02:00
|
|
|
return super().de_json(data=data, bot=bot)
|