diff --git a/pyrogram/types/user_and_chats/__init__.py b/pyrogram/types/user_and_chats/__init__.py index 6294c632..f0112112 100644 --- a/pyrogram/types/user_and_chats/__init__.py +++ b/pyrogram/types/user_and_chats/__init__.py @@ -37,6 +37,7 @@ from .emoji_status import EmojiStatus from .invite_link_importer import InviteLinkImporter from .restriction import Restriction from .user import User +from .username import Username from .video_chat_ended import VideoChatEnded from .video_chat_members_invited import VideoChatMembersInvited from .video_chat_scheduled import VideoChatScheduled @@ -50,6 +51,7 @@ __all__ = [ "ChatPreview", "Dialog", "User", + "Username", "Restriction", "ChatEvent", "ChatEventFilter", diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 0543cab8..550b22b2 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -133,6 +133,10 @@ class Chat(Object): full_name (``str``, *property*): Full name of the other party in a private chat, for private chats and bots. + + usernames (List of :obj:`~pyrogram.types.Username`, *optional*): + List of all chat (fragment) usernames; for private chats, supergroups and channels. + Returned only in :meth:`~pyrogram.Client.get_chat`. """ def __init__( @@ -166,7 +170,8 @@ class Chat(Object): distance: int = None, linked_chat: "types.Chat" = None, send_as_chat: "types.Chat" = None, - available_reactions: Optional["types.ChatReactions"] = None + available_reactions: Optional["types.ChatReactions"] = None, + usernames: List["types.Username"] = None ): super().__init__(client) @@ -198,6 +203,7 @@ class Chat(Object): self.linked_chat = linked_chat self.send_as_chat = send_as_chat self.available_reactions = available_reactions + self.usernames = usernames @property def full_name(self) -> str: @@ -227,6 +233,12 @@ class Chat(Object): @staticmethod def _parse_chat_chat(client, chat: raw.types.Chat) -> "Chat": peer_id = -chat.id + active_usernames = getattr(chat, "usernames", []) + usernames = None + if len(active_usernames) >= 1: + usernames = [] + for username in active_usernames: + usernames.append(types.Username._parse(username)) return Chat( id=peer_id, @@ -238,6 +250,7 @@ class Chat(Object): members_count=getattr(chat, "participants_count", None), dc_id=getattr(getattr(chat, "photo", None), "dc_id", None), has_protected_content=getattr(chat, "noforwards", None), + usernames=usernames, client=client ) @@ -245,6 +258,12 @@ class Chat(Object): def _parse_channel_chat(client, channel: raw.types.Channel) -> "Chat": peer_id = utils.get_channel_id(channel.id) restriction_reason = getattr(channel, "restriction_reason", []) + active_usernames = getattr(channel, "usernames", []) + usernames = None + if len(active_usernames) >= 1: + usernames = [] + for username in active_usernames: + usernames.append(types.Username._parse(username)) return Chat( id=peer_id, @@ -256,6 +275,7 @@ class Chat(Object): is_fake=getattr(channel, "fake", None), title=channel.title, username=getattr(channel, "username", None), + usernames=usernames, photo=types.ChatPhoto._parse(client, getattr(channel, "photo", None), peer_id, getattr(channel, "access_hash", 0)), restrictions=types.List([types.Restriction._parse(r) for r in restriction_reason]) or None, diff --git a/pyrogram/types/user_and_chats/username.py b/pyrogram/types/user_and_chats/username.py new file mode 100644 index 00000000..cc57a306 --- /dev/null +++ b/pyrogram/types/user_and_chats/username.py @@ -0,0 +1,58 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrofork 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 General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrofork. If not, see . + +from pyrogram import raw +from ..object import Object + + +class Username(Object): + """A Username. + + + Parameters: + username (``String``): + The channel/user username. + + editable (``bool``, *optional*): + Can the username edited. + + active (``bool``, *optional*) + Is the username active. + """ + + def __init__( + self, *, + username: str, + editable: bool = None, + active: bool = None + ): + super().__init__() + + self.username = username + self.editable = editable + self.active = active + + @staticmethod + def _parse(action: "raw.types.Username") -> "Username": + + + return Username( + username=getattr(action,"username", None), + editable=getattr(action,"editable", None), + active=getattr(action,"active", None) + )