Skip to content

Commit 7a53c3d

Browse files
committed
Add support for emoji status
1 parent 2cd0f38 commit 7a53c3d

4 files changed

Lines changed: 77 additions & 1 deletion

File tree

compiler/docs/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ def get_title_list(s: str) -> list:
385385
ChatJoiner
386386
Dialog
387387
Restriction
388+
EmojiStatus
388389
""",
389390
messages_media="""
390391
Messages & Media

pyrogram/types/user_and_chats/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .chat_preview import ChatPreview
3131
from .chat_privileges import ChatPrivileges
3232
from .dialog import Dialog
33+
from .emoji_status import EmojiStatus
3334
from .invite_link_importer import InviteLinkImporter
3435
from .restriction import Restriction
3536
from .user import User
@@ -59,5 +60,6 @@
5960
"VideoChatScheduled",
6061
"ChatJoinRequest",
6162
"ChatPrivileges",
62-
"ChatJoiner"
63+
"ChatJoiner",
64+
"EmojiStatus"
6365
]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from datetime import datetime
20+
from typing import Optional
21+
22+
import pyrogram
23+
from pyrogram import raw
24+
from pyrogram import utils
25+
from ..object import Object
26+
27+
28+
class EmojiStatus(Object):
29+
"""A user emoji status.
30+
31+
Parameters:
32+
custom_emoji_id (``int``):
33+
Custom emoji id.
34+
35+
until_date (:py:obj:`~datetime.datetime`, *optional*):
36+
Valid until date.
37+
"""
38+
39+
def __init__(
40+
self,
41+
*,
42+
client: "pyrogram.Client" = None,
43+
custom_emoji_id: int,
44+
until_date: Optional[datetime] = None
45+
):
46+
super().__init__(client)
47+
48+
self.custom_emoji_id = custom_emoji_id
49+
self.until_date = until_date
50+
51+
@staticmethod
52+
def _parse(client, emoji_status: "raw.base.EmojiStatus") -> Optional["EmojiStatus"]:
53+
if isinstance(emoji_status, raw.types.EmojiStatusEmpty):
54+
return None
55+
56+
if isinstance(emoji_status, raw.types.EmojiStatus):
57+
return EmojiStatus(
58+
client=client,
59+
custom_emoji_id=emoji_status.document_id
60+
)
61+
62+
if isinstance(emoji_status, raw.types.EmojiStatusUntil):
63+
return EmojiStatus(
64+
client=client,
65+
custom_emoji_id=emoji_status.document_id,
66+
until_date=utils.timestamp_to_datetime(emoji_status.until)
67+
)

pyrogram/types/user_and_chats/user.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class User(Object, Update):
121121
language_code (``str``, *optional*):
122122
IETF language tag of the user's language.
123123
124+
emoji_status (:obj:`~pyrogram.types.EmojiStatus`, *optional*):
125+
Emoji status.
126+
124127
dc_id (``int``, *optional*):
125128
User's or bot's assigned DC (data center). Available only in case the user has set a public profile photo.
126129
Note that this information is approximate; it is based on where Telegram stores a user profile pictures and
@@ -167,6 +170,7 @@ def __init__(
167170
next_offline_date: datetime = None,
168171
username: str = None,
169172
language_code: str = None,
173+
emoji_status: Optional[str] = None,
170174
dc_id: int = None,
171175
phone_number: str = None,
172176
photo: "types.ChatPhoto" = None,
@@ -193,6 +197,7 @@ def __init__(
193197
self.next_offline_date = next_offline_date
194198
self.username = username
195199
self.language_code = language_code
200+
self.emoji_status = emoji_status
196201
self.dc_id = dc_id
197202
self.phone_number = phone_number
198203
self.photo = photo
@@ -229,6 +234,7 @@ def _parse(client, user: "raw.base.User") -> Optional["User"]:
229234
**User._parse_status(user.status, user.bot),
230235
username=user.username,
231236
language_code=user.lang_code,
237+
emoji_status=types.EmojiStatus._parse(client, user.emoji_status),
232238
dc_id=getattr(user.photo, "dc_id", None),
233239
phone_number=user.phone,
234240
photo=types.ChatPhoto._parse(client, user.photo, user.id, user.access_hash),

0 commit comments

Comments
 (0)