Co-authored-by: poolitzer <github@poolitzer.eu>
Co-authored-by: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com>
This commit is contained in:
Harshil 2023-10-03 16:32:57 +04:00 committed by GitHub
parent 8d76087bed
commit ae57d3b7c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 184 additions and 24 deletions

View file

@ -14,7 +14,7 @@
:target: https://pypi.org/project/python-telegram-bot/
:alt: Supported Python versions
.. image:: https://img.shields.io/badge/Bot%20API-6.8-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-6.9-blue?logo=telegram
:target: https://core.telegram.org/bots/api-changelog
:alt: Supported Bot API versions
@ -93,7 +93,7 @@ Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conju
Telegram API support
====================
All types and methods of the Telegram Bot API **6.8** are supported.
All types and methods of the Telegram Bot API **6.9** are supported.
Installing
==========

View file

@ -14,7 +14,7 @@
:target: https://pypi.org/project/python-telegram-bot-raw/
:alt: Supported Python versions
.. image:: https://img.shields.io/badge/Bot%20API-6.8-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-6.9-blue?logo=telegram
:target: https://core.telegram.org/bots/api-changelog
:alt: Supported Bot API versions
@ -89,7 +89,7 @@ Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conju
Telegram API support
====================
All types and methods of the Telegram Bot API **6.8** are supported.
All types and methods of the Telegram Bot API **6.9** are supported.
Installing
==========

View file

@ -4590,6 +4590,9 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]):
can_manage_chat: Optional[bool] = None,
can_manage_video_chats: Optional[bool] = None,
can_manage_topics: Optional[bool] = None,
can_post_stories: Optional[bool] = None,
can_edit_stories: Optional[bool] = None,
can_delete_stories: Optional[bool] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -4645,6 +4648,18 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]):
allowed to create, rename, close, and reopen forum topics; supergroups only.
.. versionadded:: 20.0
can_post_stories (:obj:`bool`, optional): Pass :obj:`True`, if the administrator can
post stories in the channel; channels only.
.. versionadded:: NEXT.VERSION
can_edit_stories (:obj:`bool`, optional): Pass :obj:`True`, if the administrator can
edit stories posted by other users; channels only.
.. versionadded:: NEXT.VERSION
can_delete_stories (:obj:`bool`, optional): Pass :obj:`True`, if the administrator can
delete stories posted by other users; channels only.
.. versionadded:: NEXT.VERSION
Returns:
:obj:`bool`: On success, :obj:`True` is returned.
@ -4668,6 +4683,9 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]):
"can_manage_chat": can_manage_chat,
"can_manage_video_chats": can_manage_video_chats,
"can_manage_topics": can_manage_topics,
"can_post_stories": can_post_stories,
"can_edit_stories": can_edit_stories,
"can_delete_stories": can_delete_stories,
}
return await self._post(

View file

@ -922,6 +922,9 @@ class Chat(TelegramObject):
can_manage_chat: Optional[bool] = None,
can_manage_video_chats: Optional[bool] = None,
can_manage_topics: Optional[bool] = None,
can_post_stories: Optional[bool] = None,
can_edit_stories: Optional[bool] = None,
can_delete_stories: Optional[bool] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -941,6 +944,9 @@ class Chat(TelegramObject):
The argument ``can_manage_voice_chats`` was renamed to
:paramref:`~telegram.Bot.promote_chat_member.can_manage_video_chats` in accordance to
Bot API 6.0.
.. versionchanged:: NEXT.VERSION
The arguments `can_post_stories`, `can_edit_stories` and `can_delete_stories` were
added.
Returns:
:obj:`bool`: On success, :obj:`True` is returned.
@ -966,6 +972,9 @@ class Chat(TelegramObject):
can_manage_chat=can_manage_chat,
can_manage_video_chats=can_manage_video_chats,
can_manage_topics=can_manage_topics,
can_post_stories=can_post_stories,
can_edit_stories=can_edit_stories,
can_delete_stories=can_delete_stories,
)
async def restrict_member(

View file

@ -31,13 +31,18 @@ class ChatAdministratorRights(TelegramObject):
:attr:`can_delete_messages`, :attr:`can_manage_video_chats`, :attr:`can_restrict_members`,
:attr:`can_promote_members`, :attr:`can_change_info`, :attr:`can_invite_users`,
:attr:`can_post_messages`, :attr:`can_edit_messages`, :attr:`can_pin_messages`,
:attr:`can_manage_topics` are equal.
:attr:`can_manage_topics`, :attr:`can_post_stories`, :attr:`can_delete_stories`, and
:attr:`can_edit_stories` are equal.
.. versionadded:: 20.0
.. versionchanged:: 20.0
:attr:`can_manage_topics` is considered as well when comparing objects of
this type in terms of equality.
.. versionadded:: 20.0
.. versionchanged:: NEXT.VERSION
:attr:`can_post_stories`, :attr:`can_edit_stories`, and :attr:`can_delete_stories` are
considered as well when comparing objects of this type in terms of equality.
Args:
is_anonymous (:obj:`bool`): :obj:`True`, if the user's presence in the chat is hidden.
@ -65,6 +70,18 @@ class ChatAdministratorRights(TelegramObject):
messages of other users.
can_pin_messages (:obj:`bool`, optional): :obj:`True`, if the user is allowed to pin
messages; groups and supergroups only.
can_post_stories (:obj:`bool`, optional): :obj:`True`, if the administrator can post
stories in the channel; channels only.
.. versionadded:: NEXT.VERSION
can_edit_stories (:obj:`bool`, optional): :obj:`True`, if the administrator can edit
stories posted by other users; channels only.
.. versionadded:: NEXT.VERSION
can_delete_stories (:obj:`bool`, optional): :obj:`True`, if the administrator can delete
stories posted by other users; channels only.
.. versionadded:: NEXT.VERSION
can_manage_topics (:obj:`bool`, optional): :obj:`True`, if the user is allowed
to create, rename, close, and reopen forum topics; supergroups only.
@ -96,6 +113,18 @@ class ChatAdministratorRights(TelegramObject):
messages of other users.
can_pin_messages (:obj:`bool`): Optional. :obj:`True`, if the user is allowed to pin
messages; groups and supergroups only.
can_post_stories (:obj:`bool`): Optional. :obj:`True`, if the administrator can post
stories in the channel; channels only.
.. versionadded:: NEXT.VERSION
can_edit_stories (:obj:`bool`): Optional. :obj:`True`, if the administrator can edit
stories posted by other users; channels only.
.. versionadded:: NEXT.VERSION
can_delete_stories (:obj:`bool`): Optional. :obj:`True`, if the administrator can delete
stories posted by other users; channels only.
.. versionadded:: NEXT.VERSION
can_manage_topics (:obj:`bool`): Optional. :obj:`True`, if the user is allowed
to create, rename, close, and reopen forum topics; supergroups only.
@ -115,6 +144,9 @@ class ChatAdministratorRights(TelegramObject):
"can_edit_messages",
"can_pin_messages",
"can_manage_topics",
"can_post_stories",
"can_edit_stories",
"can_delete_stories",
)
def __init__(
@ -131,6 +163,9 @@ class ChatAdministratorRights(TelegramObject):
can_edit_messages: Optional[bool] = None,
can_pin_messages: Optional[bool] = None,
can_manage_topics: Optional[bool] = None,
can_post_stories: Optional[bool] = None,
can_edit_stories: Optional[bool] = None,
can_delete_stories: Optional[bool] = None,
*,
api_kwargs: Optional[JSONDict] = None,
) -> None:
@ -148,6 +183,9 @@ class ChatAdministratorRights(TelegramObject):
self.can_post_messages: Optional[bool] = can_post_messages
self.can_edit_messages: Optional[bool] = can_edit_messages
self.can_pin_messages: Optional[bool] = can_pin_messages
self.can_post_stories: Optional[bool] = can_post_stories
self.can_edit_stories: Optional[bool] = can_edit_stories
self.can_delete_stories: Optional[bool] = can_delete_stories
self.can_manage_topics: Optional[bool] = can_manage_topics
self._id_attrs = (
@ -163,6 +201,9 @@ class ChatAdministratorRights(TelegramObject):
self.can_edit_messages,
self.can_pin_messages,
self.can_manage_topics,
self.can_post_stories,
self.can_edit_stories,
self.can_delete_stories,
)
self._freeze()
@ -176,7 +217,7 @@ class ChatAdministratorRights(TelegramObject):
.. versionadded:: 20.0
"""
return cls(True, True, True, True, True, True, True, True, True, True, True, True)
return cls(*(True,) * len(cls.__slots__))
@classmethod
def no_rights(cls) -> "ChatAdministratorRights":
@ -186,6 +227,4 @@ class ChatAdministratorRights(TelegramObject):
.. versionadded:: 20.0
"""
return cls(
False, False, False, False, False, False, False, False, False, False, False, False
)
return cls(*(False,) * len(cls.__slots__))

View file

@ -224,6 +224,18 @@ class ChatMemberAdministrator(ChatMember):
messages; channels only.
can_pin_messages (:obj:`bool`, optional): :obj:`True`, if the user is allowed
to pin messages; groups and supergroups only.
can_post_stories (:obj:`bool`, optional): :obj:`True`, if the administrator can post
stories in the channel; channels only.
.. versionadded:: NEXT.VERSION
can_edit_stories (:obj:`bool`, optional): :obj:`True`, if the administrator can edit
stories posted by other users; channels only.
.. versionadded:: NEXT.VERSION
can_delete_stories (:obj:`bool`, optional): :obj:`True`, if the administrator can delete
stories posted by other users; channels only.
.. versionadded:: NEXT.VERSION
can_manage_topics (:obj:`bool`, optional): :obj:`True`, if the user is allowed
to create, rename, close, and reopen forum topics; supergroups only.
@ -265,6 +277,18 @@ class ChatMemberAdministrator(ChatMember):
messages; channels only.
can_pin_messages (:obj:`bool`): Optional. :obj:`True`, if the user is allowed
to pin messages; groups and supergroups only.
can_post_stories (:obj:`bool`): Optional. :obj:`True`, if the administrator can post
stories in the channel; channels only.
.. versionadded:: NEXT.VERSION
can_edit_stories (:obj:`bool`): Optional. :obj:`True`, if the administrator can edit
stories posted by other users; channels only.
.. versionadded:: NEXT.VERSION
can_delete_stories (:obj:`bool`): Optional. :obj:`True`, if the administrator can delete
stories posted by other users; channels only.
.. versionadded:: NEXT.VERSION
can_manage_topics (:obj:`bool`): Optional. :obj:`True`, if the user is allowed
to create, rename, close, and reopen forum topics; supergroups only
@ -287,6 +311,9 @@ class ChatMemberAdministrator(ChatMember):
"can_pin_messages",
"can_manage_topics",
"custom_title",
"can_post_stories",
"can_edit_stories",
"can_delete_stories",
)
def __init__(
@ -306,6 +333,9 @@ class ChatMemberAdministrator(ChatMember):
can_pin_messages: Optional[bool] = None,
can_manage_topics: Optional[bool] = None,
custom_title: Optional[str] = None,
can_post_stories: Optional[bool] = None,
can_edit_stories: Optional[bool] = None,
can_delete_stories: Optional[bool] = None,
*,
api_kwargs: Optional[JSONDict] = None,
):
@ -325,6 +355,9 @@ class ChatMemberAdministrator(ChatMember):
self.can_pin_messages: Optional[bool] = can_pin_messages
self.can_manage_topics: Optional[bool] = can_manage_topics
self.custom_title: Optional[str] = custom_title
self.can_post_stories: Optional[bool] = can_post_stories
self.can_edit_stories: Optional[bool] = can_edit_stories
self.can_delete_stories: Optional[bool] = can_delete_stories
class ChatMemberMember(ChatMember):

View file

@ -330,7 +330,10 @@ class Message(TelegramObject):
.. versionadded:: 20.0
write_access_allowed (:class:`telegram.WriteAccessAllowed`, optional): Service message:
the user allowed the bot added to the attachment menu to write messages.
the user allowed the bot to write messages after adding it to the attachment or side
menu, launching a Web App from a link, or accepting an explicit request from a Web App
sent by the method
`requestWriteAccess <https://core.telegram.org/bots/webapps#initializing-mini-apps>`_.
.. versionadded:: 20.0
has_media_spoiler (:obj:`bool`, optional): :obj:`True`, if the message media is covered

View file

@ -26,7 +26,9 @@ from telegram._utils.types import JSONDict
class WriteAccessAllowed(TelegramObject):
"""
This object represents a service message about a user allowing a bot to write messages after
adding the bot to the attachment menu or launching a Web App from a link.
adding it to the attachment menu, launching a Web App from a link, or accepting an explicit
request from a Web App sent by the method
`requestWriteAccess <https://core.telegram.org/bots/webapps#initializing-mini-apps>`_.
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`web_app_name` is equal.
@ -36,24 +38,50 @@ class WriteAccessAllowed(TelegramObject):
Added custom equality comparison for objects of this class.
Args:
web_app_name (:obj:`str`, optional): Name of the Web App which was launched from a link.
web_app_name (:obj:`str`, optional): Name of the Web App, if the access was granted when
the Web App was launched from a link.
.. versionadded:: 20.3
from_request (:obj:`bool`, optional): :obj:`True`, if the access was granted after the user
accepted an explicit request from a Web App sent by the method
`requestWriteAccess <https://core.telegram.org/bots/webapps#initializing-mini-apps>`_.
.. versionadded:: NEXT.VERSION
from_attachment_menu (:obj:`bool`, optional): :obj:`True`, if the access was granted when
the bot was added to the attachment or side menu.
.. versionadded:: NEXT.VERSION
Attributes:
web_app_name (:obj:`str`): Optional. Name of the Web App which was launched from a link.
web_app_name (:obj:`str`): Optional. Name of the Web App, if the access was granted when
the Web App was launched from a link.
.. versionadded:: 20.3
from_request (:obj:`bool`): Optional. :obj:`True`, if the access was granted after the user
accepted an explicit request from a Web App.
.. versionadded:: NEXT.VERSION
from_attachment_menu (:obj:`bool`): Optional. :obj:`True`, if the access was granted when
the bot was added to the attachment or side menu.
.. versionadded:: NEXT.VERSION
"""
__slots__ = ("web_app_name",)
__slots__ = ("web_app_name", "from_request", "from_attachment_menu")
def __init__(
self, web_app_name: Optional[str] = None, *, api_kwargs: Optional[JSONDict] = None
self,
web_app_name: Optional[str] = None,
from_request: Optional[bool] = None,
from_attachment_menu: Optional[bool] = None,
*,
api_kwargs: Optional[JSONDict] = None,
):
super().__init__(api_kwargs=api_kwargs)
self.web_app_name: Optional[str] = web_app_name
self.from_request: Optional[bool] = from_request
self.from_attachment_menu: Optional[bool] = from_attachment_menu
self._id_attrs = (self.web_app_name,)

View file

@ -116,7 +116,7 @@ class _BotAPIVersion(NamedTuple):
#: :data:`telegram.__bot_api_version_info__`.
#:
#: .. versionadded:: 20.0
BOT_API_VERSION_INFO: Final[_BotAPIVersion] = _BotAPIVersion(major=6, minor=8)
BOT_API_VERSION_INFO: Final[_BotAPIVersion] = _BotAPIVersion(major=6, minor=9)
#: :obj:`str`: Telegram Bot API
#: version supported by this version of `python-telegram-bot`. Also available as
#: :data:`telegram.__bot_api_version__`.

View file

@ -2057,6 +2057,9 @@ class ExtBot(Bot, Generic[RLARGS]):
can_manage_chat: Optional[bool] = None,
can_manage_video_chats: Optional[bool] = None,
can_manage_topics: Optional[bool] = None,
can_post_stories: Optional[bool] = None,
can_edit_stories: Optional[bool] = None,
can_delete_stories: Optional[bool] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2080,6 +2083,9 @@ class ExtBot(Bot, Generic[RLARGS]):
can_manage_chat=can_manage_chat,
can_manage_video_chats=can_manage_video_chats,
can_manage_topics=can_manage_topics,
can_post_stories=can_post_stories,
can_edit_stories=can_edit_stories,
can_delete_stories=can_delete_stories,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,

View file

@ -2699,6 +2699,9 @@ class TestBotWithRequest:
can_manage_chat=True,
can_manage_video_chats=True,
can_manage_topics=True,
can_post_stories=True,
can_edit_stories=True,
can_delete_stories=True,
)
# Test that we pass the correct params to TG
@ -2719,6 +2722,9 @@ class TestBotWithRequest:
and data.get("can_manage_chat") == 10
and data.get("can_manage_video_chats") == 11
and data.get("can_manage_topics") == 12
and data.get("can_post_stories") == 13
and data.get("can_edit_stories") == 14
and data.get("can_delete_stories") == 15
)
monkeypatch.setattr(bot, "_post", make_assertion)
@ -2737,6 +2743,9 @@ class TestBotWithRequest:
can_manage_chat=10,
can_manage_video_chats=11,
can_manage_topics=12,
can_post_stories=13,
can_edit_stories=14,
can_delete_stories=15,
)
async def test_export_chat_invite_link(self, bot, channel_id):

View file

@ -37,6 +37,9 @@ def chat_admin_rights():
can_manage_video_chats=True,
can_manage_topics=True,
is_anonymous=True,
can_post_stories=True,
can_edit_stories=True,
can_delete_stories=True,
)
@ -61,6 +64,9 @@ class TestChatAdministratorRightsWithoutRequest:
"can_manage_video_chats": True,
"can_manage_topics": True,
"is_anonymous": True,
"can_post_stories": True,
"can_edit_stories": True,
"can_delete_stories": True,
}
chat_administrator_rights_de = ChatAdministratorRights.de_json(json_dict, bot)
assert chat_administrator_rights_de.api_kwargs == {}
@ -84,13 +90,16 @@ class TestChatAdministratorRightsWithoutRequest:
assert admin_rights_dict["is_anonymous"] == car.is_anonymous
assert admin_rights_dict["can_manage_video_chats"] == car.can_manage_video_chats
assert admin_rights_dict["can_manage_topics"] == car.can_manage_topics
assert admin_rights_dict["can_post_stories"] == car.can_post_stories
assert admin_rights_dict["can_edit_stories"] == car.can_edit_stories
assert admin_rights_dict["can_delete_stories"] == car.can_delete_stories
def test_equality(self):
a = ChatAdministratorRights(True, False, False, False, False, False, False, False, False)
b = ChatAdministratorRights(True, False, False, False, False, False, False, False, False)
c = ChatAdministratorRights(False, False, False, False, False, False, False, False, False)
d = ChatAdministratorRights(True, True, False, False, False, False, False, False, False)
e = ChatAdministratorRights(True, True, False, False, False, False, False, False, False)
a = ChatAdministratorRights(True, *((False,) * 11))
b = ChatAdministratorRights(True, *((False,) * 11))
c = ChatAdministratorRights(*(False,) * 12)
d = ChatAdministratorRights(True, True, *((False,) * 10))
e = ChatAdministratorRights(True, True, *((False,) * 10))
assert a == b
assert hash(a) == hash(b)
@ -110,7 +119,7 @@ class TestChatAdministratorRightsWithoutRequest:
t = ChatAdministratorRights.all_rights()
# if the dirs are the same, the attributes will all be there
assert dir(f) == dir(t)
# now we just need to check that all attributes are True. _id_attrs returns all values,
# now we just need to check that all attributes are True. __slots__ returns all values,
# if a new one is added without defaulting to True, this will fail
for key in t.__slots__:
assert t[key] is True
@ -122,7 +131,7 @@ class TestChatAdministratorRightsWithoutRequest:
t = ChatAdministratorRights.no_rights()
# if the dirs are the same, the attributes will all be there
assert dir(f) == dir(t)
# now we just need to check that all attributes are True. _id_attrs returns all values,
# now we just need to check that all attributes are True. __slots__ returns all values,
# if a new one is added without defaulting to True, this will fail
for key in t.__slots__:
assert t[key] is False

View file

@ -68,6 +68,9 @@ class CMDefaults:
can_send_videos: bool = True
can_send_video_notes: bool = True
can_send_voice_notes: bool = True
can_post_stories: bool = True
can_edit_stories: bool = True
can_delete_stories: bool = True
def chat_member_owner():
@ -91,6 +94,9 @@ def chat_member_administrator():
CMDefaults.can_pin_messages,
CMDefaults.can_manage_topics,
CMDefaults.custom_title,
CMDefaults.can_post_stories,
CMDefaults.can_edit_stories,
CMDefaults.can_delete_stories,
)