mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-07 07:24:51 +00:00
PyroFork: Add usernames field to Chat
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
4401c62244
commit
2cd117f301
3 changed files with 81 additions and 1 deletions
|
|
@ -36,6 +36,7 @@ from .emoji_status import EmojiStatus
|
||||||
from .invite_link_importer import InviteLinkImporter
|
from .invite_link_importer import InviteLinkImporter
|
||||||
from .restriction import Restriction
|
from .restriction import Restriction
|
||||||
from .user import User
|
from .user import User
|
||||||
|
from .username import Username
|
||||||
from .forum_topic import ForumTopic
|
from .forum_topic import ForumTopic
|
||||||
from .forum_topic_created import ForumTopicCreated
|
from .forum_topic_created import ForumTopicCreated
|
||||||
from .forum_topic_closed import ForumTopicClosed
|
from .forum_topic_closed import ForumTopicClosed
|
||||||
|
|
@ -58,6 +59,7 @@ __all__ = [
|
||||||
"ChatPreview",
|
"ChatPreview",
|
||||||
"Dialog",
|
"Dialog",
|
||||||
"User",
|
"User",
|
||||||
|
"Username",
|
||||||
"Restriction",
|
"Restriction",
|
||||||
"ChatEvent",
|
"ChatEvent",
|
||||||
"ChatEventFilter",
|
"ChatEventFilter",
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,10 @@ class Chat(Object):
|
||||||
|
|
||||||
full_name (``str``, *property*):
|
full_name (``str``, *property*):
|
||||||
Full name of the other party in a private chat, for private chats and bots.
|
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__(
|
def __init__(
|
||||||
|
|
@ -169,7 +173,8 @@ class Chat(Object):
|
||||||
distance: int = None,
|
distance: int = None,
|
||||||
linked_chat: "types.Chat" = None,
|
linked_chat: "types.Chat" = None,
|
||||||
send_as_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)
|
super().__init__(client)
|
||||||
|
|
||||||
|
|
@ -202,6 +207,7 @@ class Chat(Object):
|
||||||
self.linked_chat = linked_chat
|
self.linked_chat = linked_chat
|
||||||
self.send_as_chat = send_as_chat
|
self.send_as_chat = send_as_chat
|
||||||
self.available_reactions = available_reactions
|
self.available_reactions = available_reactions
|
||||||
|
self.usernames = usernames
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def full_name(self) -> str:
|
def full_name(self) -> str:
|
||||||
|
|
@ -231,6 +237,12 @@ class Chat(Object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_chat_chat(client, chat: raw.types.Chat) -> "Chat":
|
def _parse_chat_chat(client, chat: raw.types.Chat) -> "Chat":
|
||||||
peer_id = -chat.id
|
peer_id = -chat.id
|
||||||
|
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(
|
return Chat(
|
||||||
id=peer_id,
|
id=peer_id,
|
||||||
|
|
@ -242,6 +254,7 @@ class Chat(Object):
|
||||||
members_count=getattr(chat, "participants_count", None),
|
members_count=getattr(chat, "participants_count", None),
|
||||||
dc_id=getattr(getattr(chat, "photo", None), "dc_id", None),
|
dc_id=getattr(getattr(chat, "photo", None), "dc_id", None),
|
||||||
has_protected_content=getattr(chat, "noforwards", None),
|
has_protected_content=getattr(chat, "noforwards", None),
|
||||||
|
usernames=usernames,
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -249,6 +262,12 @@ class Chat(Object):
|
||||||
def _parse_channel_chat(client, channel: raw.types.Channel) -> "Chat":
|
def _parse_channel_chat(client, channel: raw.types.Channel) -> "Chat":
|
||||||
peer_id = utils.get_channel_id(channel.id)
|
peer_id = utils.get_channel_id(channel.id)
|
||||||
restriction_reason = getattr(channel, "restriction_reason", [])
|
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(
|
return Chat(
|
||||||
id=peer_id,
|
id=peer_id,
|
||||||
|
|
@ -261,6 +280,7 @@ class Chat(Object):
|
||||||
is_forum=getattr(channel, "forum", None),
|
is_forum=getattr(channel, "forum", None),
|
||||||
title=channel.title,
|
title=channel.title,
|
||||||
username=getattr(channel, "username", None),
|
username=getattr(channel, "username", None),
|
||||||
|
usernames=usernames,
|
||||||
photo=types.ChatPhoto._parse(client, getattr(channel, "photo", None), peer_id,
|
photo=types.ChatPhoto._parse(client, getattr(channel, "photo", None), peer_id,
|
||||||
getattr(channel, "access_hash", 0)),
|
getattr(channel, "access_hash", 0)),
|
||||||
restrictions=types.List([types.Restriction._parse(r) for r in restriction_reason]) or None,
|
restrictions=types.List([types.Restriction._parse(r) for r in restriction_reason]) or None,
|
||||||
|
|
|
||||||
58
pyrogram/types/user_and_chats/username.py
Normal file
58
pyrogram/types/user_and_chats/username.py
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram 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.
|
||||||
|
#
|
||||||
|
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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)
|
||||||
|
)
|
||||||
Loading…
Reference in a new issue