From 41d5a13b5f99ea65c5a36959f78bc8cd2c511712 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 29 May 2019 09:44:57 +0200 Subject: [PATCH] Extend Chat and User types with new fields is_verified, is_restricted, is_scam and is_support (user only) --- pyrogram/client/types/user_and_chats/chat.py | 44 ++++++++++++++++---- pyrogram/client/types/user_and_chats/user.py | 33 +++++++++++++-- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/pyrogram/client/types/user_and_chats/chat.py b/pyrogram/client/types/user_and_chats/chat.py index e45814ea..10cc10a7 100644 --- a/pyrogram/client/types/user_and_chats/chat.py +++ b/pyrogram/client/types/user_and_chats/chat.py @@ -35,6 +35,16 @@ class Chat(PyrogramType): type (``str``): Type of chat, can be either "private", "bot", "group", "supergroup" or "channel". + is_verified (``bool``, *optional*): + True, if this chat has been verified by Telegram. Supergroups and channels only. + + is_restricted (``bool``, *optional*): + True, if this chat has been restricted. Supergroups and channels only. + See *restriction_reason* for details. + + is_scam (``bool``, *optional*): + True, if this chat has been flagged for scam. Supergroups and channels only. + title (``str``, *optional*): Title, for supergroups, channels and basic group chats. @@ -75,15 +85,16 @@ class Chat(PyrogramType): restriction_reason (``str``, *optional*): The reason why this chat might be unavailable to some users. + This field is available only in case *is_restricted* is True. permissions (:obj:`ChatPermissions ` *optional*): Information about the chat default permissions, for groups and supergroups. """ __slots__ = [ - "id", "type", "title", "username", "first_name", "last_name", "photo", "description", "invite_link", - "pinned_message", "sticker_set_name", "can_set_sticker_set", "members_count", "restriction_reason", - "permissions" + "id", "type", "is_verified", "is_restricted", "is_scam", "title", "username", "first_name", "last_name", + "photo", "description", "invite_link", "pinned_message", "sticker_set_name", "can_set_sticker_set", + "members_count", "restriction_reason", "permissions" ] def __init__( @@ -92,6 +103,9 @@ class Chat(PyrogramType): client: "pyrogram.BaseClient" = None, id: int, type: str, + is_verified: bool = None, + is_restricted: bool = None, + is_scam: bool = None, title: str = None, username: str = None, first_name: str = None, @@ -110,6 +124,9 @@ class Chat(PyrogramType): self.id = id self.type = type + self.is_verified = is_verified + self.is_restricted = is_restricted + self.is_scam = is_scam self.title = title self.username = username self.first_name = first_name @@ -126,36 +143,45 @@ class Chat(PyrogramType): @staticmethod def _parse_user_chat(client, user: types.User) -> "Chat": + peer_id = user.id + return Chat( - id=user.id, + id=peer_id, type="bot" if user.bot else "private", username=user.username, first_name=user.first_name, last_name=user.last_name, - photo=ChatPhoto._parse(client, user.photo), + photo=ChatPhoto._parse(client, user.photo, peer_id), restriction_reason=user.restriction_reason, client=client ) @staticmethod def _parse_chat_chat(client, chat: types.Chat) -> "Chat": + peer_id = -chat.id + return Chat( - id=-chat.id, + id=peer_id, type="group", title=chat.title, - photo=ChatPhoto._parse(client, getattr(chat, "photo", None)), + photo=ChatPhoto._parse(client, getattr(chat, "photo", None), peer_id), permissions=ChatPermissions._parse(getattr(chat, "default_banned_rights", None)), client=client ) @staticmethod def _parse_channel_chat(client, channel: types.Channel) -> "Chat": + peer_id = int("-100" + str(channel.id)) + return Chat( - id=int("-100" + str(channel.id)), + id=peer_id, type="supergroup" if channel.megagroup else "channel", + is_verified=getattr(channel, "verified", None), + is_restricted=getattr(channel, "restricted", None), + is_scam=getattr(channel, "scam", None), title=channel.title, username=getattr(channel, "username", None), - photo=ChatPhoto._parse(client, getattr(channel, "photo", None)), + photo=ChatPhoto._parse(client, getattr(channel, "photo", None), peer_id), restriction_reason=getattr(channel, "restriction_reason", None), permissions=ChatPermissions._parse(getattr(channel, "default_banned_rights", None)), client=client diff --git a/pyrogram/client/types/user_and_chats/user.py b/pyrogram/client/types/user_and_chats/user.py index 455b4a4d..ae631df1 100644 --- a/pyrogram/client/types/user_and_chats/user.py +++ b/pyrogram/client/types/user_and_chats/user.py @@ -45,6 +45,19 @@ class User(PyrogramType): is_bot (``bool``): True, if this user is a bot. + is_verified (``bool``): + True, if this user has been verified by Telegram. + + is_restricted (``bool``): + True, if this user has been restricted. Bots only. + See *restriction_reason* for details. + + is_support (``bool``): + True, if this user is part of the Telegram support team. + + is_scam (``bool``): + True, if this user has been flagged for scam. + first_name (``str``): User's or bot's first name. @@ -68,11 +81,13 @@ class User(PyrogramType): restriction_reason (``str``, *optional*): The reason why this bot might be unavailable to some users. + This field is available only in case *is_restricted* is True. """ __slots__ = [ - "id", "is_self", "is_contact", "is_mutual_contact", "is_deleted", "is_bot", "first_name", "last_name", "status", - "username", "language_code", "phone_number", "photo", "restriction_reason" + "id", "is_self", "is_contact", "is_mutual_contact", "is_deleted", "is_bot", "is_verified", "is_restricted", + "is_support", "is_scam", "first_name", "last_name", "status", "username", "language_code", "phone_number", + "photo", "restriction_reason" ] def __init__( @@ -85,6 +100,10 @@ class User(PyrogramType): is_mutual_contact: bool, is_deleted: bool, is_bot: bool, + is_verified: bool, + is_restricted: bool, + is_support: bool, + is_scam: bool, first_name: str, last_name: str = None, status: UserStatus = None, @@ -102,6 +121,10 @@ class User(PyrogramType): self.is_mutual_contact = is_mutual_contact self.is_deleted = is_deleted self.is_bot = is_bot + self.is_verified = is_verified + self.is_restricted = is_restricted + self.is_support = is_support + self.is_scam = is_scam self.first_name = first_name self.last_name = last_name self.status = status @@ -123,13 +146,17 @@ class User(PyrogramType): is_mutual_contact=user.mutual_contact, is_deleted=user.deleted, is_bot=user.bot, + is_verified=user.verified, + is_restricted=user.restricted, + is_support=user.support, + is_scam=user.scam, first_name=user.first_name, last_name=user.last_name, status=UserStatus._parse(client, user.status, user.id, user.bot), username=user.username, language_code=user.lang_code, phone_number=user.phone, - photo=ChatPhoto._parse(client, user.photo), + photo=ChatPhoto._parse(client, user.photo, user.id), restriction_reason=user.restriction_reason, client=client )