From 5d11c03b4ee74e805391b1955683a617c881052f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 3 Sep 2022 14:18:12 +0200 Subject: [PATCH] Add set_emoji_status method --- compiler/docs/compiler.py | 1 + pyrogram/methods/users/__init__.py | 4 +- pyrogram/methods/users/set_emoji_status.py | 56 +++++++++++++++++++ pyrogram/types/user_and_chats/emoji_status.py | 11 ++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/users/set_emoji_status.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 149cdcf0..12a4d972 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -252,6 +252,7 @@ def pyrogram_api(): unblock_user get_common_chats get_default_emoji_statuses + set_emoji_status """, invite_links=""" Invite Links diff --git a/pyrogram/methods/users/__init__.py b/pyrogram/methods/users/__init__.py index 52c4699f..31fda1dc 100644 --- a/pyrogram/methods/users/__init__.py +++ b/pyrogram/methods/users/__init__.py @@ -24,6 +24,7 @@ from .get_common_chats import GetCommonChats from .get_default_emoji_statuses import GetDefaultEmojiStatuses from .get_me import GetMe from .get_users import GetUsers +from .set_emoji_status import SetEmojiStatus from .set_profile_photo import SetProfilePhoto from .set_username import SetUsername from .unblock_user import UnblockUser @@ -42,6 +43,7 @@ class Users( GetChatPhotosCount, UnblockUser, UpdateProfile, - GetDefaultEmojiStatuses + GetDefaultEmojiStatuses, + SetEmojiStatus ): pass diff --git a/pyrogram/methods/users/set_emoji_status.py b/pyrogram/methods/users/set_emoji_status.py new file mode 100644 index 00000000..288e966b --- /dev/null +++ b/pyrogram/methods/users/set_emoji_status.py @@ -0,0 +1,56 @@ +# 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 typing import Optional + +import pyrogram +from pyrogram import raw, types + + +class SetEmojiStatus: + async def set_emoji_status( + self: "pyrogram.Client", + emoji_status: Optional["types.EmojiStatus"] = None + ) -> bool: + """Set the emoji status. + + Parameters: + emoji_status (:obj:`~pyrogram.types.EmojiStatus`, *optional*): + The emoji status to set. None to remove. + + Returns: + ``bool``: On success, True is returned. + + Example: + .. code-block:: python + + from pyrogram import types + + await app.set_emoji_status(types.EmojiStatus(custom_emoji_id=1234567890987654321)) + """ + await self.invoke( + raw.functions.account.UpdateEmojiStatus( + emoji_status=( + emoji_status.write() + if emoji_status + else raw.types.EmojiStatusEmpty() + ) + ) + ) + + return True diff --git a/pyrogram/types/user_and_chats/emoji_status.py b/pyrogram/types/user_and_chats/emoji_status.py index 746c98ef..50b46bfa 100644 --- a/pyrogram/types/user_and_chats/emoji_status.py +++ b/pyrogram/types/user_and_chats/emoji_status.py @@ -64,3 +64,14 @@ class EmojiStatus(Object): ) return None + + def write(self): + if self.until_date: + return raw.types.EmojiStatusUntil( + document_id=self.custom_emoji_id, + until=utils.datetime_to_timestamp(self.until_date) + ) + + return raw.types.EmojiStatus( + document_id=self.custom_emoji_id + )