mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Extend Chat and User types with new fields
is_verified, is_restricted, is_scam and is_support (user only)
This commit is contained in:
parent
38de4299c5
commit
41d5a13b5f
@ -35,6 +35,16 @@ class Chat(PyrogramType):
|
|||||||
type (``str``):
|
type (``str``):
|
||||||
Type of chat, can be either "private", "bot", "group", "supergroup" or "channel".
|
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 (``str``, *optional*):
|
||||||
Title, for supergroups, channels and basic group chats.
|
Title, for supergroups, channels and basic group chats.
|
||||||
|
|
||||||
@ -75,15 +85,16 @@ class Chat(PyrogramType):
|
|||||||
|
|
||||||
restriction_reason (``str``, *optional*):
|
restriction_reason (``str``, *optional*):
|
||||||
The reason why this chat might be unavailable to some users.
|
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 <pyrogram.ChatPermissions>` *optional*):
|
permissions (:obj:`ChatPermissions <pyrogram.ChatPermissions>` *optional*):
|
||||||
Information about the chat default permissions, for groups and supergroups.
|
Information about the chat default permissions, for groups and supergroups.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = [
|
__slots__ = [
|
||||||
"id", "type", "title", "username", "first_name", "last_name", "photo", "description", "invite_link",
|
"id", "type", "is_verified", "is_restricted", "is_scam", "title", "username", "first_name", "last_name",
|
||||||
"pinned_message", "sticker_set_name", "can_set_sticker_set", "members_count", "restriction_reason",
|
"photo", "description", "invite_link", "pinned_message", "sticker_set_name", "can_set_sticker_set",
|
||||||
"permissions"
|
"members_count", "restriction_reason", "permissions"
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -92,6 +103,9 @@ class Chat(PyrogramType):
|
|||||||
client: "pyrogram.BaseClient" = None,
|
client: "pyrogram.BaseClient" = None,
|
||||||
id: int,
|
id: int,
|
||||||
type: str,
|
type: str,
|
||||||
|
is_verified: bool = None,
|
||||||
|
is_restricted: bool = None,
|
||||||
|
is_scam: bool = None,
|
||||||
title: str = None,
|
title: str = None,
|
||||||
username: str = None,
|
username: str = None,
|
||||||
first_name: str = None,
|
first_name: str = None,
|
||||||
@ -110,6 +124,9 @@ class Chat(PyrogramType):
|
|||||||
|
|
||||||
self.id = id
|
self.id = id
|
||||||
self.type = type
|
self.type = type
|
||||||
|
self.is_verified = is_verified
|
||||||
|
self.is_restricted = is_restricted
|
||||||
|
self.is_scam = is_scam
|
||||||
self.title = title
|
self.title = title
|
||||||
self.username = username
|
self.username = username
|
||||||
self.first_name = first_name
|
self.first_name = first_name
|
||||||
@ -126,36 +143,45 @@ class Chat(PyrogramType):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_user_chat(client, user: types.User) -> "Chat":
|
def _parse_user_chat(client, user: types.User) -> "Chat":
|
||||||
|
peer_id = user.id
|
||||||
|
|
||||||
return Chat(
|
return Chat(
|
||||||
id=user.id,
|
id=peer_id,
|
||||||
type="bot" if user.bot else "private",
|
type="bot" if user.bot else "private",
|
||||||
username=user.username,
|
username=user.username,
|
||||||
first_name=user.first_name,
|
first_name=user.first_name,
|
||||||
last_name=user.last_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,
|
restriction_reason=user.restriction_reason,
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_chat_chat(client, chat: types.Chat) -> "Chat":
|
def _parse_chat_chat(client, chat: types.Chat) -> "Chat":
|
||||||
|
peer_id = -chat.id
|
||||||
|
|
||||||
return Chat(
|
return Chat(
|
||||||
id=-chat.id,
|
id=peer_id,
|
||||||
type="group",
|
type="group",
|
||||||
title=chat.title,
|
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)),
|
permissions=ChatPermissions._parse(getattr(chat, "default_banned_rights", None)),
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_channel_chat(client, channel: types.Channel) -> "Chat":
|
def _parse_channel_chat(client, channel: types.Channel) -> "Chat":
|
||||||
|
peer_id = int("-100" + str(channel.id))
|
||||||
|
|
||||||
return Chat(
|
return Chat(
|
||||||
id=int("-100" + str(channel.id)),
|
id=peer_id,
|
||||||
type="supergroup" if channel.megagroup else "channel",
|
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,
|
title=channel.title,
|
||||||
username=getattr(channel, "username", None),
|
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),
|
restriction_reason=getattr(channel, "restriction_reason", None),
|
||||||
permissions=ChatPermissions._parse(getattr(channel, "default_banned_rights", None)),
|
permissions=ChatPermissions._parse(getattr(channel, "default_banned_rights", None)),
|
||||||
client=client
|
client=client
|
||||||
|
@ -45,6 +45,19 @@ class User(PyrogramType):
|
|||||||
is_bot (``bool``):
|
is_bot (``bool``):
|
||||||
True, if this user is a bot.
|
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``):
|
first_name (``str``):
|
||||||
User's or bot's first name.
|
User's or bot's first name.
|
||||||
|
|
||||||
@ -68,11 +81,13 @@ class User(PyrogramType):
|
|||||||
|
|
||||||
restriction_reason (``str``, *optional*):
|
restriction_reason (``str``, *optional*):
|
||||||
The reason why this bot might be unavailable to some users.
|
The reason why this bot might be unavailable to some users.
|
||||||
|
This field is available only in case *is_restricted* is True.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = [
|
__slots__ = [
|
||||||
"id", "is_self", "is_contact", "is_mutual_contact", "is_deleted", "is_bot", "first_name", "last_name", "status",
|
"id", "is_self", "is_contact", "is_mutual_contact", "is_deleted", "is_bot", "is_verified", "is_restricted",
|
||||||
"username", "language_code", "phone_number", "photo", "restriction_reason"
|
"is_support", "is_scam", "first_name", "last_name", "status", "username", "language_code", "phone_number",
|
||||||
|
"photo", "restriction_reason"
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -85,6 +100,10 @@ class User(PyrogramType):
|
|||||||
is_mutual_contact: bool,
|
is_mutual_contact: bool,
|
||||||
is_deleted: bool,
|
is_deleted: bool,
|
||||||
is_bot: bool,
|
is_bot: bool,
|
||||||
|
is_verified: bool,
|
||||||
|
is_restricted: bool,
|
||||||
|
is_support: bool,
|
||||||
|
is_scam: bool,
|
||||||
first_name: str,
|
first_name: str,
|
||||||
last_name: str = None,
|
last_name: str = None,
|
||||||
status: UserStatus = None,
|
status: UserStatus = None,
|
||||||
@ -102,6 +121,10 @@ class User(PyrogramType):
|
|||||||
self.is_mutual_contact = is_mutual_contact
|
self.is_mutual_contact = is_mutual_contact
|
||||||
self.is_deleted = is_deleted
|
self.is_deleted = is_deleted
|
||||||
self.is_bot = is_bot
|
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.first_name = first_name
|
||||||
self.last_name = last_name
|
self.last_name = last_name
|
||||||
self.status = status
|
self.status = status
|
||||||
@ -123,13 +146,17 @@ class User(PyrogramType):
|
|||||||
is_mutual_contact=user.mutual_contact,
|
is_mutual_contact=user.mutual_contact,
|
||||||
is_deleted=user.deleted,
|
is_deleted=user.deleted,
|
||||||
is_bot=user.bot,
|
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,
|
first_name=user.first_name,
|
||||||
last_name=user.last_name,
|
last_name=user.last_name,
|
||||||
status=UserStatus._parse(client, user.status, user.id, user.bot),
|
status=UserStatus._parse(client, user.status, user.id, user.bot),
|
||||||
username=user.username,
|
username=user.username,
|
||||||
language_code=user.lang_code,
|
language_code=user.lang_code,
|
||||||
phone_number=user.phone,
|
phone_number=user.phone,
|
||||||
photo=ChatPhoto._parse(client, user.photo),
|
photo=ChatPhoto._parse(client, user.photo, user.id),
|
||||||
restriction_reason=user.restriction_reason,
|
restriction_reason=user.restriction_reason,
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user