|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present Dan <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from datetime import datetime |
| 20 | + |
| 21 | +import pyrogram |
| 22 | +from pyrogram import raw, types, utils |
| 23 | +from ..object import Object |
| 24 | + |
| 25 | + |
| 26 | +class GroupCallMessage(Object): |
| 27 | + """A message in a group call. |
| 28 | +
|
| 29 | + Parameters: |
| 30 | + id (``int``): |
| 31 | + Message identifier. |
| 32 | +
|
| 33 | + from_id (:obj:`~pyrogram.types.Chat` | :obj:`~pyrogram.types.User`): |
| 34 | + Sender of the message. |
| 35 | +
|
| 36 | + date (``datetime``): |
| 37 | + Date the message was sent. |
| 38 | +
|
| 39 | + text (``str``): |
| 40 | + Message text. |
| 41 | +
|
| 42 | + is_from_admin (``bool``, *optional*): |
| 43 | + True, if the message was sent by an admin. |
| 44 | +
|
| 45 | + paid_message_stars (``int``, *optional*): |
| 46 | + Price of the message in Telegram Stars. |
| 47 | + """ |
| 48 | + |
| 49 | + def __init__( |
| 50 | + self, |
| 51 | + *, |
| 52 | + client: "pyrogram.Client" = None, |
| 53 | + id: int, |
| 54 | + from_id: "types.Chat" = None, |
| 55 | + date: datetime, |
| 56 | + text: str, |
| 57 | + is_from_admin: bool = None, |
| 58 | + paid_message_stars: int = None |
| 59 | + ): |
| 60 | + super().__init__(client) |
| 61 | + |
| 62 | + self.id = id |
| 63 | + self.from_id = from_id |
| 64 | + self.date = date |
| 65 | + self.text = text |
| 66 | + self.is_from_admin = is_from_admin |
| 67 | + self.paid_message_stars = paid_message_stars |
| 68 | + |
| 69 | + @staticmethod |
| 70 | + def _parse( |
| 71 | + client: "pyrogram.Client", |
| 72 | + message: "raw.types.GroupCallMessage", |
| 73 | + users: dict = None, |
| 74 | + chats: dict = None |
| 75 | + ) -> "GroupCallMessage": |
| 76 | + if not message: |
| 77 | + return None |
| 78 | + |
| 79 | + return GroupCallMessage( |
| 80 | + client=client, |
| 81 | + id=message.id, |
| 82 | + from_id=types.Chat._parse(client, message.from_id, users, chats), |
| 83 | + date=utils.timestamp_to_datetime(message.date), |
| 84 | + text=message.message.text if hasattr(message.message, "text") else message.message, |
| 85 | + is_from_admin=getattr(message, "from_admin", None), |
| 86 | + paid_message_stars=getattr(message, "paid_message_stars", None) |
| 87 | + ) |
0 commit comments