diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 05ab23fd..a6f82f32 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -385,6 +385,7 @@ def pyrogram_api(): ChatJoiner Dialog Restriction + EmojiStatus """, messages_media=""" Messages & Media diff --git a/pyrogram/types/user_and_chats/__init__.py b/pyrogram/types/user_and_chats/__init__.py index a9b63359..60ebd309 100644 --- a/pyrogram/types/user_and_chats/__init__.py +++ b/pyrogram/types/user_and_chats/__init__.py @@ -30,6 +30,7 @@ from .chat_photo import ChatPhoto from .chat_preview import ChatPreview from .chat_privileges import ChatPrivileges from .dialog import Dialog +from .emoji_status import EmojiStatus from .invite_link_importer import InviteLinkImporter from .restriction import Restriction from .user import User @@ -59,5 +60,6 @@ __all__ = [ "VideoChatScheduled", "ChatJoinRequest", "ChatPrivileges", - "ChatJoiner" + "ChatJoiner", + "EmojiStatus" ] diff --git a/pyrogram/types/user_and_chats/emoji_status.py b/pyrogram/types/user_and_chats/emoji_status.py new file mode 100644 index 00000000..99159dbc --- /dev/null +++ b/pyrogram/types/user_and_chats/emoji_status.py @@ -0,0 +1,67 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . + +from datetime import datetime +from typing import Optional + +import pyrogram +from pyrogram import raw +from pyrogram import utils +from ..object import Object + + +class EmojiStatus(Object): + """A user emoji status. + + Parameters: + custom_emoji_id (``int``): + Custom emoji id. + + until_date (:py:obj:`~datetime.datetime`, *optional*): + Valid until date. + """ + + def __init__( + self, + *, + client: "pyrogram.Client" = None, + custom_emoji_id: int, + until_date: Optional[datetime] = None + ): + super().__init__(client) + + self.custom_emoji_id = custom_emoji_id + self.until_date = until_date + + @staticmethod + def _parse(client, emoji_status: "raw.base.EmojiStatus") -> Optional["EmojiStatus"]: + if isinstance(emoji_status, raw.types.EmojiStatusEmpty): + return None + + if isinstance(emoji_status, raw.types.EmojiStatus): + return EmojiStatus( + client=client, + custom_emoji_id=emoji_status.document_id + ) + + if isinstance(emoji_status, raw.types.EmojiStatusUntil): + return EmojiStatus( + client=client, + custom_emoji_id=emoji_status.document_id, + until_date=utils.timestamp_to_datetime(emoji_status.until) + ) diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py index 4df3b17e..2c9b58f8 100644 --- a/pyrogram/types/user_and_chats/user.py +++ b/pyrogram/types/user_and_chats/user.py @@ -121,6 +121,9 @@ class User(Object, Update): language_code (``str``, *optional*): IETF language tag of the user's language. + emoji_status (:obj:`~pyrogram.types.EmojiStatus`, *optional*): + Emoji status. + dc_id (``int``, *optional*): User's or bot's assigned DC (data center). Available only in case the user has set a public profile photo. Note that this information is approximate; it is based on where Telegram stores a user profile pictures and @@ -167,6 +170,7 @@ class User(Object, Update): next_offline_date: datetime = None, username: str = None, language_code: str = None, + emoji_status: Optional[str] = None, dc_id: int = None, phone_number: str = None, photo: "types.ChatPhoto" = None, @@ -193,6 +197,7 @@ class User(Object, Update): self.next_offline_date = next_offline_date self.username = username self.language_code = language_code + self.emoji_status = emoji_status self.dc_id = dc_id self.phone_number = phone_number self.photo = photo @@ -229,6 +234,7 @@ class User(Object, Update): **User._parse_status(user.status, user.bot), username=user.username, language_code=user.lang_code, + emoji_status=types.EmojiStatus._parse(client, user.emoji_status), dc_id=getattr(user.photo, "dc_id", None), phone_number=user.phone, photo=types.ChatPhoto._parse(client, user.photo, user.id, user.access_hash),