Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
374563d
copy-paste Poolitzer's `test_forum.py`, move test from `test_bot.py`
lemontree210 Nov 11, 2022
b5211d8
refactor(`test_forum.py`): add fixture to create and delete topic
lemontree210 Nov 11, 2022
c24efa2
merge api_6.3_update
lemontree210 Nov 11, 2022
726b6ab
create classes `ForumTopic`, `ForumTopic...`, 1st test
lemontree210 Nov 11, 2022
7d77ae9
add tests for service message classes, fix `de_json()` in `ForumTopic…
lemontree210 Nov 12, 2022
5c0a2e8
minor: remove TODO after comment in review
lemontree210 Nov 12, 2022
deaacfb
add tests and `de_json()` for `ForumTopic`
lemontree210 Nov 12, 2022
b627a9c
fix(typos in `message.py`): `TopicForum` -> `ForumTopic`
lemontree210 Nov 13, 2022
5fe81c1
fix(`_forumtopic.py`): rm `de_json()`, replace `{}` with `None` in test
lemontree210 Nov 13, 2022
d40e8a0
fix(`telegram.rst`): reorder alphabetically
lemontree210 Nov 13, 2022
417bd26
fix(`message.py`): add "forum_topic_closed", "_reopened" to `de_json()`
lemontree210 Nov 13, 2022
e12a8ff
fix(class docstrings) `, optional):` -> `): Optional.` in attrs section
lemontree210 Nov 13, 2022
7328f43
refactor(`test_forum.py`) add/change fixtures
lemontree210 Nov 13, 2022
99095c4
fix(`ForumTopic`): make `__eq__` check all required args (+`icon_color`)
lemontree210 Nov 14, 2022
1be6f67
Merge remote-tracking branch 'origin/api_6.3_update' into new_classes…
lemontree210 Nov 14, 2022
0d3d1c0
Merge branch 'api_6.3_update' into new_classes_for_api_6.3
Bibo-Joshi Nov 15, 2022
46d24bc
re-add new classes to toctree
Bibo-Joshi Nov 15, 2022
f51caf3
Merge remote-tracking branch 'origin/api_6.3_update' into new_classes…
lemontree210 Nov 15, 2022
f958cbc
fix(`Bot.create_forum_topic`): return `ForumTopic`; change test fixture
lemontree210 Nov 16, 2022
759816f
fix(`Bot.create_forum_topic`): make 2 attrs optional, tweak docstring
lemontree210 Nov 16, 2022
d323c7f
fix existing test that was failing
lemontree210 Nov 16, 2022
1b52d1c
add tests for `Bot.create_forum_topic()`
lemontree210 Nov 16, 2022
011fcfa
rename fixture, replace dummy emoji ID with real one from fixture
lemontree210 Nov 17, 2022
61eca9a
remove failing test: service message can't be checked
lemontree210 Nov 17, 2022
748ca5f
remove 2 TODOs
lemontree210 Nov 17, 2022
ab33cb5
fix signature of `ExtBot.create_forum_topic()`
lemontree210 Nov 17, 2022
c180f8f
Merge remote-tracking branch 'origin/api_6.3_update' into new_classes…
lemontree210 Nov 17, 2022
27db94d
add test for `Bot.close_forum_topic()` and `.reopen_forum_topic()`
lemontree210 Nov 18, 2022
b137494
add (failing, commented) test for `Bot.unpin_all_forum_topic_messages`
lemontree210 Nov 18, 2022
3b12a8e
fix failing `unpin_all_forum_messages` test
harshil21 Nov 18, 2022
620c0c2
remove duplicate test from test_bot.py
harshil21 Nov 18, 2022
c2705e9
status update filters
Bibo-Joshi Nov 18, 2022
07a0967
Merge remote-tracking branch 'origin/new_classes_for_api_6.3' into ne…
Bibo-Joshi Nov 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/source/telegram.at-tree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Available Types
telegram.document
telegram.file
telegram.forcereply
telegram.forumtopic
telegram.forumtopicclosed
telegram.forumtopiccreated
telegram.forumtopicreopened
telegram.inlinekeyboardbutton
telegram.inlinekeyboardmarkup
telegram.inputfile
Expand Down
6 changes: 6 additions & 0 deletions docs/source/telegram.forumtopic.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
telegram.ForumTopic
===================

.. autoclass:: telegram.ForumTopic
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.forumtopicclosed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
telegram.ForumTopicClosed
=========================

.. autoclass:: telegram.ForumTopicClosed
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.forumtopiccreated.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
telegram.ForumTopicCreated
==========================

.. autoclass:: telegram.ForumTopicCreated
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.forumtopicreopened.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
telegram.ForumTopicReopened
===========================

.. autoclass:: telegram.ForumTopicReopened
:members:
:show-inheritance:
5 changes: 5 additions & 0 deletions telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"File",
"FileCredentials",
"ForceReply",
"ForumTopic",
"ForumTopicClosed",
"ForumTopicCreated",
"ForumTopicReopened",
"Game",
"GameHighScore",
"helpers",
Expand Down Expand Up @@ -230,6 +234,7 @@
from ._files.videonote import VideoNote
from ._files.voice import Voice
from ._forcereply import ForceReply
from ._forumtopic import ForumTopic, ForumTopicClosed, ForumTopicCreated, ForumTopicReopened
from ._games.callbackgame import CallbackGame
from ._games.game import Game
from ._games.gamehighscore import GameHighScore
Expand Down
21 changes: 11 additions & 10 deletions telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from telegram._files.video import Video
from telegram._files.videonote import VideoNote
from telegram._files.voice import Voice
from telegram._forumtopic import ForumTopic
from telegram._games.gamehighscore import GameHighScore
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._menubutton import MenuButton
Expand Down Expand Up @@ -6915,15 +6916,15 @@ async def create_forum_topic(
self,
chat_id: Union[str, int],
name: str,
icon_color: int,
icon_custom_emoji_id: str,
icon_color: int = None,
icon_custom_emoji_id: str = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
) -> ForumTopic:
"""
Use this method to create a topic in a forum supergroup chat. The bot must be
an administrator in the chat for this to work and must have
Expand All @@ -6938,19 +6939,19 @@ async def create_forum_topic(
name (:obj:`str`): New topic name,
:tg-const:`telegram.constants.TopicLimit.MIN_NAME_LENGTH`-
:tg-const:`telegram.constants.TopicLimit.MAX_NAME_LENGTH` characters.
icon_color (:obj:`int`): Color of the topic icon in RGB format. Currently,
icon_color (:obj:`int`, optional): Color of the topic icon in RGB format. Currently,
must be one of :attr:`telegram.constants.ForumIconColor.BLUE`,
:attr:`telegram.constants.ForumIconColor.YELLOW`,
:attr:`telegram.constants.ForumIconColor.PURPLE`,
:attr:`telegram.constants.ForumIconColor.GREEN`,
:attr:`telegram.constants.ForumIconColor.PINK`, or
:attr:`telegram.constants.ForumIconColor.RED`.
icon_custom_emoji_id (:obj:`str`): New unique identifier of the custom emoji shown as
the topic icon. Use :meth:`~telegram.Bot.get_forum_topic_icon_stickers` to get all
allowed custom emoji identifiers.
icon_custom_emoji_id (:obj:`str`, optional): New unique identifier of the custom emoji
shown as the topic icon. Use :meth:`~telegram.Bot.get_forum_topic_icon_stickers`
to get all allowed custom emoji identifiers.

Returns:
:obj:`bool`: On success, :class:`telegram.ForumTopic` is returned.
:class:`telegram.ForumTopic`

Raises:
:class:`telegram.error.TelegramError`
Expand All @@ -6961,8 +6962,7 @@ async def create_forum_topic(
"icon_color": icon_color,
"icon_custom_emoji_id": icon_custom_emoji_id,
}
# TODO: DO ForumTopic.de_json here!
return await self._post( # type: ignore[return-value]
result = await self._post(
"createForumTopic",
data,
read_timeout=read_timeout,
Expand All @@ -6971,6 +6971,7 @@ async def create_forum_topic(
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)
return ForumTopic.de_json(result, self) # type: ignore[return-value, arg-type]

@_log
async def edit_forum_topic(
Expand Down
4 changes: 2 additions & 2 deletions telegram/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2620,8 +2620,8 @@ async def set_menu_button(
async def create_forum_topic(
self,
name: str,
icon_color: int,
icon_custom_emoji_id: str,
icon_color: int = None,
icon_custom_emoji_id: str = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down
131 changes: 131 additions & 0 deletions telegram/_forumtopic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2022
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains objects related to Telegram forum topics."""

from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict


class ForumTopic(TelegramObject):
"""
This object represents the content of a service message about a new forum topic created in
the chat.

Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`message_thread_id`, :attr:`name` and :attr:`icon_color`
are equal.

.. versionadded:: 20.0

Args:
message_thread_id (:obj:`int`): Unique identifier of the forum topic
name (:obj:`str`): Name of the topic
icon_color (:obj:`int`): Color of the topic icon in RGB format
icon_custom_emoji_id (:obj:`str`, optional): Unique identifier of the custom emoji shown
as the topic icon.

Attributes:
message_thread_id (:obj:`int`): Unique identifier of the forum topic
name (:obj:`str`): Name of the topic
icon_color (:obj:`int`): Color of the topic icon in RGB format
icon_custom_emoji_id (:obj:`str`): Optional. Unique identifier of the custom emoji shown
as the topic icon.
"""

__slots__ = ("message_thread_id", "name", "icon_color", "icon_custom_emoji_id")

def __init__(
self,
message_thread_id: int,
name: str,
icon_color: int,
icon_custom_emoji_id: str = None,
*,
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.message_thread_id = message_thread_id
self.name = name
self.icon_color = icon_color
self.icon_custom_emoji_id = icon_custom_emoji_id

self._id_attrs = (self.message_thread_id, self.name, self.icon_color)


class ForumTopicCreated(TelegramObject):
"""
This object represents the content of a service message about a new forum topic created in
the chat.

Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`name` and :attr:`icon_color` are equal.

.. versionadded:: 20.0

Args:
name (:obj:`str`): Name of the topic
icon_color (:obj:`int`): Color of the topic icon in RGB format
icon_custom_emoji_id (:obj:`str`, optional): Unique identifier of the custom emoji shown
as the topic icon.

Attributes:
name (:obj:`str`): Name of the topic
icon_color (:obj:`int`): Color of the topic icon in RGB format
icon_custom_emoji_id (:obj:`str`): Optional. Unique identifier of the custom emoji shown
as the topic icon.
"""

__slots__ = ("name", "icon_color", "icon_custom_emoji_id")

def __init__(
self,
name: str,
icon_color: int,
icon_custom_emoji_id: str = None,
*,
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.name = name
self.icon_color = icon_color
self.icon_custom_emoji_id = icon_custom_emoji_id

self._id_attrs = (self.name, self.icon_color)


class ForumTopicClosed(TelegramObject):
"""
This object represents a service message about a forum topic closed in the chat.
Currently holds no information.

.. versionadded:: 20.0
"""

__slots__ = ()


class ForumTopicReopened(TelegramObject):
"""
This object represents a service message about a forum topic reopened in the chat.
Currently holds no information.

.. versionadded:: 20.0
"""

__slots__ = ()
45 changes: 43 additions & 2 deletions telegram/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from telegram._files.video import Video
from telegram._files.videonote import VideoNote
from telegram._files.voice import Voice
from telegram._forumtopic import ForumTopicClosed, ForumTopicCreated, ForumTopicReopened
from telegram._games.game import Game
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._messageautodeletetimerchanged import MessageAutoDeleteTimerChanged
Expand Down Expand Up @@ -254,6 +255,18 @@ class Message(TelegramObject):
message_thread_id (:obj:`int`, optional): Unique identifier of a message thread to which
the message belongs; for supergroups only.

.. versionadded:: 20.0
forum_topic_created (:class:`telegram.ForumTopicCreated`, optional): Service message:
forum topic created

.. versionadded:: 20.0
forum_topic_closed (:class:`telegram.ForumTopicClosed`, optional): Service message:
forum topic closed

.. versionadded:: 20.0
forum_topic_reopened (:class:`telegram.ForumTopicReopened`, optional): Service message:
forum topic reopened

.. versionadded:: 20.0

Attributes:
Expand Down Expand Up @@ -407,12 +420,24 @@ class Message(TelegramObject):
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message. :paramref:`~telegram.InlineKeyboardButton.login_url` buttons are
represented as ordinary url buttons.
is_topic_message (:obj:`bool`, optional): True, if the message is sent to a forum topic.
is_topic_message (:obj:`bool`): Optional. True, if the message is sent to a forum topic.

.. versionadded:: 20.0
message_thread_id (:obj:`int`, optional): Unique identifier of a message thread to which
message_thread_id (:obj:`int`): Optional. Unique identifier of a message thread to which
the message belongs; for supergroups only.

.. versionadded:: 20.0
forum_topic_created (:class:`telegram.ForumTopicCreated`): Optional. Service message:
forum topic created

.. versionadded:: 20.0
forum_topic_closed (:class:`telegram.ForumTopicClosed`): Optional. Service message:
forum topic closed

.. versionadded:: 20.0
forum_topic_reopened (:class:`telegram.ForumTopicReopened`): Optional. Service message:
forum topic reopened

.. versionadded:: 20.0

.. |custom_emoji_formatting_note| replace:: Custom emoji entities will currently be ignored
Expand Down Expand Up @@ -483,6 +508,9 @@ class Message(TelegramObject):
"web_app_data",
"is_topic_message",
"message_thread_id",
"forum_topic_created",
"forum_topic_closed",
"forum_topic_reopened",
)

def __init__(
Expand Down Expand Up @@ -548,6 +576,9 @@ def __init__(
web_app_data: WebAppData = None,
is_topic_message: bool = None,
message_thread_id: int = None,
forum_topic_created: ForumTopicCreated = None,
forum_topic_closed: ForumTopicClosed = None,
forum_topic_reopened: ForumTopicReopened = None,
*,
api_kwargs: JSONDict = None,
):
Expand Down Expand Up @@ -616,6 +647,9 @@ def __init__(
self.web_app_data = web_app_data
self.is_topic_message = is_topic_message
self.message_thread_id = message_thread_id
self.forum_topic_created = forum_topic_created
self.forum_topic_closed = forum_topic_closed
self.forum_topic_reopened = forum_topic_reopened

self._effective_attachment = DEFAULT_NONE

Expand Down Expand Up @@ -706,6 +740,13 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["Message"]:
data.get("video_chat_participants_invited"), bot
)
data["web_app_data"] = WebAppData.de_json(data.get("web_app_data"), bot)
data["forum_topic_closed"] = ForumTopicClosed.de_json(data.get("forum_topic_closed"), bot)
data["forum_topic_created"] = ForumTopicCreated.de_json(
data.get("forum_topic_created"), bot
)
data["forum_topic_reopened"] = ForumTopicReopened.de_json(
data.get("forum_topic_reopened"), bot
)

return super().de_json(data=data, bot=bot)

Expand Down
7 changes: 4 additions & 3 deletions telegram/ext/_extbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
Contact,
Document,
File,
ForumTopic,
GameHighScore,
InlineKeyboardMarkup,
InputMedia,
Expand Down Expand Up @@ -1849,16 +1850,16 @@ async def create_forum_topic(
self,
chat_id: Union[str, int],
name: str,
icon_color: int,
icon_custom_emoji_id: str,
icon_color: int = None,
icon_custom_emoji_id: str = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
rate_limit_args: RLARGS = None,
) -> bool:
) -> ForumTopic:
return await super().create_forum_topic(
chat_id=chat_id,
name=name,
Expand Down
Loading