Add set_emoji_status method

This commit is contained in:
Dan 2022-09-03 14:18:12 +02:00
parent 04b343f61b
commit 5d11c03b4e
4 changed files with 71 additions and 1 deletions

View File

@ -252,6 +252,7 @@ def pyrogram_api():
unblock_user
get_common_chats
get_default_emoji_statuses
set_emoji_status
""",
invite_links="""
Invite Links

View File

@ -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

View File

@ -0,0 +1,56 @@
# 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 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

View File

@ -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
)