Add support for voice chat service messages
This commit is contained in:
parent
783e89e0f0
commit
975ff219f2
@ -264,6 +264,15 @@ class Message(Object, Update):
|
||||
E.g.: "/start 1 2 3" would produce ["start", "1", "2", "3"].
|
||||
Only applicable when using :obj:`~pyrogram.filters.command`.
|
||||
|
||||
voice_chat_started (:obj:`~pyrogram.types.VoiceChatStarted`, *optional*):
|
||||
Service message: the voice chat started.
|
||||
|
||||
voice_chat_ended (:obj:`~pyrogram.types.VoiceChatEnded`, *optional*):
|
||||
Service message: the voice chat has ended.
|
||||
|
||||
voice_chat_members_invited (:obj:`~pyrogram.types.VoiceChatParticipantsInvited`, *optional*):
|
||||
Service message: new members were invited to the voice chat.
|
||||
|
||||
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*):
|
||||
Additional interface options. An object for an inline keyboard, custom reply keyboard,
|
||||
instructions to remove reply keyboard or to force a reply from the user.
|
||||
@ -335,6 +344,9 @@ class Message(Object, Update):
|
||||
outgoing: bool = None,
|
||||
matches: List[Match] = None,
|
||||
command: List[str] = None,
|
||||
voice_chat_started: "types.VoiceChatStarted" = None,
|
||||
voice_chat_ended: "types.VoiceChatEnded" = None,
|
||||
voice_chat_members_invited: "types.VoiceChatMemberInvited" = None,
|
||||
reply_markup: Union[
|
||||
"types.InlineKeyboardMarkup",
|
||||
"types.ReplyKeyboardMarkup",
|
||||
@ -402,6 +414,9 @@ class Message(Object, Update):
|
||||
self.matches = matches
|
||||
self.command = command
|
||||
self.reply_markup = reply_markup
|
||||
self.voice_chat_started = voice_chat_started
|
||||
self.voice_chat_ended = voice_chat_ended
|
||||
self.voice_chat_members_invited = voice_chat_members_invited
|
||||
|
||||
@staticmethod
|
||||
async def _parse(
|
||||
@ -427,6 +442,9 @@ class Message(Object, Update):
|
||||
group_chat_created = None
|
||||
channel_chat_created = None
|
||||
new_chat_photo = None
|
||||
voice_chat_started = None
|
||||
voice_chat_ended = None
|
||||
voice_chat_members_invited = None
|
||||
|
||||
if isinstance(action, raw.types.MessageActionChatAddUser):
|
||||
new_chat_members = [types.User._parse(client, users[i]) for i in action.users]
|
||||
@ -448,6 +466,13 @@ class Message(Object, Update):
|
||||
channel_chat_created = True
|
||||
elif isinstance(action, raw.types.MessageActionChatEditPhoto):
|
||||
new_chat_photo = types.Photo._parse(client, action.photo)
|
||||
elif isinstance(action, raw.types.MessageActionGroupCall):
|
||||
if action.duration:
|
||||
voice_chat_ended = types.VoiceChatEnded._parse(action)
|
||||
else:
|
||||
voice_chat_started = types.VoiceChatStarted()
|
||||
elif isinstance(action, raw.types.MessageActionInviteToGroupCall):
|
||||
voice_chat_members_invited = types.VoiceChatMembersInvited._parse(client, action, users)
|
||||
|
||||
user = utils.get_raw_peer_id(message.from_id) or utils.get_raw_peer_id(message.peer_id)
|
||||
from_user = types.User._parse(client, users.get(user, None))
|
||||
@ -469,7 +494,10 @@ class Message(Object, Update):
|
||||
migrate_from_chat_id=-migrate_from_chat_id if migrate_from_chat_id else None,
|
||||
group_chat_created=group_chat_created,
|
||||
channel_chat_created=channel_chat_created,
|
||||
client=client
|
||||
client=client,
|
||||
voice_chat_started=voice_chat_started,
|
||||
voice_chat_ended=voice_chat_ended,
|
||||
voice_chat_members_invited=voice_chat_members_invited
|
||||
# TODO: supergroup_chat_created
|
||||
)
|
||||
|
||||
|
@ -29,6 +29,9 @@ from .dialog import Dialog
|
||||
from .invite_link_importer import InviteLinkImporter
|
||||
from .restriction import Restriction
|
||||
from .user import User
|
||||
from .voice_chat_ended import VoiceChatEnded
|
||||
from .voice_chat_members_invited import VoiceChatMembersInvited
|
||||
from .voice_chat_started import VoiceChatStarted
|
||||
|
||||
__all__ = [
|
||||
"Chat",
|
||||
@ -43,5 +46,8 @@ __all__ = [
|
||||
"ChatEventFilter",
|
||||
"ChatInviteLink",
|
||||
"InviteLinkImporter",
|
||||
"ChatAdminWithInviteLinks"
|
||||
"ChatAdminWithInviteLinks",
|
||||
"VoiceChatStarted",
|
||||
"VoiceChatEnded",
|
||||
"VoiceChatMembersInvited"
|
||||
]
|
||||
|
41
pyrogram/types/user_and_chats/voice_chat_ended.py
Normal file
41
pyrogram/types/user_and_chats/voice_chat_ended.py
Normal file
@ -0,0 +1,41 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2021 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 pyrogram import raw
|
||||
from ..object import Object
|
||||
|
||||
|
||||
class VoiceChatEnded(Object):
|
||||
"""A service message about a voice chat ended in the chat.
|
||||
|
||||
Parameters:
|
||||
duration (``int``):
|
||||
Voice chat duration; in seconds.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, *,
|
||||
duration: int
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
self.duration = duration
|
||||
|
||||
@staticmethod
|
||||
def _parse(action: "raw.types.MessageActionGroupCall") -> "VoiceChatEnded":
|
||||
return VoiceChatEnded(duration=action.duration)
|
50
pyrogram/types/user_and_chats/voice_chat_members_invited.py
Normal file
50
pyrogram/types/user_and_chats/voice_chat_members_invited.py
Normal file
@ -0,0 +1,50 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2021 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 List, Dict
|
||||
|
||||
from pyrogram import raw, types
|
||||
from ..object import Object
|
||||
|
||||
|
||||
class VoiceChatMembersInvited(Object):
|
||||
"""A service message about new members invited to a voice chat.
|
||||
|
||||
|
||||
Parameters:
|
||||
users (List of :obj:`~pyrogram.types.User`):
|
||||
New members that were invited to the voice chat.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, *,
|
||||
users: List["types.User"]
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
self.users = users
|
||||
|
||||
@staticmethod
|
||||
def _parse(
|
||||
client,
|
||||
action: "raw.types.MessageActionInviteToGroupCall",
|
||||
users: Dict[int, "raw.types.User"]
|
||||
) -> "VoiceChatMembersInvited":
|
||||
users = [types.User._parse(client, users[i]) for i in action.users]
|
||||
|
||||
return VoiceChatMembersInvited(users=users)
|
29
pyrogram/types/user_and_chats/voice_chat_started.py
Normal file
29
pyrogram/types/user_and_chats/voice_chat_started.py
Normal file
@ -0,0 +1,29 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2021 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 ..object import Object
|
||||
|
||||
|
||||
class VoiceChatStarted(Object):
|
||||
"""A service message about a voice chat started in the chat.
|
||||
|
||||
Currently holds no information.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
Loading…
Reference in New Issue
Block a user