Pyrogram: Add ForumTopicCreated, ForumTopicClosed, ForumTopicReopened, ForumTopicEdited service message types

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
wulan17 2022-11-15 12:12:58 +07:00
parent 6f8aaa449c
commit 115b9877b6
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5
7 changed files with 249 additions and 2 deletions

View file

@ -57,6 +57,18 @@ class MessageServiceType(AutoName):
GAME_HIGH_SCORE = auto()
"Game high score"
FORUM_TOPIC_CREATED = auto()
"a new forum topic created in the chat"
FORUM_TOPIC_CLOSED = auto()
"a new forum topic closed in the chat"
FORUM_TOPIC_REOPENED = auto()
"a new forum topic reopened in the chat"
FORUM_TOPIC_EDITED = auto()
"a new forum topic renamed in the chat"
VIDEO_CHAT_STARTED = auto()
"Video chat started"

View file

@ -260,8 +260,8 @@ class Message(Object, Update):
views (``int``, *optional*):
Channel post views.
forwards (``int``, *optional*):
forwards (``int``, *optional*):
Channel post forwards.
via_bot (:obj:`~pyrogram.types.User`):
@ -282,6 +282,18 @@ class Message(Object, Update):
E.g.: "/start 1 2 3" would produce ["start", "1", "2", "3"].
Only applicable when using :obj:`~pyrogram.filters.command`.
forum_topic_created (:obj:`~pyrogram.types.ForumTopicCreated`, *optional*):
Service message: forum topic created
forum_topic_closed (:obj:`~pyrogram.types.ForumTopicClosed`, *optional*):
Service message: forum topic closed
forum_topic_reopened (:obj:`~pyrogram.types.ForumTopicReopened`, *optional*):
Service message: forum topic reopened
forum_topic_edited (:obj:`~pyrogram.types.ForumTopicEdited`, *optional*):
Service message: forum topic edited
video_chat_scheduled (:obj:`~pyrogram.types.VideoChatScheduled`, *optional*):
Service message: voice chat scheduled.
@ -377,6 +389,10 @@ class Message(Object, Update):
outgoing: bool = None,
matches: List[Match] = None,
command: List[str] = None,
forum_topic_created: "types.ForumTopicCreated" = None,
forum_topic_closed: "types.ForumTopicClosed" = None,
forum_topic_reopened: "types.ForumTopicReopened" = None,
forum_topic_edited: "types.ForumTopicEdited" = None,
video_chat_scheduled: "types.VideoChatScheduled" = None,
video_chat_started: "types.VideoChatStarted" = None,
video_chat_ended: "types.VideoChatEnded" = None,
@ -456,6 +472,10 @@ class Message(Object, Update):
self.matches = matches
self.command = command
self.reply_markup = reply_markup
self.forum_topic_created = forum_topic_created
self.forum_topic_closed = forum_topic_closed
self.forum_topic_reopened = forum_topic_reopened
self.forum_topic_edited = forum_topic_edited
self.video_chat_scheduled = video_chat_scheduled
self.video_chat_started = video_chat_started
self.video_chat_ended = video_chat_ended
@ -496,6 +516,7 @@ class Message(Object, Update):
users.update({i.id: i for i in r})
if isinstance(message, raw.types.MessageService):
message_thread_id = None
action = message.action
new_chat_members = None
@ -507,6 +528,11 @@ class Message(Object, Update):
group_chat_created = None
channel_chat_created = None
new_chat_photo = None
is_topic_message = None
forum_topic_created = None
forum_topic_closed = None
forum_topic_reopened = None
forum_topic_edited = None
video_chat_scheduled = None
video_chat_started = None
video_chat_ended = None
@ -545,6 +571,19 @@ class Message(Object, Update):
elif isinstance(action, raw.types.MessageActionChatEditPhoto):
new_chat_photo = types.Photo._parse(client, action.photo)
service_type = enums.MessageServiceType.NEW_CHAT_PHOTO
elif isinstance(action, raw.types.MessageActionTopicCreate):
forum_topic_created = types.ForumTopicCreated._parse(action)
service_type = enums.MessageServiceType.FORUM_TOPIC_CREATED
elif isinstance(action, raw.types.MessageActionTopicEdit):
if action.title:
forum_topic_edited = types.ForumTopicEdited._parse(action)
service_type = enums.MessageServiceType.FORUM_TOPIC_EDITED
elif action.closed:
forum_topic_closed = types.ForumTopicClosed()
service_type = enums.MessageServiceType.FORUM_TOPIC_CLOSED
else:
forum_topic_reopened = types.ForumTopicReopened()
service_type = enums.MessageServiceType.FORUM_TOPIC_REOPENED
elif isinstance(action, raw.types.MessageActionGroupCallScheduled):
video_chat_scheduled = types.VideoChatScheduled._parse(action)
service_type = enums.MessageServiceType.VIDEO_CHAT_SCHEDULED
@ -567,6 +606,7 @@ class Message(Object, Update):
parsed_message = Message(
id=message.id,
message_thread_id=message_thread_id,
date=utils.timestamp_to_datetime(message.date),
chat=types.Chat._parse(client, message, users, chats, is_chat=True),
from_user=from_user,
@ -581,6 +621,11 @@ 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,
is_topic_message=is_topic_message,
forum_topic_created=forum_topic_created,
forum_topic_closed=forum_topic_closed,
forum_topic_reopened=forum_topic_reopened,
forum_topic_edited=forum_topic_edited,
video_chat_scheduled=video_chat_scheduled,
video_chat_started=video_chat_started,
video_chat_ended=video_chat_ended,
@ -619,6 +664,14 @@ class Message(Object, Update):
client.message_cache[(parsed_message.chat.id, parsed_message.id)] = parsed_message
if message.reply_to:
if message.reply_to.forum_topic:
if message.reply_to.reply_to_top_id:
parsed_message.message_thread_id = message.reply_to.reply_to_top_id
else:
parsed_message.message_thread_id = message.reply_to.reply_to_msg_id
parsed_message.is_topic_message = True
return parsed_message
if isinstance(message, raw.types.Message):

View file

@ -35,6 +35,10 @@ from .emoji_status import EmojiStatus
from .invite_link_importer import InviteLinkImporter
from .restriction import Restriction
from .user import User
from .forum_topic_created import ForumTopicCreated
from .forum_topic_closed import ForumTopicClosed
from .forum_topic_reopened import ForumTopicReopened
from .forum_topic_edited import ForumTopicEdited
from .video_chat_ended import VideoChatEnded
from .video_chat_members_invited import VideoChatMembersInvited
from .video_chat_scheduled import VideoChatScheduled
@ -54,6 +58,10 @@ __all__ = [
"ChatInviteLink",
"InviteLinkImporter",
"ChatAdminWithInviteLinks",
"ForumTopicCreated",
"ForumTopicClosed",
"ForumTopicReopened",
"ForumTopicEdited",
"VideoChatStarted",
"VideoChatEnded",
"VideoChatMembersInvited",

View file

@ -0,0 +1,29 @@
# 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 ..object import Object
class ForumTopicClosed(Object):
"""A service message about a forum topic closed in the chat.
Currently holds no information.
"""
def __init__(self):
super().__init__()

View file

@ -0,0 +1,58 @@
# 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 pyrogram import raw
from ..object import Object
class ForumTopicCreated(Object):
"""A service message about a new forum topic created in the chat.
Parameters:
title (``String``):
Name of the topic.
icon_color (``Integer``):
Color of the topic icon in RGB format
icon_custom_emoji_id (``String``, *optional*):
Unique identifier of the custom emoji shown as the topic icon
"""
def __init__(
self, *,
title: str = None,
icon_color: int = None,
icon_custom_emoji_id: str = None
):
super().__init__()
self.title = title
self.icon_color = icon_color
self.icon_custom_emoji_id = icon_custom_emoji_id
@staticmethod
def _parse(action: "raw.types.MessageActionTopicCreate") -> "ForumTopicCreated":
return ForumTopicCreated(
title=getattr(action,"title", None),
icon_color=getattr(action,"icon_color", None),
icon_custom_emoji_id=getattr(action,"icon_custom_emoji_id", None)
)

View file

@ -0,0 +1,58 @@
# 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 pyrogram import raw
from ..object import Object
class ForumTopicEdited(Object):
"""A service message about a forum topic renamed in the chat.
Parameters:
title (``String``):
Name of the topic.
icon_color (``Integer``):
Color of the topic icon in RGB format
icon_custom_emoji_id (``String``, *optional*):
Unique identifier of the custom emoji shown as the topic icon
"""
def __init__(
self, *,
title: str = None,
icon_color: int = None,
icon_custom_emoji_id: str = None
):
super().__init__()
self.title = title
self.icon_color = icon_color
self.icon_custom_emoji_id = icon_custom_emoji_id
@staticmethod
def _parse(action: "raw.types.MessageActionTopicEdit") -> "ForumTopicEdited":
return ForumTopicEdited(
title=getattr(action,"title", None),
icon_color=getattr(action,"icon_color", None),
icon_custom_emoji_id=getattr(action,"icon_custom_emoji_id", None)
)

View file

@ -0,0 +1,29 @@
# 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 ..object import Object
class ForumTopicReopened(Object):
"""A service message about a forum topic reopened in the chat.
Currently holds no information.
"""
def __init__(self):
super().__init__()