From 244ad9322987fa7fd4509af00dbfb80b138aba90 Mon Sep 17 00:00:00 2001 From: Alisson Lauffer Date: Mon, 9 Jan 2023 01:07:58 -0300 Subject: [PATCH] Add `full_name` property to `User` and `Chat` objects Signed-off-by: wulan17 --- pyrogram/types/user_and_chats/chat.py | 18 +++++++++++++----- pyrogram/types/user_and_chats/user.py | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index f37542fb..0543cab8 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -1,20 +1,21 @@ -# Pyrogram - Telegram MTProto API Client Library for Python +# Pyrofork - Telegram MTProto API Client Library for Python # Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan # -# This file is part of Pyrogram. +# This file is part of Pyrofork. # -# Pyrogram is free software: you can redistribute it and/or modify +# 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. # -# Pyrogram is distributed in the hope that it will be useful, +# 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 Pyrogram. If not, see . +# along with Pyrofork. If not, see . from datetime import datetime from typing import Union, List, Optional, AsyncGenerator, BinaryIO @@ -129,6 +130,9 @@ class Chat(Object): available_reactions (:obj:`~pyrogram.types.ChatReactions`, *optional*): Available reactions in the chat. Returned only in :meth:`~pyrogram.Client.get_chat`. + + full_name (``str``, *property*): + Full name of the other party in a private chat, for private chats and bots. """ def __init__( @@ -195,6 +199,10 @@ class Chat(Object): self.send_as_chat = send_as_chat self.available_reactions = available_reactions + @property + def full_name(self) -> str: + return " ".join(filter(None, [self.first_name, self.last_name])) or None + @staticmethod def _parse_user_chat(client, user: raw.types.User) -> "Chat": peer_id = user.id diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py index e9813578..2c7f3d6d 100644 --- a/pyrogram/types/user_and_chats/user.py +++ b/pyrogram/types/user_and_chats/user.py @@ -1,20 +1,21 @@ -# Pyrogram - Telegram MTProto API Client Library for Python +# Pyrofork - Telegram MTProto API Client Library for Python # Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan # -# This file is part of Pyrogram. +# This file is part of Pyrofork. # -# Pyrogram is free software: you can redistribute it and/or modify +# 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. # -# Pyrogram is distributed in the hope that it will be useful, +# 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 Pyrogram. If not, see . +# along with Pyrofork. If not, see . import html from datetime import datetime @@ -140,6 +141,9 @@ class User(Object, Update): The list of reasons why this bot might be unavailable to some users. This field is available only in case *is_restricted* is True. + full_name (``str``, *optional*): + User's or bot's full name. + mention (``str``, *property*): Generate a text mention for this user. You can use ``user.mention()`` to mention the user using their first name (styled using html), or @@ -203,6 +207,10 @@ class User(Object, Update): self.photo = photo self.restrictions = restrictions + @property + def full_name(self) -> str: + return " ".join(filter(None, [self.first_name, self.last_name])) or None + @property def mention(self): return Link(