Add chat_reactions.py

This commit is contained in:
Dan 2022-09-03 13:43:38 +02:00
parent fe7fcf3448
commit 9eb7589a7f
3 changed files with 75 additions and 4 deletions

View File

@ -29,6 +29,7 @@ from .chat_permissions import ChatPermissions
from .chat_photo import ChatPhoto
from .chat_preview import ChatPreview
from .chat_privileges import ChatPrivileges
from .chat_reactions import ChatReactions
from .dialog import Dialog
from .emoji_status import EmojiStatus
from .invite_link_importer import InviteLinkImporter
@ -61,5 +62,6 @@ __all__ = [
"ChatJoinRequest",
"ChatPrivileges",
"ChatJoiner",
"EmojiStatus"
"EmojiStatus",
"ChatReactions"
]

View File

@ -126,7 +126,7 @@ class Chat(Object):
The default "send_as" chat.
Returned only in :meth:`~pyrogram.Client.get_chat`.
available_reactions (List of ``str``, *optional*):
available_reactions (List of :obj:`~pyrogram.types.Reaction`, *optional*):
Available reactions in the chat.
Returned only in :meth:`~pyrogram.Client.get_chat`.
"""
@ -162,7 +162,7 @@ class Chat(Object):
distance: int = None,
linked_chat: "types.Chat" = None,
send_as_chat: "types.Chat" = None,
available_reactions: List[str] = None
available_reactions: Optional[List["types.Reaction"]] = None
):
super().__init__(client)
@ -345,7 +345,7 @@ class Chat(Object):
if isinstance(full_chat.exported_invite, raw.types.ChatInviteExported):
parsed_chat.invite_link = full_chat.exported_invite.link
parsed_chat.available_reactions = full_chat.available_reactions or None
parsed_chat.available_reactions = types.ChatReactions._parse(client, full_chat.available_reactions)
return parsed_chat

View File

@ -0,0 +1,69 @@
# 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, List
import pyrogram
from pyrogram import raw, types
from ..object import Object
class ChatReactions(Object):
"""A chat reactions
Parameters:
all_are_enabled (``bool``, *optional*)
allow_custom_emoji (``bool``, *optional*):
Whether custom emoji are allowed or not.
reactions (List of :obj:`~pyrogram.types.Reaction`, *optional*):
Reactions available.
"""
def __init__(
self,
*,
client: "pyrogram.Client" = None,
all_are_enabled: Optional[bool] = None,
allow_custom_emoji: Optional[bool] = None,
reactions: Optional[List["types.Reaction"]] = None,
):
super().__init__(client)
self.all_are_enabled = all_are_enabled
self.allow_custom_emoji = allow_custom_emoji
self.reactions = reactions
@staticmethod
def _parse(client, chat_reactions: "raw.base.ChatReactions") -> Optional["ChatReactions"]:
if isinstance(chat_reactions, raw.types.ChatReactionsAll):
return ChatReactions(
client=client,
all_are_enabled=True,
allow_custom_emoji=chat_reactions.allow_custom
)
if isinstance(chat_reactions, raw.types.ChatReactionsSome):
return ChatReactions(
client=client,
reactions=[types.Reaction._parse(client, reaction)
for reaction in chat_reactions.reactions]
)
return None