From 876d679765812f8f315bd64dbbe299c361c747e7 Mon Sep 17 00:00:00 2001 From: coder2020official Date: Sun, 6 Nov 2022 15:14:19 +0400 Subject: [PATCH] Added ForumTopic class and fixed previous classes by fixing de_json method. --- telebot/types.py | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/telebot/types.py b/telebot/types.py index 96154d6..98fae8d 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -6779,10 +6779,11 @@ class ForumTopicCreated(JsonDeserializable): :return: Instance of the class :rtype: :class:`telebot.types.ForumTopicCreated` """ - def de_json(self, json_string): + @classmethod + def de_json(cls, json_string): if json_string is None: return None - obj = self.check_json(json_string) - return self(**obj) + obj = cls.check_json(json_string) + return cls(**obj) def __init__(self, name: str, icon_color: int, icon_custom_emoji_id: Optional[str]=None) -> None: self.name: str = name @@ -6793,8 +6794,9 @@ class ForumTopicCreated(JsonDeserializable): class ForumTopicClosed(JsonDeserializable): """This object represents a service message about a forum topic closed in the chat. Currently holds no information.""" # for future use - def de_json(self, json_string): - return self() + @classmethod + def de_json(cls, json_string): + return cls() def __init__(self) -> None: pass @@ -6803,13 +6805,45 @@ class ForumTopicClosed(JsonDeserializable): class ForumTopicReopened(JsonDeserializable): """This object represents a service message about a forum topic reopened in the chat. Currently holds no information.""" # for future use - def de_json(self, json_string): - return self() + @classmethod + def de_json(cls, json_string): + return cls() def __init__(self) -> None: pass +class ForumTopic(JsonDeserializable): + """ + This object represents a forum topic. + + :param message_thread_id: Unique identifier of the forum topic + :type message_thread_id: :obj:`int` + + :param name: Name of the topic + :type name: :obj:`str` + + :param icon_color: Color of the topic icon in RGB format + :type icon_color: :obj:`int` + + :param icon_custom_emoji_id: Optional. Unique identifier of the custom emoji shown as the topic icon + :type icon_custom_emoji_id: :obj:`str` + """ + + @classmethod + def de_json(cls, json_string): + if json_string is None: return None + obj = cls.check_json(json_string) + return cls(**obj) + + def __init__(self, message_thread_id: int, name: str, icon_color: int, icon_custom_emoji_id: Optional[str]=None) -> None: + self.message_thread_id: int = message_thread_id + self.name: str = name + self.icon_color: int = icon_color + self.icon_custom_emoji_id: Optional[str] = icon_custom_emoji_id + + +