From 97865c70d4fc06c648feef91038f9dfae914b7fe Mon Sep 17 00:00:00 2001 From: Poolitzer <25934244+Poolitzer@users.noreply.github.com> Date: Sun, 6 Nov 2022 13:08:38 +0100 Subject: [PATCH 01/17] Feat: Add get_topic_stickers method --- telegram/_bot.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++ tests/test_bot.py | 22 ++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/telegram/_bot.py b/telegram/_bot.py index f526101164c..a268f514397 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -8270,6 +8270,55 @@ async def create_invoice_link( api_kwargs=api_kwargs, ) + @_log + async def get_forum_topic_icon_stickers( + self, + *, + 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, + ) -> List[Sticker]: + """Use this method to get custom emoji stickers, which can be used as a forum topic + icon by any user. Requires no parameters. + + + .. versionadded:: 20.0 + + Keyword Args: + read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the + Telegram API. + + Returns: + List[:class:`telegram.Sticker`] + + Raises: + :class:`telegram.error.TelegramError` + + """ + result = await self._post( + "getForumTopicIconStickers", + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + return Sticker.de_list(result, self) # type: ignore[return-value, arg-type] + def to_dict(self, recursive: bool = True) -> JSONDict: # skipcq: PYL-W0613 """See :meth:`telegram.TelegramObject.to_dict`.""" data: JSONDict = {"id": self.id, "username": self.username, "first_name": self.first_name} @@ -8462,3 +8511,5 @@ def __hash__(self) -> int: """Alias for :meth:`set_my_default_administrator_rights`""" createInvoiceLink = create_invoice_link """Alias for :meth:`create_invoice_link`""" + getForumTopicIconStickers = get_forum_topic_icon_stickers + """Alias for :meth:`get_forum_topic_icon_stickers`""" diff --git a/tests/test_bot.py b/tests/test_bot.py index 0189763799a..71dbdfdc8ce 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -60,6 +60,7 @@ PollOption, SentWebAppMessage, ShippingOption, + Sticker, Update, User, WebAppInfo, @@ -2778,6 +2779,27 @@ async def test_copy_message_with_default(self, default_bot, chat_id, media_messa else: assert len(message.caption_entities) == 0 + async def test_get_forum_topic_icon_stickers(self, bot): + # we expect the first to stay as it is. This might change in the future. + # If we have to fix this test too often maybe just checking it is set to "something" + # is enough. + emoji_sticker_list = await bot.get_forum_topic_icon_stickers() + print(emoji_sticker_list[0].emoji) + assert emoji_sticker_list[0].emoji == "📰" + assert emoji_sticker_list[0].height == 512 + assert emoji_sticker_list[0].width == 512 + assert emoji_sticker_list[0].is_animated + assert not emoji_sticker_list[0].is_video + assert emoji_sticker_list[0].set_name == "Topics" + assert emoji_sticker_list[0].type == Sticker.CUSTOM_EMOJI + assert emoji_sticker_list[0].custom_emoji_id == "5420143492263320958" + assert emoji_sticker_list[0].thumb.width == 128 + assert emoji_sticker_list[0].thumb.height == 128 + assert emoji_sticker_list[0].thumb.file_size == 4036 + assert emoji_sticker_list[0].thumb.file_unique_id == "AQADfh0AAso3OEty" + assert emoji_sticker_list[0].file_size == 57126 + assert emoji_sticker_list[0].file_unique_id == "AgADfh0AAso3OEs" + async def test_replace_callback_data_send_message(self, cdc_bot, chat_id): bot = cdc_bot From 984af105a85f54365d6383dd2619ac46f53ec327 Mon Sep 17 00:00:00 2001 From: Poolitzer <25934244+Poolitzer@users.noreply.github.com> Date: Sun, 6 Nov 2022 14:14:31 +0100 Subject: [PATCH 02/17] Fix: Add edit_topic method --- docs/source/inclusions/bot_methods.rst | 19 +++++++ telegram/_bot.py | 71 ++++++++++++++++++++++++++ telegram/constants.py | 15 ++++++ tests/test_bot.py | 25 ++------- tests/test_forum.py | 59 +++++++++++++++++++++ 5 files changed, 167 insertions(+), 22 deletions(-) create mode 100644 tests/test_forum.py diff --git a/docs/source/inclusions/bot_methods.rst b/docs/source/inclusions/bot_methods.rst index 605194f3f18..3a6941b4df3 100644 --- a/docs/source/inclusions/bot_methods.rst +++ b/docs/source/inclusions/bot_methods.rst @@ -256,6 +256,25 @@
+.. raw:: html + +
+ Forum topic management + +.. list-table:: + :align: left + :widths: 1 4 + + * - :meth:`~telegram.Bot.get_forum_topic_icon_stickers` + - Used to get custom emojis to use as topic icons + * - :meth:`~telegram.Bot.edit_forum_topic` + - Used to edit a topic + +.. raw:: html + +
+
+ .. raw:: html
diff --git a/telegram/_bot.py b/telegram/_bot.py index a268f514397..48b0f1754f9 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -8319,6 +8319,77 @@ async def get_forum_topic_icon_stickers( ) return Sticker.de_list(result, self) # type: ignore[return-value, arg-type] + @_log + async def edit_forum_topic( + self, + chat_id: Union[str, int], + message_thread_id: int, + name: str, + icon_custom_emoji_id: str, + *, + 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: + """ + Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must + be an administrator in the chat for this to work and must have + :paramref:`~telegram.ChatAdministratorRights.can_manage_topics` administrator rights, + unless it is the creator of the topic. + + Args: + chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username + of the target channel (in the format ``@channelusername``). + message_thread_id (:obj:`int`): Unique identifier for the target message thread of + the forum topic. + name (:obj:`str`): New topic name, + tg-const:`telegram.constants.TopicLimit.MIN_TITLE_LENGTH`- + tg-const:`telegram.constants.TopicLimit.MAX_TITLE_LENGTH` characters. + 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. + + Keyword Args: + read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the + Telegram API. + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + + Raises: + :class:`telegram.error.TelegramError` + + """ + data: JSONDict = { + "chat_id": chat_id, + "message_thread_id": message_thread_id, + "name": name, + "icon_custom_emoji_id": icon_custom_emoji_id, + } + return await self._post( # type: ignore[return-value] + "editForumTopic", + data, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + def to_dict(self, recursive: bool = True) -> JSONDict: # skipcq: PYL-W0613 """See :meth:`telegram.TelegramObject.to_dict`.""" data: JSONDict = {"id": self.id, "username": self.username, "first_name": self.first_name} diff --git a/telegram/constants.py b/telegram/constants.py index f5cd7b838f2..0f7ee900f1b 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -901,3 +901,18 @@ class WebhookLimit(IntEnum): """:obj:`int`: Minimum length of the secret token.""" MAX_SECRET_TOKEN_LENGTH = 256 """:obj:`int`: Maximum length of the secret token.""" + + +class TopicLimit(IntEnum): + """This enum contains limitations for :paramref:`telegram.Bot.edit_forum_topic.name`. The + enum members of this enumeration are instances of :class:`int` and can be treated as such. + + .. versionadded:: 20.0 + """ + + __slots__ = () + + MIN_NAME_LENGTH = 1 + """:obj:`int`: Minimum length of the topic name.""" + MAX_NAME_LENGTH = 128 + """:obj:`int`: Maximum length of the topic name.""" diff --git a/tests/test_bot.py b/tests/test_bot.py index 71dbdfdc8ce..a83fdcde935 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -60,7 +60,6 @@ PollOption, SentWebAppMessage, ShippingOption, - Sticker, Update, User, WebAppInfo, @@ -2436,6 +2435,9 @@ async def test_pin_and_unpin_message(self, bot, super_group_id): # set_sticker_position_in_set, delete_sticker_from_set and get_custom_emoji_stickers # are tested in the test_sticker module. + # get_forum_topic_icon_stickers, edit_forum_topic, etc... + # are tested in the test_forum module. + async def test_timeout_propagation_explicit(self, monkeypatch, bot, chat_id): # Use BaseException that's not a subclass of Exception such that # OkException should not be caught anywhere @@ -2779,27 +2781,6 @@ async def test_copy_message_with_default(self, default_bot, chat_id, media_messa else: assert len(message.caption_entities) == 0 - async def test_get_forum_topic_icon_stickers(self, bot): - # we expect the first to stay as it is. This might change in the future. - # If we have to fix this test too often maybe just checking it is set to "something" - # is enough. - emoji_sticker_list = await bot.get_forum_topic_icon_stickers() - print(emoji_sticker_list[0].emoji) - assert emoji_sticker_list[0].emoji == "📰" - assert emoji_sticker_list[0].height == 512 - assert emoji_sticker_list[0].width == 512 - assert emoji_sticker_list[0].is_animated - assert not emoji_sticker_list[0].is_video - assert emoji_sticker_list[0].set_name == "Topics" - assert emoji_sticker_list[0].type == Sticker.CUSTOM_EMOJI - assert emoji_sticker_list[0].custom_emoji_id == "5420143492263320958" - assert emoji_sticker_list[0].thumb.width == 128 - assert emoji_sticker_list[0].thumb.height == 128 - assert emoji_sticker_list[0].thumb.file_size == 4036 - assert emoji_sticker_list[0].thumb.file_unique_id == "AQADfh0AAso3OEty" - assert emoji_sticker_list[0].file_size == 57126 - assert emoji_sticker_list[0].file_unique_id == "AgADfh0AAso3OEs" - async def test_replace_callback_data_send_message(self, cdc_bot, chat_id): bot = cdc_bot diff --git a/tests/test_forum.py b/tests/test_forum.py new file mode 100644 index 00000000000..b961dc44496 --- /dev/null +++ b/tests/test_forum.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# +# A library that provides a Python interface to the Telegram Bot API +# Copyright (C) 2015-2022 +# Leandro Toledo de Souza +# +# 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/]. +from telegram import Sticker + + +class TestForum: + async def test_get_forum_topic_icon_stickers(self, bot): + # we expect the first to stay as it is. This might change in the future. + # If we have to fix this test too often maybe just checking it is set to "something" + # is enough. + emoji_sticker_list = await bot.get_forum_topic_icon_stickers() + print(emoji_sticker_list[0].emoji) + assert emoji_sticker_list[0].emoji == "📰" + assert emoji_sticker_list[0].height == 512 + assert emoji_sticker_list[0].width == 512 + assert emoji_sticker_list[0].is_animated + assert not emoji_sticker_list[0].is_video + assert emoji_sticker_list[0].set_name == "Topics" + assert emoji_sticker_list[0].type == Sticker.CUSTOM_EMOJI + assert emoji_sticker_list[0].custom_emoji_id == "5420143492263320958" + assert emoji_sticker_list[0].thumb.width == 128 + assert emoji_sticker_list[0].thumb.height == 128 + assert emoji_sticker_list[0].thumb.file_size == 4036 + assert emoji_sticker_list[0].thumb.file_unique_id == "AQADfh0AAso3OEty" + assert emoji_sticker_list[0].file_size == 57126 + assert emoji_sticker_list[0].file_unique_id == "AgADfh0AAso3OEs" + + # we sadly do not have access to a test group right now so we only test params right now + async def test_edit_forum_topic_all_params(self, monkeypatch, bot, chat_id): + async def make_assertion(_, data, *args, **kwargs): + assert data["chat_id"] == chat_id + assert data["message_thread_id"] == 1234 + assert data["name"] == "name" + assert data["icon_custom_emoji_id"] == "icon_custom_emoji_id" + + monkeypatch.setattr(bot, "_post", make_assertion) + await bot.edit_forum_topic( + chat_id, + 1234, + "name", + "icon_custom_emoji_id", + ) + monkeypatch.delattr(bot, "_post") From be85bc7e4ae482facae033910eecd8cb3bd64b00 Mon Sep 17 00:00:00 2001 From: poolitzer <25934244+Poolitzer@users.noreply.github.com> Date: Mon, 7 Nov 2022 10:38:31 +0100 Subject: [PATCH 03/17] Fix: add TopicLimit to the all variable --- telegram/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/telegram/constants.py b/telegram/constants.py index 0f7ee900f1b..8256ea6538b 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -62,6 +62,7 @@ "PollType", "SUPPORTED_WEBHOOK_PORTS", "StickerType", + "TopicLimit", "WebhookLimit", "UpdateType", ] From fb15e87e23429893527621aaa4e0c66cc9592690 Mon Sep 17 00:00:00 2001 From: poolitzer <25934244+Poolitzer@users.noreply.github.com> Date: Mon, 7 Nov 2022 22:00:05 +0100 Subject: [PATCH 04/17] Fix: black. --- tests/test_chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_chat.py b/tests/test_chat.py index 8422148c0fb..4f2305180b8 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -106,7 +106,7 @@ def test_de_json(self, bot): ), "is_forum": self.is_forum, "active_usernames": self.active_usernames, - "emoji_status_custom_emoji_id": self.emoji_status_custom_emoji_id + "emoji_status_custom_emoji_id": self.emoji_status_custom_emoji_id, } chat = Chat.de_json(json_dict, bot) From 3501e87fa38553d73b55e250ef846a538aebfee6 Mon Sep 17 00:00:00 2001 From: poolitzer <25934244+Poolitzer@users.noreply.github.com> Date: Mon, 7 Nov 2022 22:01:17 +0100 Subject: [PATCH 05/17] Revert "Fix: black." This reverts commit fb15e87e23429893527621aaa4e0c66cc9592690. --- tests/test_chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_chat.py b/tests/test_chat.py index 4f2305180b8..8422148c0fb 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -106,7 +106,7 @@ def test_de_json(self, bot): ), "is_forum": self.is_forum, "active_usernames": self.active_usernames, - "emoji_status_custom_emoji_id": self.emoji_status_custom_emoji_id, + "emoji_status_custom_emoji_id": self.emoji_status_custom_emoji_id } chat = Chat.de_json(json_dict, bot) From d4dc454083b5a45fa6b984e959aec0b4e32f7e3a Mon Sep 17 00:00:00 2001 From: poolitzer <25934244+Poolitzer@users.noreply.github.com> Date: Fri, 11 Nov 2022 11:50:23 +0100 Subject: [PATCH 06/17] Feat: Add shortcuts to edit function Also doing black a solid here --- telegram/_bot.py | 3 +++ telegram/_chat.py | 36 ++++++++++++++++++++++++++++++++++++ telegram/_message.py | 38 ++++++++++++++++++++++++++++++++++++++ telegram/constants.py | 1 - 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/telegram/_bot.py b/telegram/_bot.py index b8b7ba27262..e7693f0bf64 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -8462,6 +8462,9 @@ async def edit_forum_topic( :paramref:`~telegram.ChatAdministratorRights.can_manage_topics` administrator rights, unless it is the creator of the topic. + .. seealso:: :meth:`telegram.Message.set_chat_menu_button`, + :meth:`telegram.Chat.edit_forum_topic`, + Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username of the target channel (in the format ``@channelusername``). diff --git a/telegram/_chat.py b/telegram/_chat.py index ea27ad74462..a67a10573f0 100644 --- a/telegram/_chat.py +++ b/telegram/_chat.py @@ -2607,6 +2607,42 @@ async def set_menu_button( api_kwargs=api_kwargs, ) + async def edit_forum_topic( + self, + message_thread_id: int, + name: str, + icon_custom_emoji_id: str, + *, + 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: + """Shortcut for:: + + await bot.edit_forum_topic(chat_id=update.effective_chat.id, *args, **kwargs) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.edit_forum_topic`. + + .. versionadded:: 20.0 + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + """ + return await self.get_bot().edit_forum_topic( + chat_id=self.id, + message_thread_id=message_thread_id, + name=name, + icon_custom_emoji_id=icon_custom_emoji_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + async def get_menu_button( self, *, diff --git a/telegram/_message.py b/telegram/_message.py index cbbbfc3b581..24b8a031b7f 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -2703,6 +2703,44 @@ async def unpin( api_kwargs=api_kwargs, ) + async def edit_forum_topic( + self, + name: str, + icon_custom_emoji_id: str, + *, + 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: + """Shortcut for:: + + await bot.edit_forum_topic( + chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args, + **kwargs + ) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.edit_forum_topic`. + + .. versionadded:: 20.0 + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + """ + return await self.get_bot().edit_forum_topic( + chat_id=self.chat_id, + message_thread_id=self.message_thread_id, + name=name, + icon_custom_emoji_id=icon_custom_emoji_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + def parse_entity(self, entity: MessageEntity) -> str: """Returns the text from a given :class:`telegram.MessageEntity`. diff --git a/telegram/constants.py b/telegram/constants.py index 9f4f870e2c4..d86e2b49d66 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -933,4 +933,3 @@ class TopicLimit(IntEnum): """:obj:`int`: Minimum length of the topic name.""" MAX_NAME_LENGTH = 128 """:obj:`int`: Maximum length of the topic name.""" - From 12391026ff9c2903b50b5c2d39141e0d89fd30f6 Mon Sep 17 00:00:00 2001 From: poolitzer <25934244+Poolitzer@users.noreply.github.com> Date: Fri, 11 Nov 2022 12:02:38 +0100 Subject: [PATCH 07/17] Feat: Add shortcut tests --- tests/test_chat.py | 14 ++++++++++++++ tests/test_message.py | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/test_chat.py b/tests/test_chat.py index 4f2305180b8..e9e5d88e654 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -896,6 +896,20 @@ async def make_assertion(*_, **kwargs): monkeypatch.setattr(chat.get_bot(), "decline_chat_join_request", make_assertion) assert await chat.decline_join_request(user_id=42) + async def test_edit_forum_topic(self, monkeypatch, chat): + async def make_assertion(*_, **kwargs): + return ( + kwargs["chat_id"] == chat.id + and kwargs["message_thread_id"] == 42 + and kwargs["name"] == "New Name" + and kwargs["icon_custom_emoji_id"] == "12345" + ) + + monkeypatch.setattr(chat.get_bot(), "edit_forum_topic", make_assertion) + assert await chat.edit_forum_topic( + message_thread_id=42, name="New Name", icon_custom_emoji_id="12345" + ) + def test_mention_html(self): with pytest.raises(TypeError, match="Can not create a mention to a private group chat"): chat = Chat(id=1, type="foo") diff --git a/tests/test_message.py b/tests/test_message.py index c9aca3572fb..eca21b61f3d 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -66,6 +66,7 @@ def message(bot): date=TestMessage.date, chat=TestMessage.chat, from_user=TestMessage.from_user, + message_thread_id=42, ) message.set_bot(bot) return message @@ -1685,6 +1686,18 @@ def test_default_quote(self, message): finally: message.get_bot()._defaults = None + async def test_edit_forum_topic(self, monkeypatch, message): + async def make_assertion(*_, **kwargs): + return ( + kwargs["chat_id"] == message.chat_id + and kwargs["message_thread_id"] == message.message_thread_id + and kwargs["name"] == "New Name" + and kwargs["icon_custom_emoji_id"] == "12345" + ) + + monkeypatch.setattr(message.get_bot(), "edit_forum_topic", make_assertion) + assert await message.edit_forum_topic(name="New Name", icon_custom_emoji_id="12345") + def test_equality(self): id_ = 1 a = Message( From a4be521fb896e7fe402edc04788c98cd25406e64 Mon Sep 17 00:00:00 2001 From: Aditya Yadav Date: Sat, 12 Nov 2022 22:23:04 +0530 Subject: [PATCH 08/17] adding remaining new methods --- telegram/_bot.py | 342 +++++++++++++++++++++++++++++++++++++++++- telegram/_chat.py | 165 ++++++++++++++++++++ telegram/_message.py | 175 +++++++++++++++++++++ tests/test_chat.py | 42 ++++++ tests/test_message.py | 54 +++++++ 5 files changed, 777 insertions(+), 1 deletion(-) diff --git a/telegram/_bot.py b/telegram/_bot.py index e7693f0bf64..f744d63e569 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -8442,6 +8442,78 @@ async def get_forum_topic_icon_stickers( ) return Sticker.de_list(result, self) # type: ignore[return-value, arg-type] + @_log + async def create_forum_topic( + self, + chat_id: Union[str, int], + name: str, + icon_color: int, + icon_custom_emoji_id: str, + *, + 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: + """ + 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 + :paramref:`~telegram.ChatAdministratorRights.can_manage_topics` administrator rights. + + .. seealso:: :meth:`telegram.Message.create_forum_topic`, + :meth:`telegram.Chat.create_forum_topic`, + + Args: + chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username + of the target channel (in the format ``@channelusername``). + name (:obj:`str`): New topic name, + tg-const:`telegram.constants.TopicLimit.MIN_TITLE_LENGTH`- + tg-const:`telegram.constants.TopicLimit.MAX_TITLE_LENGTH` characters. + icon_color (:obj:`int`): Color of the topic icon in RGB format. Currently, + must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F. + 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. + + Keyword Args: + read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the + Telegram API. + + Returns: + :obj:`bool`: On success, :class:`telegram.ForumTopic` is returned. + + Raises: + :class:`telegram.error.TelegramError` + """ + data: JSONDict = { + "chat_id": chat_id, + "name": name, + "icon_color": icon_color, + "icon_custom_emoji_id": icon_custom_emoji_id, + } + return await self._post( # type: ignore[return-value] + "createForumTopic", + data, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + @_log async def edit_forum_topic( self, @@ -8462,7 +8534,7 @@ async def edit_forum_topic( :paramref:`~telegram.ChatAdministratorRights.can_manage_topics` administrator rights, unless it is the creator of the topic. - .. seealso:: :meth:`telegram.Message.set_chat_menu_button`, + .. seealso:: :meth:`telegram.Message.edit_forum_topic`, :meth:`telegram.Chat.edit_forum_topic`, Args: @@ -8516,6 +8588,262 @@ async def edit_forum_topic( api_kwargs=api_kwargs, ) + @_log + async def close_forum_topic( + self, + chat_id: Union[str, int], + message_thread_id: int, + *, + 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: + """ + Use this method to close an open topic in a forum supergroup chat. The bot must + be an administrator in the chat for this to work and must have + :paramref:`~telegram.ChatAdministratorRights.can_manage_topics` administrator rights, + unless it is the creator of the topic. + + .. seealso:: :meth:`telegram.Message.close_forum_topic`, + :meth:`telegram.Chat.close_forum_topic`, + + Args: + chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username + of the target channel (in the format ``@channelusername``). + message_thread_id (:obj:`int`): Unique identifier for the target message thread of + the forum topic. + + Keyword Args: + read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the + Telegram API. + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + + Raises: + :class:`telegram.error.TelegramError` + + """ + data: JSONDict = { + "chat_id": chat_id, + "message_thread_id": message_thread_id, + } + return await self._post( # type: ignore[return-value] + "closeForumTopic", + data, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + + @_log + async def reopen_forum_topic( + self, + chat_id: Union[str, int], + message_thread_id: int, + *, + 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: + """ + Use this method to reopen a closed topic in a forum supergroup chat. The bot must + be an administrator in the chat for this to work and must have + :paramref:`~telegram.ChatAdministratorRights.can_manage_topics` administrator rights, + unless it is the creator of the topic. + + .. seealso:: :meth:`telegram.Message.reopen_forum_topic`, + :meth:`telegram.Chat.reopen_forum_topic`, + + Args: + chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username + of the target channel (in the format ``@channelusername``). + message_thread_id (:obj:`int`): Unique identifier for the target message thread of + the forum topic. + + Keyword Args: + read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the + Telegram API. + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + + Raises: + :class:`telegram.error.TelegramError` + + """ + data: JSONDict = { + "chat_id": chat_id, + "message_thread_id": message_thread_id, + } + return await self._post( # type: ignore[return-value] + "reopenForumTopic", + data, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + + @_log + async def delete_forum_topic( + self, + chat_id: Union[str, int], + message_thread_id: int, + *, + 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: + """ + Use this method to delete a forum topic along with all its messages in a forum supergroup + chat. The bot must be an administrator in the chat for this to work and must have + :paramref:`~telegram.ChatAdministratorRights.can_delete_messages` administrator rights, + unless it is the creator of the topic. + + .. seealso:: :meth:`telegram.Message.delete_forum_topic`, + :meth:`telegram.Chat.delete_forum_topic`, + + Args: + chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username + of the target channel (in the format ``@channelusername``). + message_thread_id (:obj:`int`): Unique identifier for the target message thread of + the forum topic. + + Keyword Args: + read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the + Telegram API. + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + + Raises: + :class:`telegram.error.TelegramError` + + """ + data: JSONDict = { + "chat_id": chat_id, + "message_thread_id": message_thread_id, + } + return await self._post( # type: ignore[return-value] + "deleteForumTopic", + data, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + + @_log + async def unpin_all_forum_topic_messages( + self, + chat_id: Union[str, int], + message_thread_id: int, + *, + 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: + """ + Use this method to clear the list of pinned messages in a forum topic. The bot must + be an administrator in the chat for this to work and must have + :paramref:`~telegram.ChatAdministratorRights.can_pin_messages` administrator rights + in the supergroup, unless it is the creator of the topic. + + .. seealso:: :meth:`telegram.Message.unpin_all_forum_topic_messages`, + :meth:`telegram.Chat.unpin_all_forum_topic_messages`, + + Args: + chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username + of the target channel (in the format ``@channelusername``). + message_thread_id (:obj:`int`): Unique identifier for the target message thread of + the forum topic. + + Keyword Args: + read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to + :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to + :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. + api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the + Telegram API. + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + + Raises: + :class:`telegram.error.TelegramError` + + """ + data: JSONDict = { + "chat_id": chat_id, + "message_thread_id": message_thread_id, + } + return await self._post( # type: ignore[return-value] + "unpinAllForumTopicMessages", + data, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + def to_dict(self, recursive: bool = True) -> JSONDict: # skipcq: PYL-W0613 """See :meth:`telegram.TelegramObject.to_dict`.""" data: JSONDict = {"id": self.id, "username": self.username, "first_name": self.first_name} @@ -8710,3 +9038,15 @@ def __hash__(self) -> int: """Alias for :meth:`create_invoice_link`""" getForumTopicIconStickers = get_forum_topic_icon_stickers """Alias for :meth:`get_forum_topic_icon_stickers`""" + createForumTopic = create_forum_topic + """Alias for :meth:`create_forum_topic`""" + editForumTopic = edit_forum_topic + """Alias for :meth:`edit_forum_topic`""" + closeForumTopic = close_forum_topic + """Alias for :meth:`close_forum_topic`""" + reopenForumTopic = reopen_forum_topic + """Alias for :meth:`reopen_forum_topic`""" + deleteForumTopic = delete_forum_topic + """Alias for :meth:`delete_forum_topic`""" + unpinAllForumTopicMessages = unpin_all_forum_topic_messages + """Alias for :meth:`unpin_all_forum_topic_messages`""" diff --git a/telegram/_chat.py b/telegram/_chat.py index a67a10573f0..1302f76c172 100644 --- a/telegram/_chat.py +++ b/telegram/_chat.py @@ -2607,6 +2607,42 @@ async def set_menu_button( api_kwargs=api_kwargs, ) + async def create_forum_topic( + self, + name: str, + icon_color: int, + icon_custom_emoji_id: str, + *, + 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: + """Shortcut for:: + + await bot.create_forum_topic(chat_id=update.effective_chat.id, *args, **kwargs) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.create_forum_topic`. + + .. versionadded:: 20.0 + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + """ + return await self.get_bot().create_forum_topic( + chat_id=self.id, + name=name, + icon_color=icon_color, + icon_custom_emoji_id=icon_custom_emoji_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + async def edit_forum_topic( self, message_thread_id: int, @@ -2643,6 +2679,135 @@ async def edit_forum_topic( api_kwargs=api_kwargs, ) + async def close_forum_topic( + self, + message_thread_id: int, + *, + 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: + """Shortcut for:: + + await bot.close_forum_topic(chat_id=update.effective_chat.id, *args, **kwargs) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.close_forum_topic`. + + .. versionadded:: 20.0 + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + """ + return await self.get_bot().edit_forum_topic( + chat_id=self.id, + message_thread_id=message_thread_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + + async def reopen_forum_topic( + self, + message_thread_id: int, + *, + 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: + """Shortcut for:: + + await bot.reopen_forum_topic(chat_id=update.effective_chat.id, *args, **kwargs) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.reopen_forum_topic`. + + .. versionadded:: 20.0 + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + """ + return await self.get_bot().edit_forum_topic( + chat_id=self.id, + message_thread_id=message_thread_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + + async def delete_forum_topic( + self, + message_thread_id: int, + *, + 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: + """Shortcut for:: + + await bot.delete_forum_topic(chat_id=update.effective_chat.id, *args, **kwargs) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.delete_forum_topic`. + + .. versionadded:: 20.0 + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + """ + return await self.get_bot().delete_forum_topic( + chat_id=self.id, + message_thread_id=message_thread_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + + async def unpin_all_forum_topic_messages( + self, + message_thread_id: int, + *, + 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: + """Shortcut for:: + + await bot.unpin_all_forum_topic_messages(chat_id=update.effective_chat.id, + *args, **kwargs) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.unpin_all_forum_topic_messages`. + + .. versionadded:: 20.0 + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + """ + return await self.get_bot().edit_forum_topic( + chat_id=self.id, + message_thread_id=message_thread_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + async def get_menu_button( self, *, diff --git a/telegram/_message.py b/telegram/_message.py index 24b8a031b7f..f1cb7afb2ba 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -2703,6 +2703,45 @@ async def unpin( api_kwargs=api_kwargs, ) + async def create_forum_topic( + self, + name: str, + icon_color: int, + icon_custom_emoji_id: str, + *, + 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: + """Shortcut for:: + + await bot.create_forum_topic( + chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args, + **kwargs + ) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.create_forum_topic`. + + .. versionadded:: 20.0 + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + """ + return await self.get_bot().create_forum_topic( + chat_id=self.chat_id, + name=name, + icon_color=icon_color, + icon_custom_emoji_id=icon_custom_emoji_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + async def edit_forum_topic( self, name: str, @@ -2741,6 +2780,142 @@ async def edit_forum_topic( api_kwargs=api_kwargs, ) + async def close_forum_topic( + self, + *, + 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: + """Shortcut for:: + + await bot.close_forum_topic( + chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args, + **kwargs + ) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.close_forum_topic`. + + .. versionadded:: 20.0 + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + """ + return await self.get_bot().close_forum_topic( + chat_id=self.chat_id, + message_thread_id=self.message_thread_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + + async def reopen_forum_topic( + self, + *, + 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: + """Shortcut for:: + + await bot.edit_forum_topic( + chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args, + **kwargs + ) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.reopen_forum_topic`. + + .. versionadded:: 20.0 + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + """ + return await self.get_bot().reopen_forum_topic( + chat_id=self.chat_id, + message_thread_id=self.message_thread_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + + async def delete_forum_topic( + self, + *, + 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: + """Shortcut for:: + + await bot.delete_forum_topic( + chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args, + **kwargs + ) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.delete_forum_topic`. + + .. versionadded:: 20.0 + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + """ + return await self.get_bot().edit_forum_topic( + chat_id=self.chat_id, + message_thread_id=self.message_thread_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + + async def unpin_all_forum_topic_message( + self, + *, + 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: + """Shortcut for:: + + await bot.unpin_all_forum_topic_messages( + chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args, + **kwargs + ) + + For the documentation of the arguments, please see + :meth:`telegram.Bot.unpin_all_forum_topic_messages`. + + .. versionadded:: 20.0 + + Returns: + :obj:`bool`: On success, :obj:`True` is returned. + """ + return await self.get_bot().unpin_all_forum_topic_messages( + chat_id=self.chat_id, + message_thread_id=self.message_thread_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ) + def parse_entity(self, entity: MessageEntity) -> str: """Returns the text from a given :class:`telegram.MessageEntity`. diff --git a/tests/test_chat.py b/tests/test_chat.py index e9e5d88e654..03b9ed94180 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -896,6 +896,20 @@ async def make_assertion(*_, **kwargs): monkeypatch.setattr(chat.get_bot(), "decline_chat_join_request", make_assertion) assert await chat.decline_join_request(user_id=42) + async def test_create_forum_topic(self, monkeypatch, chat): + async def make_assertion(*_, **kwargs): + return ( + kwargs["chat_id"] == chat.id + and kwargs["name"] == "New Name" + and kwargs["icon_color"] == 0x6FB9F0 + and kwargs["icon_custom_emoji_id"] == "12345" + ) + + monkeypatch.setattr(chat.get_bot(), "create_forum_topic", make_assertion) + assert await chat.create_forum_topic( + name="New Name", icon_color=0x6FB9F0, icon_custom_emoji_id="12345" + ) + async def test_edit_forum_topic(self, monkeypatch, chat): async def make_assertion(*_, **kwargs): return ( @@ -910,6 +924,34 @@ async def make_assertion(*_, **kwargs): message_thread_id=42, name="New Name", icon_custom_emoji_id="12345" ) + async def test_close_forum_topic(self, monkeypatch, chat): + async def make_assertion(*_, **kwargs): + return kwargs["chat_id"] == chat.id and kwargs["message_thread_id"] == 42 + + monkeypatch.setattr(chat.get_bot(), "close_forum_topic", make_assertion) + assert await chat.close_forum_topic(message_thread_id=42) + + async def test_reopen_close_forum_topic(self, monkeypatch, chat): + async def make_assertion(*_, **kwargs): + return kwargs["chat_id"] == chat.id and kwargs["message_thread_id"] == 42 + + monkeypatch.setattr(chat.get_bot(), "reopen_forum_topic", make_assertion) + assert await chat.reopen_forum_topic(message_thread_id=42) + + async def test_delete_forum_topic(self, monkeypatch, chat): + async def make_assertion(*_, **kwargs): + return kwargs["chat_id"] == chat.id and kwargs["message_thread_id"] == 42 + + monkeypatch.setattr(chat.get_bot(), "delete_forum_topic", make_assertion) + assert await chat.delete_forum_topic(message_thread_id=42) + + async def test_unpin_all_forum_topic_messages(self, monkeypatch, chat): + async def make_assertion(*_, **kwargs): + return kwargs["chat_id"] == chat.id and kwargs["message_thread_id"] == 42 + + monkeypatch.setattr(chat.get_bot(), "unpin_all_forum_topic_messages", make_assertion) + assert await chat.unpin_all_forum_topic_messages(message_thread_id=42) + def test_mention_html(self): with pytest.raises(TypeError, match="Can not create a mention to a private group chat"): chat = Chat(id=1, type="foo") diff --git a/tests/test_message.py b/tests/test_message.py index eca21b61f3d..6ad2cfb29a9 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -1686,6 +1686,20 @@ def test_default_quote(self, message): finally: message.get_bot()._defaults = None + async def test_create_forum_topic(self, monkeypatch, message): + async def make_assertion(*_, **kwargs): + return ( + kwargs["chat_id"] == message.chat_id + and kwargs["name"] == "New Name" + and kwargs["icon_color"] == 0x6FB9F0 + and kwargs["icon_custom_emoji_id"] == "12345" + ) + + monkeypatch.setattr(message.get_bot(), "create_forum_topic", make_assertion) + assert await message.create_forum_topic( + name="New Name", icon_color=0x6FB9F0, icon_custom_emoji_id="12345" + ) + async def test_edit_forum_topic(self, monkeypatch, message): async def make_assertion(*_, **kwargs): return ( @@ -1698,6 +1712,46 @@ async def make_assertion(*_, **kwargs): monkeypatch.setattr(message.get_bot(), "edit_forum_topic", make_assertion) assert await message.edit_forum_topic(name="New Name", icon_custom_emoji_id="12345") + async def test_close_forum_topic(self, monkeypatch, message): + async def make_assertion(*_, **kwargs): + return ( + kwargs["chat_id"] == message.chat_id + and kwargs["message_thread_id"] == message.message_thread_id + ) + + monkeypatch.setattr(message.get_bot(), "close_forum_topic", make_assertion) + assert await message.close_forum_topic() + + async def test_reopen_forum_topic(self, monkeypatch, message): + async def make_assertion(*_, **kwargs): + return ( + kwargs["chat_id"] == message.chat_id + and kwargs["message_thread_id"] == message.message_thread_id + ) + + monkeypatch.setattr(message.get_bot(), "reopen_forum_topic", make_assertion) + assert await message.reopen_forum_topic() + + async def test_delete_forum_topic(self, monkeypatch, message): + async def make_assertion(*_, **kwargs): + return ( + kwargs["chat_id"] == message.chat_id + and kwargs["message_thread_id"] == message.message_thread_id + ) + + monkeypatch.setattr(message.get_bot(), "delete_forum_topic", make_assertion) + assert await message.delete_forum_topic() + + async def test_unpin_all_forum_topic_messages(self, monkeypatch, message): + async def make_assertion(*_, **kwargs): + return ( + kwargs["chat_id"] == message.chat_id + and kwargs["message_thread_id"] == message.message_thread_id + ) + + monkeypatch.setattr(message.get_bot(), "unpin_all_forum_topic_messages", make_assertion) + assert await message.unpin_all_forum_topic_messages() + def test_equality(self): id_ = 1 a = Message( From d9a09b8922f9ae9d9c01f87163b0d448f9db46a3 Mon Sep 17 00:00:00 2001 From: Aditya Yadav Date: Sat, 12 Nov 2022 22:31:33 +0530 Subject: [PATCH 09/17] fix some wrong calls in shortcuts --- telegram/_chat.py | 6 +++--- telegram/_message.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/telegram/_chat.py b/telegram/_chat.py index 1302f76c172..57220c73859 100644 --- a/telegram/_chat.py +++ b/telegram/_chat.py @@ -2701,7 +2701,7 @@ async def close_forum_topic( Returns: :obj:`bool`: On success, :obj:`True` is returned. """ - return await self.get_bot().edit_forum_topic( + return await self.get_bot().close_forum_topic( chat_id=self.id, message_thread_id=message_thread_id, read_timeout=read_timeout, @@ -2733,7 +2733,7 @@ async def reopen_forum_topic( Returns: :obj:`bool`: On success, :obj:`True` is returned. """ - return await self.get_bot().edit_forum_topic( + return await self.get_bot().reopen_forum_topic( chat_id=self.id, message_thread_id=message_thread_id, read_timeout=read_timeout, @@ -2798,7 +2798,7 @@ async def unpin_all_forum_topic_messages( Returns: :obj:`bool`: On success, :obj:`True` is returned. """ - return await self.get_bot().edit_forum_topic( + return await self.get_bot().unpin_all_forum_topic_messages( chat_id=self.id, message_thread_id=message_thread_id, read_timeout=read_timeout, diff --git a/telegram/_message.py b/telegram/_message.py index f1cb7afb2ba..3d6d64dad16 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -2872,7 +2872,7 @@ async def delete_forum_topic( Returns: :obj:`bool`: On success, :obj:`True` is returned. """ - return await self.get_bot().edit_forum_topic( + return await self.get_bot().delete_forum_topic( chat_id=self.chat_id, message_thread_id=self.message_thread_id, read_timeout=read_timeout, From 777e045eeeacb750e2e3a28f097e9cdeca297bba Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Sun, 13 Nov 2022 02:02:09 +0530 Subject: [PATCH 10/17] update bot_methods.rst to include new forum methods --- docs/source/inclusions/bot_methods.rst | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/source/inclusions/bot_methods.rst b/docs/source/inclusions/bot_methods.rst index 3a6941b4df3..0177b7d9703 100644 --- a/docs/source/inclusions/bot_methods.rst +++ b/docs/source/inclusions/bot_methods.rst @@ -265,10 +265,20 @@ :align: left :widths: 1 4 - * - :meth:`~telegram.Bot.get_forum_topic_icon_stickers` - - Used to get custom emojis to use as topic icons + * - :meth:`~telegram.Bot.close_forum_topic` + - Used for closing a forum topic + * - :meth:`~telegram.Bot.create_forum_topic` + - Used to create a topic + * - :meth:`~telegram.Bot.delete_forum_topic` + - Used for deleting a forum topic * - :meth:`~telegram.Bot.edit_forum_topic` - Used to edit a topic + * - :meth:`~telegram.Bot.reopen_forum_topic` + - Used to reopen a topic + * - :meth:`~telegram.Bot.get_forum_topic_icon_stickers` + - Used to get custom emojis to use as topic icons + * - :meth:`~telegram.Bot.unpin_all_forum_topic_messages` + - Used to unpin all messages in a forum topic .. raw:: html From bd1bdca1c1ffc0eef3dec209483a8521b6104d6d Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Sun, 13 Nov 2022 02:03:52 +0530 Subject: [PATCH 11/17] update extbot with new forum methods --- telegram/ext/_extbot.py | 165 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) diff --git a/telegram/ext/_extbot.py b/telegram/ext/_extbot.py index 6a68f5a9971..8a0357e882e 100644 --- a/telegram/ext/_extbot.py +++ b/telegram/ext/_extbot.py @@ -1100,6 +1100,28 @@ async def delete_chat_sticker_set( api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), ) + async def delete_forum_topic( + self, + chat_id: Union[str, int], + message_thread_id: int, + *, + 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: + return await super().delete_forum_topic( + chat_id=chat_id, + message_thread_id=message_thread_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), + ) + async def delete_message( self, chat_id: Union[str, int], @@ -1214,6 +1236,32 @@ async def edit_chat_invite_link( api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), ) + async def edit_forum_topic( + self, + chat_id: Union[str, int], + message_thread_id: int, + name: str, + icon_custom_emoji_id: str, + *, + 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: + return await super().edit_forum_topic( + chat_id=chat_id, + message_thread_id=message_thread_id, + name=name, + icon_custom_emoji_id=icon_custom_emoji_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), + ) + async def edit_message_caption( self, chat_id: Union[str, int] = None, @@ -1526,6 +1574,24 @@ async def get_file( api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), ) + async def get_forum_topic_icon_stickers( + self, + *, + 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, + ) -> List[Sticker]: + return await super().get_forum_topic_icon_stickers( + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), + ) + async def get_game_high_scores( self, user_id: Union[int, str], @@ -1750,6 +1816,54 @@ async def close( api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), ) + async def close_forum_topic( + self, + chat_id: Union[str, int], + message_thread_id: int, + *, + 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: + return await super().close_forum_topic( + chat_id=chat_id, + message_thread_id=message_thread_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), + ) + + async def create_forum_topic( + self, + chat_id: Union[str, int], + name: str, + icon_color: int, + icon_custom_emoji_id: str, + *, + 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: + return await super().create_forum_topic( + chat_id=chat_id, + name=name, + icon_color=icon_color, + icon_custom_emoji_id=icon_custom_emoji_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), + ) + async def pin_chat_message( self, chat_id: Union[str, int], @@ -1818,6 +1932,28 @@ async def promote_chat_member( api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), ) + async def reopen_forum_topic( + self, + chat_id: Union[str, int], + message_thread_id: int, + *, + 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: + return await super().reopen_forum_topic( + chat_id=chat_id, + message_thread_id=message_thread_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), + ) + async def restrict_chat_member( self, chat_id: Union[str, int], @@ -3112,6 +3248,28 @@ async def unpin_chat_message( api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), ) + async def unpin_all_forum_topic_messages( + self, + chat_id: Union[str, int], + message_thread_id: int, + *, + 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: + return await super().unpin_all_forum_topic_messages( + chat_id=chat_id, + message_thread_id=message_thread_id, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), + ) + async def upload_sticker_file( self, user_id: Union[str, int], @@ -3223,3 +3381,10 @@ async def upload_sticker_file( getMyDefaultAdministratorRights = get_my_default_administrator_rights setMyDefaultAdministratorRights = set_my_default_administrator_rights createInvoiceLink = create_invoice_link + getForumTopicIconStickers = get_forum_topic_icon_stickers + createForumTopic = create_forum_topic + editForumTopic = edit_forum_topic + closeForumTopic = close_forum_topic + reopenForumTopic = reopen_forum_topic + deleteForumTopic = delete_forum_topic + unpinAllForumTopicMessages = unpin_all_forum_topic_messages From 0069be71c81e9cf237fd358c885c52ccfcfc0beb Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Sun, 13 Nov 2022 02:05:52 +0530 Subject: [PATCH 12/17] review: fix method name in message.py --- telegram/_message.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telegram/_message.py b/telegram/_message.py index 3d6d64dad16..dea162d9948 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -2825,7 +2825,7 @@ async def reopen_forum_topic( ) -> bool: """Shortcut for:: - await bot.edit_forum_topic( + await bot.reopen_forum_topic( chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args, **kwargs ) @@ -2882,7 +2882,7 @@ async def delete_forum_topic( api_kwargs=api_kwargs, ) - async def unpin_all_forum_topic_message( + async def unpin_all_forum_topic_messages( self, *, read_timeout: ODVInput[float] = DEFAULT_NONE, From bfb8316d9a7753ed84fa6201d1411ef08b367a87 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Sun, 13 Nov 2022 02:07:02 +0530 Subject: [PATCH 13/17] review + feat: fix docstring in bot.py and add new constant class new constant class also renders the topic colors as a box --- telegram/_bot.py | 32 +++++++++++++---------- telegram/constants.py | 61 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 14 deletions(-) diff --git a/telegram/_bot.py b/telegram/_bot.py index f744d63e569..d04f90cf570 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -8406,7 +8406,6 @@ async def get_forum_topic_icon_stickers( """Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. Requires no parameters. - .. versionadded:: 20.0 Keyword Args: @@ -8466,14 +8465,19 @@ async def create_forum_topic( Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username - of the target channel (in the format ``@channelusername``). + of the target channel (in the format ``@supergroupusername``). name (:obj:`str`): New topic name, - tg-const:`telegram.constants.TopicLimit.MIN_TITLE_LENGTH`- - tg-const:`telegram.constants.TopicLimit.MAX_TITLE_LENGTH` characters. + :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, - must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F. + 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 + the topic icon. Use :meth:`~telegram.Bot.get_forum_topic_icon_stickers` to get all allowed custom emoji identifiers. Keyword Args: @@ -8539,14 +8543,14 @@ async def edit_forum_topic( Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username - of the target channel (in the format ``@channelusername``). + of the target channel (in the format ``@supergroupusername``). message_thread_id (:obj:`int`): Unique identifier for the target message thread of the forum topic. name (:obj:`str`): New topic name, - tg-const:`telegram.constants.TopicLimit.MIN_TITLE_LENGTH`- - tg-const:`telegram.constants.TopicLimit.MAX_TITLE_LENGTH` characters. + :tg-const:`telegram.constants.TopicLimit.MIN_NAME_LENGTH`- + :tg-const:`telegram.constants.TopicLimit.MAX_NAME_LENGTH` characters. 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 + the topic icon. Use :meth:`~telegram.Bot.get_forum_topic_icon_stickers` to get all allowed custom emoji identifiers. Keyword Args: @@ -8611,7 +8615,7 @@ async def close_forum_topic( Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username - of the target channel (in the format ``@channelusername``). + of the target channel (in the format ``@supergroupusername``). message_thread_id (:obj:`int`): Unique identifier for the target message thread of the forum topic. @@ -8675,7 +8679,7 @@ async def reopen_forum_topic( Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username - of the target channel (in the format ``@channelusername``). + of the target channel (in the format ``@supergroupusername``). message_thread_id (:obj:`int`): Unique identifier for the target message thread of the forum topic. @@ -8739,7 +8743,7 @@ async def delete_forum_topic( Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username - of the target channel (in the format ``@channelusername``). + of the target channel (in the format ``@supergroupusername``). message_thread_id (:obj:`int`): Unique identifier for the target message thread of the forum topic. @@ -8803,7 +8807,7 @@ async def unpin_all_forum_topic_messages( Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username - of the target channel (in the format ``@channelusername``). + of the target channel (in the format ``@supergroupusername``). message_thread_id (:obj:`int`): Unique identifier for the target message thread of the forum topic. diff --git a/telegram/constants.py b/telegram/constants.py index d86e2b49d66..0cd8a621053 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -46,6 +46,7 @@ "DiceEmoji", "FileSizeLimit", "FloodLimit", + "ForumIconColor", "InlineKeyboardMarkupLimit", "InlineQueryLimit", "InlineQueryResultType", @@ -372,6 +373,66 @@ class FloodLimit(IntEnum): """ +class ForumIconColor(IntEnum): + """This enum contains the available colors for use in + :meth:`~telegram.Bot.create_forum_topic`. The enum members of this enumeration are instances of + :class:`int` and can be treated as such. + + .. versionadded:: 20.0 + """ + + __slots__ = () + + BLUE = 0x6FB9F0 + """:obj:`int`: An icon with a color which corresponds to blue. + + .. raw:: html + +
+ + """ + YELLOW = 0xFFD67E + """:obj:`int`: An icon with a color which corresponds to yellow. + + .. raw:: html + +
+ + """ + PURPLE = 0xCB86DB + """:obj:`int`: An icon with a color which corresponds to purple. + + .. raw:: html + +
+ + """ + GREEN = 0x8EEE98 + """:obj:`int`: An icon with a color which corresponds to green. + + .. raw:: html + +
+ + """ + PINK = 0xFF93B2 + """:obj:`int`: An icon with a color which corresponds to pink. + + .. raw:: html + +
+ + """ + RED = 0xFB6F5F + """:obj:`int`: An icon with a color which corresponds to red. + + .. raw:: html + +
+ + """ + + class InlineKeyboardMarkupLimit(IntEnum): """This enum contains limitations for :class:`telegram.InlineKeyboardMarkup`/ :meth:`telegram.Bot.send_message` & friends. The enum From 184b4bdd7f442c93f7c71ffaf32663834832c220 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Sun, 13 Nov 2022 02:10:49 +0530 Subject: [PATCH 14/17] remove test_forum.py as its a subset of test_forum in branch new_classes_for_api_6.3 --- tests/test_forum.py | 59 --------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 tests/test_forum.py diff --git a/tests/test_forum.py b/tests/test_forum.py deleted file mode 100644 index b961dc44496..00000000000 --- a/tests/test_forum.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python -# -# A library that provides a Python interface to the Telegram Bot API -# Copyright (C) 2015-2022 -# Leandro Toledo de Souza -# -# 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/]. -from telegram import Sticker - - -class TestForum: - async def test_get_forum_topic_icon_stickers(self, bot): - # we expect the first to stay as it is. This might change in the future. - # If we have to fix this test too often maybe just checking it is set to "something" - # is enough. - emoji_sticker_list = await bot.get_forum_topic_icon_stickers() - print(emoji_sticker_list[0].emoji) - assert emoji_sticker_list[0].emoji == "📰" - assert emoji_sticker_list[0].height == 512 - assert emoji_sticker_list[0].width == 512 - assert emoji_sticker_list[0].is_animated - assert not emoji_sticker_list[0].is_video - assert emoji_sticker_list[0].set_name == "Topics" - assert emoji_sticker_list[0].type == Sticker.CUSTOM_EMOJI - assert emoji_sticker_list[0].custom_emoji_id == "5420143492263320958" - assert emoji_sticker_list[0].thumb.width == 128 - assert emoji_sticker_list[0].thumb.height == 128 - assert emoji_sticker_list[0].thumb.file_size == 4036 - assert emoji_sticker_list[0].thumb.file_unique_id == "AQADfh0AAso3OEty" - assert emoji_sticker_list[0].file_size == 57126 - assert emoji_sticker_list[0].file_unique_id == "AgADfh0AAso3OEs" - - # we sadly do not have access to a test group right now so we only test params right now - async def test_edit_forum_topic_all_params(self, monkeypatch, bot, chat_id): - async def make_assertion(_, data, *args, **kwargs): - assert data["chat_id"] == chat_id - assert data["message_thread_id"] == 1234 - assert data["name"] == "name" - assert data["icon_custom_emoji_id"] == "icon_custom_emoji_id" - - monkeypatch.setattr(bot, "_post", make_assertion) - await bot.edit_forum_topic( - chat_id, - 1234, - "name", - "icon_custom_emoji_id", - ) - monkeypatch.delattr(bot, "_post") From 237a2bd4e94c4e8829a011284d8aa53d1baf4a8b Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Sun, 13 Nov 2022 02:50:02 +0530 Subject: [PATCH 15/17] 2 more doc fixes --- telegram/_message.py | 5 +---- telegram/constants.py | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/telegram/_message.py b/telegram/_message.py index dea162d9948..6130b40718b 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -2717,10 +2717,7 @@ async def create_forum_topic( ) -> bool: """Shortcut for:: - await bot.create_forum_topic( - chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args, - **kwargs - ) + await bot.create_forum_topic(chat_id=message.chat_id, *args, **kwargs) For the documentation of the arguments, please see :meth:`telegram.Bot.create_forum_topic`. diff --git a/telegram/constants.py b/telegram/constants.py index 0cd8a621053..1a5bb3e9405 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -375,8 +375,8 @@ class FloodLimit(IntEnum): class ForumIconColor(IntEnum): """This enum contains the available colors for use in - :meth:`~telegram.Bot.create_forum_topic`. The enum members of this enumeration are instances of - :class:`int` and can be treated as such. + :paramref:`telegram.Bot.create_forum_topic.icon_color`. The enum members of this enumeration + are instances of :class:`int` and can be treated as such. .. versionadded:: 20.0 """ From b80e150e5e9443b499810244ae5b191097ef25f8 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Tue, 15 Nov 2022 04:54:27 +0530 Subject: [PATCH 16/17] review: improve tests and remove create_topic from message --- telegram/_bot.py | 13 +++++++ telegram/_message.py | 36 ------------------- tests/test_chat.py | 68 ++++++++++++++++++++++++++++++++++- tests/test_message.py | 83 +++++++++++++++++++++++++++++++++++-------- 4 files changed, 148 insertions(+), 52 deletions(-) diff --git a/telegram/_bot.py b/telegram/_bot.py index e44037edab0..76104211e2d 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -8470,6 +8470,8 @@ async def create_forum_topic( .. seealso:: :meth:`telegram.Message.create_forum_topic`, :meth:`telegram.Chat.create_forum_topic`, + .. versionadded:: 20.0 + Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username of the target channel (in the format ``@supergroupusername``). @@ -8515,6 +8517,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] "createForumTopic", data, @@ -8548,6 +8551,8 @@ async def edit_forum_topic( .. seealso:: :meth:`telegram.Message.edit_forum_topic`, :meth:`telegram.Chat.edit_forum_topic`, + .. versionadded:: 20.0 + Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username of the target channel (in the format ``@supergroupusername``). @@ -8620,6 +8625,8 @@ async def close_forum_topic( .. seealso:: :meth:`telegram.Message.close_forum_topic`, :meth:`telegram.Chat.close_forum_topic`, + .. versionadded:: 20.0 + Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username of the target channel (in the format ``@supergroupusername``). @@ -8684,6 +8691,8 @@ async def reopen_forum_topic( .. seealso:: :meth:`telegram.Message.reopen_forum_topic`, :meth:`telegram.Chat.reopen_forum_topic`, + .. versionadded:: 20.0 + Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username of the target channel (in the format ``@supergroupusername``). @@ -8748,6 +8757,8 @@ async def delete_forum_topic( .. seealso:: :meth:`telegram.Message.delete_forum_topic`, :meth:`telegram.Chat.delete_forum_topic`, + .. versionadded:: 20.0 + Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username of the target channel (in the format ``@supergroupusername``). @@ -8812,6 +8823,8 @@ async def unpin_all_forum_topic_messages( .. seealso:: :meth:`telegram.Message.unpin_all_forum_topic_messages`, :meth:`telegram.Chat.unpin_all_forum_topic_messages`, + .. versionadded:: 20.0 + Args: chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username of the target channel (in the format ``@supergroupusername``). diff --git a/telegram/_message.py b/telegram/_message.py index 6130b40718b..c5da24c44a1 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -2703,42 +2703,6 @@ async def unpin( api_kwargs=api_kwargs, ) - async def create_forum_topic( - self, - name: str, - icon_color: int, - icon_custom_emoji_id: str, - *, - 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: - """Shortcut for:: - - await bot.create_forum_topic(chat_id=message.chat_id, *args, **kwargs) - - For the documentation of the arguments, please see - :meth:`telegram.Bot.create_forum_topic`. - - .. versionadded:: 20.0 - - Returns: - :obj:`bool`: On success, :obj:`True` is returned. - """ - return await self.get_bot().create_forum_topic( - chat_id=self.chat_id, - name=name, - icon_color=icon_color, - icon_custom_emoji_id=icon_custom_emoji_id, - read_timeout=read_timeout, - write_timeout=write_timeout, - connect_timeout=connect_timeout, - pool_timeout=pool_timeout, - api_kwargs=api_kwargs, - ) - async def edit_forum_topic( self, name: str, diff --git a/tests/test_chat.py b/tests/test_chat.py index 03b9ed94180..e8871deeedd 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -905,6 +905,17 @@ async def make_assertion(*_, **kwargs): and kwargs["icon_custom_emoji_id"] == "12345" ) + assert check_shortcut_signature( + Chat.create_forum_topic, Bot.create_forum_topic, ["chat_id"], [] + ) + assert await check_shortcut_call( + chat.create_forum_topic, + chat.get_bot(), + "create_forum_topic", + shortcut_kwargs=["chat_id"], + ) + assert await check_defaults_handling(chat.create_forum_topic, chat.get_bot()) + monkeypatch.setattr(chat.get_bot(), "create_forum_topic", make_assertion) assert await chat.create_forum_topic( name="New Name", icon_color=0x6FB9F0, icon_custom_emoji_id="12345" @@ -919,6 +930,14 @@ async def make_assertion(*_, **kwargs): and kwargs["icon_custom_emoji_id"] == "12345" ) + assert check_shortcut_signature( + Chat.edit_forum_topic, Bot.edit_forum_topic, ["chat_id"], [] + ) + assert await check_shortcut_call( + chat.edit_forum_topic, chat.get_bot(), "edit_forum_topic", shortcut_kwargs=["chat_id"] + ) + assert await check_defaults_handling(chat.edit_forum_topic, chat.get_bot()) + monkeypatch.setattr(chat.get_bot(), "edit_forum_topic", make_assertion) assert await chat.edit_forum_topic( message_thread_id=42, name="New Name", icon_custom_emoji_id="12345" @@ -928,13 +947,35 @@ async def test_close_forum_topic(self, monkeypatch, chat): async def make_assertion(*_, **kwargs): return kwargs["chat_id"] == chat.id and kwargs["message_thread_id"] == 42 + assert check_shortcut_signature( + Chat.close_forum_topic, Bot.close_forum_topic, ["chat_id"], [] + ) + assert await check_shortcut_call( + chat.close_forum_topic, + chat.get_bot(), + "close_forum_topic", + shortcut_kwargs=["chat_id"], + ) + assert await check_defaults_handling(chat.close_forum_topic, chat.get_bot()) + monkeypatch.setattr(chat.get_bot(), "close_forum_topic", make_assertion) assert await chat.close_forum_topic(message_thread_id=42) - async def test_reopen_close_forum_topic(self, monkeypatch, chat): + async def test_reopen_forum_topic(self, monkeypatch, chat): async def make_assertion(*_, **kwargs): return kwargs["chat_id"] == chat.id and kwargs["message_thread_id"] == 42 + assert check_shortcut_signature( + Chat.reopen_forum_topic, Bot.reopen_forum_topic, ["chat_id"], [] + ) + assert await check_shortcut_call( + chat.reopen_forum_topic, + chat.get_bot(), + "reopen_forum_topic", + shortcut_kwargs=["chat_id"], + ) + assert await check_defaults_handling(chat.reopen_forum_topic, chat.get_bot()) + monkeypatch.setattr(chat.get_bot(), "reopen_forum_topic", make_assertion) assert await chat.reopen_forum_topic(message_thread_id=42) @@ -942,6 +983,17 @@ async def test_delete_forum_topic(self, monkeypatch, chat): async def make_assertion(*_, **kwargs): return kwargs["chat_id"] == chat.id and kwargs["message_thread_id"] == 42 + assert check_shortcut_signature( + Chat.delete_forum_topic, Bot.delete_forum_topic, ["chat_id"], [] + ) + assert await check_shortcut_call( + chat.delete_forum_topic, + chat.get_bot(), + "delete_forum_topic", + shortcut_kwargs=["chat_id"], + ) + assert await check_defaults_handling(chat.delete_forum_topic, chat.get_bot()) + monkeypatch.setattr(chat.get_bot(), "delete_forum_topic", make_assertion) assert await chat.delete_forum_topic(message_thread_id=42) @@ -949,6 +1001,20 @@ async def test_unpin_all_forum_topic_messages(self, monkeypatch, chat): async def make_assertion(*_, **kwargs): return kwargs["chat_id"] == chat.id and kwargs["message_thread_id"] == 42 + assert check_shortcut_signature( + Chat.unpin_all_forum_topic_messages, + Bot.unpin_all_forum_topic_messages, + ["chat_id"], + [], + ) + assert await check_shortcut_call( + chat.unpin_all_forum_topic_messages, + chat.get_bot(), + "unpin_all_forum_topic_messages", + shortcut_kwargs=["chat_id"], + ) + assert await check_defaults_handling(chat.unpin_all_forum_topic_messages, chat.get_bot()) + monkeypatch.setattr(chat.get_bot(), "unpin_all_forum_topic_messages", make_assertion) assert await chat.unpin_all_forum_topic_messages(message_thread_id=42) diff --git a/tests/test_message.py b/tests/test_message.py index 6ad2cfb29a9..034217d3ba2 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -66,7 +66,6 @@ def message(bot): date=TestMessage.date, chat=TestMessage.chat, from_user=TestMessage.from_user, - message_thread_id=42, ) message.set_bot(bot) return message @@ -191,6 +190,7 @@ def message(bot): ] }, {"web_app_data": WebAppData("some_data", "some_button_text")}, + {"message_thread_id": 123}, ], ids=[ "forwarded_user", @@ -244,6 +244,7 @@ def message(bot): "has_protected_content", "entities", "web_app_data", + "message_thread_id", ], ) def message_params(bot, request): @@ -1686,20 +1687,6 @@ def test_default_quote(self, message): finally: message.get_bot()._defaults = None - async def test_create_forum_topic(self, monkeypatch, message): - async def make_assertion(*_, **kwargs): - return ( - kwargs["chat_id"] == message.chat_id - and kwargs["name"] == "New Name" - and kwargs["icon_color"] == 0x6FB9F0 - and kwargs["icon_custom_emoji_id"] == "12345" - ) - - monkeypatch.setattr(message.get_bot(), "create_forum_topic", make_assertion) - assert await message.create_forum_topic( - name="New Name", icon_color=0x6FB9F0, icon_custom_emoji_id="12345" - ) - async def test_edit_forum_topic(self, monkeypatch, message): async def make_assertion(*_, **kwargs): return ( @@ -1709,6 +1696,17 @@ async def make_assertion(*_, **kwargs): and kwargs["icon_custom_emoji_id"] == "12345" ) + assert check_shortcut_signature( + Message.edit_forum_topic, Bot.edit_forum_topic, ["chat_id", "message_thread_id"], [] + ) + assert await check_shortcut_call( + message.edit_forum_topic, + message.get_bot(), + "edit_forum_topic", + shortcut_kwargs=["chat_id", "message_thread_id"], + ) + assert await check_defaults_handling(message.edit_forum_topic, message.get_bot()) + monkeypatch.setattr(message.get_bot(), "edit_forum_topic", make_assertion) assert await message.edit_forum_topic(name="New Name", icon_custom_emoji_id="12345") @@ -1719,6 +1717,17 @@ async def make_assertion(*_, **kwargs): and kwargs["message_thread_id"] == message.message_thread_id ) + assert check_shortcut_signature( + Message.close_forum_topic, Bot.close_forum_topic, ["chat_id", "message_thread_id"], [] + ) + assert await check_shortcut_call( + message.close_forum_topic, + message.get_bot(), + "close_forum_topic", + shortcut_kwargs=["chat_id", "message_thread_id"], + ) + assert await check_defaults_handling(message.close_forum_topic, message.get_bot()) + monkeypatch.setattr(message.get_bot(), "close_forum_topic", make_assertion) assert await message.close_forum_topic() @@ -1729,6 +1738,20 @@ async def make_assertion(*_, **kwargs): and kwargs["message_thread_id"] == message.message_thread_id ) + assert check_shortcut_signature( + Message.reopen_forum_topic, + Bot.reopen_forum_topic, + ["chat_id", "message_thread_id"], + [], + ) + assert await check_shortcut_call( + message.reopen_forum_topic, + message.get_bot(), + "reopen_forum_topic", + shortcut_kwargs=["chat_id", "message_thread_id"], + ) + assert await check_defaults_handling(message.reopen_forum_topic, message.get_bot()) + monkeypatch.setattr(message.get_bot(), "reopen_forum_topic", make_assertion) assert await message.reopen_forum_topic() @@ -1739,6 +1762,20 @@ async def make_assertion(*_, **kwargs): and kwargs["message_thread_id"] == message.message_thread_id ) + assert check_shortcut_signature( + Message.delete_forum_topic, + Bot.delete_forum_topic, + ["chat_id", "message_thread_id"], + [], + ) + assert await check_shortcut_call( + message.delete_forum_topic, + message.get_bot(), + "delete_forum_topic", + shortcut_kwargs=["chat_id", "message_thread_id"], + ) + assert await check_defaults_handling(message.delete_forum_topic, message.get_bot()) + monkeypatch.setattr(message.get_bot(), "delete_forum_topic", make_assertion) assert await message.delete_forum_topic() @@ -1749,6 +1786,22 @@ async def make_assertion(*_, **kwargs): and kwargs["message_thread_id"] == message.message_thread_id ) + assert check_shortcut_signature( + Message.unpin_all_forum_topic_messages, + Bot.unpin_all_forum_topic_messages, + ["chat_id", "message_thread_id"], + [], + ) + assert await check_shortcut_call( + message.unpin_all_forum_topic_messages, + message.get_bot(), + "unpin_all_forum_topic_messages", + shortcut_kwargs=["chat_id", "message_thread_id"], + ) + assert await check_defaults_handling( + message.unpin_all_forum_topic_messages, message.get_bot() + ) + monkeypatch.setattr(message.get_bot(), "unpin_all_forum_topic_messages", make_assertion) assert await message.unpin_all_forum_topic_messages() From b5a99c1642d13fe87304a614d8f7c038562a441a Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Tue, 15 Nov 2022 17:55:27 +0530 Subject: [PATCH 17/17] review: remove Keyword args section in new methods --- docs/substitutions/global.rst | 2 + telegram/_bot.py | 145 +++------------------------------- 2 files changed, 13 insertions(+), 134 deletions(-) diff --git a/docs/substitutions/global.rst b/docs/substitutions/global.rst index 46067cbc8a9..b06bb09db41 100644 --- a/docs/substitutions/global.rst +++ b/docs/substitutions/global.rst @@ -26,6 +26,8 @@ .. |chat_id_group| replace:: Unique identifier for the target chat or username of the target supergroup (in the format ``@supergroupusername``). +.. |message_thread_id| replace:: Unique identifier for the target message thread of the forum topic. + .. |parse_mode| replace:: Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. See the constants in :class:`telegram.constants.ParseMode` for the available modes. .. |allow_sending_without_reply| replace:: Pass :obj:`True`, if the message should be sent even if the specified replied-to message is not found. diff --git a/telegram/_bot.py b/telegram/_bot.py index bfeb5e6559a..d8825ef4881 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -6893,22 +6893,6 @@ async def get_forum_topic_icon_stickers( .. versionadded:: 20.0 - Keyword Args: - read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the - Telegram API. - Returns: List[:class:`telegram.Sticker`] @@ -6951,8 +6935,7 @@ async def create_forum_topic( .. versionadded:: 20.0 Args: - chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username - of the target channel (in the format ``@supergroupusername``). + chat_id (:obj:`int` | :obj:`str`): |chat_id_group| name (:obj:`str`): New topic name, :tg-const:`telegram.constants.TopicLimit.MIN_NAME_LENGTH`- :tg-const:`telegram.constants.TopicLimit.MAX_NAME_LENGTH` characters. @@ -6967,22 +6950,6 @@ async def create_forum_topic( the topic icon. Use :meth:`~telegram.Bot.get_forum_topic_icon_stickers` to get all allowed custom emoji identifiers. - Keyword Args: - read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the - Telegram API. - Returns: :obj:`bool`: On success, :class:`telegram.ForumTopic` is returned. @@ -7032,10 +6999,8 @@ async def edit_forum_topic( .. versionadded:: 20.0 Args: - chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username - of the target channel (in the format ``@supergroupusername``). - message_thread_id (:obj:`int`): Unique identifier for the target message thread of - the forum topic. + chat_id (:obj:`int` | :obj:`str`): |chat_id_group| + message_thread_id (:obj:`int`): |message_thread_id| name (:obj:`str`): New topic name, :tg-const:`telegram.constants.TopicLimit.MIN_NAME_LENGTH`- :tg-const:`telegram.constants.TopicLimit.MAX_NAME_LENGTH` characters. @@ -7043,22 +7008,6 @@ async def edit_forum_topic( the topic icon. Use :meth:`~telegram.Bot.get_forum_topic_icon_stickers` to get all allowed custom emoji identifiers. - Keyword Args: - read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the - Telegram API. - Returns: :obj:`bool`: On success, :obj:`True` is returned. @@ -7106,26 +7055,8 @@ async def close_forum_topic( .. versionadded:: 20.0 Args: - chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username - of the target channel (in the format ``@supergroupusername``). - message_thread_id (:obj:`int`): Unique identifier for the target message thread of - the forum topic. - - Keyword Args: - read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the - Telegram API. + chat_id (:obj:`int` | :obj:`str`): |chat_id_group| + message_thread_id (:obj:`int`): |message_thread_id| Returns: :obj:`bool`: On success, :obj:`True` is returned. @@ -7172,26 +7103,8 @@ async def reopen_forum_topic( .. versionadded:: 20.0 Args: - chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username - of the target channel (in the format ``@supergroupusername``). - message_thread_id (:obj:`int`): Unique identifier for the target message thread of - the forum topic. - - Keyword Args: - read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the - Telegram API. + chat_id (:obj:`int` | :obj:`str`): |chat_id_group| + message_thread_id (:obj:`int`): |message_thread_id| Returns: :obj:`bool`: On success, :obj:`True` is returned. @@ -7238,26 +7151,8 @@ async def delete_forum_topic( .. versionadded:: 20.0 Args: - chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username - of the target channel (in the format ``@supergroupusername``). - message_thread_id (:obj:`int`): Unique identifier for the target message thread of - the forum topic. - - Keyword Args: - read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the - Telegram API. + chat_id (:obj:`int` | :obj:`str`): |chat_id_group| + message_thread_id (:obj:`int`): |message_thread_id| Returns: :obj:`bool`: On success, :obj:`True` is returned. @@ -7304,26 +7199,8 @@ async def unpin_all_forum_topic_messages( .. versionadded:: 20.0 Args: - chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username - of the target channel (in the format ``@supergroupusername``). - message_thread_id (:obj:`int`): Unique identifier for the target message thread of - the forum topic. - - Keyword Args: - read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to - :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to - :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. - api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the - Telegram API. + chat_id (:obj:`int` | :obj:`str`): |chat_id_group| + message_thread_id (:obj:`int`): |message_thread_id| Returns: :obj:`bool`: On success, :obj:`True` is returned.