Return bool from update_color

This commit is contained in:
KurimuzonAkuma 2023-12-08 01:37:00 +03:00
parent c88dd2bcf1
commit 50e2d102b4

View File

@ -21,7 +21,6 @@ from typing import Union
import pyrogram
from pyrogram import raw
from pyrogram import enums
from pyrogram import types
class UpdateColor:
async def update_color(
@ -29,7 +28,7 @@ class UpdateColor:
chat_id: Union[int, str],
color: Union["enums.ReplyColor", "enums.ProfileColor"],
background_emoji_id: int = None
) -> "types.Chat":
) -> bool:
"""Update color
.. include:: /_includes/usable-by/users.rst
@ -40,32 +39,29 @@ class UpdateColor:
color (:obj:`~pyrogram.enums.ReplyColor` | :obj:`~pyrogram.enums.ProfileColor`):
Color type.
Profile color can only be set for the user.
background_emoji_id (``int``, *optional*):
Unique identifier of the custom emoji.
Returns:
:obj:`~pyrogram.types.Chat`: On success, a chat object is returned.
``bool``: On success, in case the passed-in session is authorized, True is returned.
Example:
.. code-block:: python
await app.update_color(chat_id, enums.ProfileColor.RED)
await app.update_color(chat_id, enums.ReplyColor.RED)
"""
peer = await self.resolve_peer(chat_id)
if isinstance(peer, raw.types.InputPeerSelf):
await self.invoke(
r = await self.invoke(
raw.functions.account.UpdateColor(
for_profile=isinstance(color, enums.ProfileColor),
color=color.value,
background_emoji_id=background_emoji_id
)
)
r = await self.invoke(raw.functions.users.GetUsers(id=[raw.types.InputPeerSelf()]))
chat = r[0]
else:
r = await self.invoke(
raw.functions.channels.UpdateColor(
@ -74,6 +70,5 @@ class UpdateColor:
background_emoji_id=background_emoji_id
)
)
chat = r.chats[0]
return types.Chat._parse_chat(self, chat)
return bool(r)