Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Addcan_manage_topics forpromoteChatMember andChat* classes#3342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Bibo-Joshi merged 7 commits intopython-telegram-bot:api_6.3_updatefromclot27:new_api_update
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletionstelegram/_bot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5332,6 +5332,7 @@ async def promote_chat_member(
is_anonymous: bool = None,
can_manage_chat: bool = None,
can_manage_video_chats: bool = None,
can_manage_topics: bool = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand DownExpand Up@@ -5386,6 +5387,10 @@ async def promote_chat_member(
add new administrators with a subset of his own privileges or demote administrators
that he has promoted, directly or indirectly (promoted by administrators that were
appointed by him).
can_manage_topics (:obj: `bool`, optional): Pass :obj:`True`, if the administrator is
allowed to create, rename, close, and reopen forum topics, supergroups only.

.. versionadded:: 20.0

Keyword Args:
read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
Expand DownExpand Up@@ -5434,6 +5439,8 @@ async def promote_chat_member(
data["can_manage_chat"] = can_manage_chat
if can_manage_video_chats is not None:
data["can_manage_video_chats"] = can_manage_video_chats
if can_manage_topics is not None:
data["can_manage_topics"] = can_manage_topics

result = await self._post(
"promoteChatMember",
Expand Down
25 changes: 22 additions & 3 deletionstelegram/_chatadministratorrights.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,12 @@ class ChatAdministratorRights(TelegramObject):
considered equal, if their :attr:`is_anonymous`, :attr:`can_manage_chat`,
: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` are equal.
:attr:`can_post_messages`, :attr:`can_edit_messages`, :attr:`can_pin_messages`,
:attr:`can_manage_topics` are equal.

.. versionchanged:: 20.0
:attr:`can_manage_topics` is considered as well when comparing objects of
this type in terms of equality.

.. seealso: :meth:`Bot.set_my_default_administrator_rights`,
:meth:`Bot.get_my_default_administrator_rights`
Expand DownExpand Up@@ -62,6 +67,10 @@ 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_manage_topics (:obj: `bool`, optional): :obj:`True`, if the user is allowed
to create, rename, close, and reopen forum topics; supergroups only.

.. versionadded:: 20.0

Attributes:
is_anonymous (:obj:`bool`): :obj:`True`, if the user's presence in the chat is hidden.
Expand DownExpand Up@@ -89,6 +98,10 @@ 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_manage_topics (:obj: `bool`, optional): :obj:`True`, if the user is allowed
to create, rename, close, and reopen forum topics; supergroups only.

.. versionadded:: 20.0
"""

__slots__ = (
Expand All@@ -103,6 +116,7 @@ class ChatAdministratorRights(TelegramObject):
"can_post_messages",
"can_edit_messages",
"can_pin_messages",
"can_manage_topics",
)

def __init__(
Expand All@@ -118,6 +132,7 @@ def __init__(
can_post_messages: bool = None,
can_edit_messages: bool = None,
can_pin_messages: bool = None,
can_manage_topics: bool = None,
*,
api_kwargs: JSONDict = None,
) -> None:
Expand All@@ -135,6 +150,7 @@ def __init__(
self.can_post_messages = can_post_messages
self.can_edit_messages = can_edit_messages
self.can_pin_messages = can_pin_messages
self.can_manage_topics = can_manage_topics

self._id_attrs = (
self.is_anonymous,
Expand All@@ -148,6 +164,7 @@ def __init__(
self.can_post_messages,
self.can_edit_messages,
self.can_pin_messages,
self.can_manage_topics,
)

@classmethod
Expand All@@ -159,7 +176,7 @@ def all_rights(cls) -> "ChatAdministratorRights":

.. versionadded:: 20.0
"""
return cls(True, True, True, True, True, True, True, True, True, True, True)
return cls(True, True, True, True, True, True, True, True, True, True, True, True)

@classmethod
def no_rights(cls) -> "ChatAdministratorRights":
Expand All@@ -169,4 +186,6 @@ def no_rights(cls) -> "ChatAdministratorRights":

.. versionadded:: 20.0
"""
return cls(False, False, False, False, False, False, False, False, False, False, False)
return cls(
False, False, False, False, False, False, False, False, False, False, False, False
)
22 changes: 22 additions & 0 deletionstelegram/_chatmember.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -215,6 +215,10 @@ 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_manage_topics (:obj: `bool`, optional): :obj:`True`, if the user is allowed
to create, rename, close, and reopen forum topics; supergroups only.

.. versionadded:: 20.0
custom_title (:obj:`str`, optional): Custom title for this user.

Attributes:
Expand DownExpand Up@@ -252,6 +256,10 @@ 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_manage_topics (:obj: `bool`, optional): :obj:`True`, if the user is allowed
to create, rename, close, and reopen forum topics; supergroups only

.. versionadded:: 20.0
custom_title (:obj:`str`): Optional. Custom title for this user.
"""

Expand All@@ -268,6 +276,7 @@ class ChatMemberAdministrator(ChatMember):
"can_post_messages",
"can_edit_messages",
"can_pin_messages",
"can_manage_topics",
"custom_title",
)

Expand All@@ -286,6 +295,7 @@ def __init__(
can_post_messages: bool = None,
can_edit_messages: bool = None,
can_pin_messages: bool = None,
can_manage_topics: bool = None,
custom_title: str = None,
*,
api_kwargs: JSONDict = None,
Expand All@@ -303,6 +313,7 @@ def __init__(
self.can_post_messages = can_post_messages
self.can_edit_messages = can_edit_messages
self.can_pin_messages = can_pin_messages
self.can_manage_topics = can_manage_topics
self.custom_title = custom_title


Expand DownExpand Up@@ -361,6 +372,10 @@ class ChatMemberRestricted(ChatMember):
to send animations, games, stickers and use inline bots.
can_add_web_page_previews (:obj:`bool`): :obj:`True`, if the user is
allowed to add web page previews to their messages.
can_manage_topics (:obj: `bool`, optional): :obj:`True`, if the user is allowed
to create, rename, close, and reopen forum topics; supergroups only

.. versionadded:: 20.0
until_date (:class:`datetime.datetime`): Date when restrictions
will be lifted for this user.

Expand All@@ -386,6 +401,10 @@ class ChatMemberRestricted(ChatMember):
to send animations, games, stickers and use inline bots.
can_add_web_page_previews (:obj:`bool`): :obj:`True`, if the user is
allowed to add web page previews to their messages.
can_manage_topics (:obj: `bool`, optional): :obj:`True`, if the user is allowed
to create, rename, close, and reopen forum topics; supergroups only

.. versionadded:: 20.0
until_date (:class:`datetime.datetime`): Date when restrictions
will be lifted for this user.

Expand All@@ -401,6 +420,7 @@ class ChatMemberRestricted(ChatMember):
"can_send_polls",
"can_send_other_messages",
"can_add_web_page_previews",
"can_manage_topics",
"until_date",
)

Expand All@@ -416,6 +436,7 @@ def __init__(
can_send_polls: bool,
can_send_other_messages: bool,
can_add_web_page_previews: bool,
can_manage_topics: bool,
until_date: datetime.datetime,
*,
api_kwargs: JSONDict = None,
Expand All@@ -430,6 +451,7 @@ def __init__(
self.can_send_polls = can_send_polls
self.can_send_other_messages = can_send_other_messages
self.can_add_web_page_previews = can_add_web_page_previews
self.can_manage_topics = can_manage_topics
self.until_date = until_date


Expand Down
25 changes: 21 additions & 4 deletionstelegram/_chatpermissions.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,12 +28,17 @@ class ChatPermissions(TelegramObject):
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`can_send_messages`, :attr:`can_send_media_messages`,
:attr:`can_send_polls`, :attr:`can_send_other_messages`, :attr:`can_add_web_page_previews`,
:attr:`can_change_info`, :attr:`can_invite_users` and :attr:`can_pin_messages` are equal.
:attr:`can_change_info`, :attr:`can_invite_users` and :attr:`can_pin_messages`,
:attr:`can_manage_topics` are equal.

.. versionchanged:: 20.0
:attr:`can_manage_topics` is considered as well when comparing objects of
this type in terms of equality.

Note:
Though not stated explicitly in the official docs, Telegram changes not only the
permissions that are set, but also sets all the others to :obj:`False`. However, since not
documented, thisbehaviour may change unbeknown to PTB.
documented, thisbehavior may change unbeknown to PTB.

Args:
can_send_messages (:obj:`bool`, optional): :obj:`True`, if the user is allowed to send text
Expand All@@ -54,6 +59,10 @@ class ChatPermissions(TelegramObject):
users to the chat.
can_pin_messages (:obj:`bool`, optional): :obj:`True`, if the user is allowed to pin
messages. Ignored in public supergroups.
can_manage_topics (:obj: `bool`, optional): :obj:`True`, if the user is allowed
to create, rename, close, and reopen forum topics; supergroups only

.. versionadded:: 20.0

Attributes:
can_send_messages (:obj:`bool`): Optional. :obj:`True`, if the user is allowed to send text
Expand All@@ -74,6 +83,10 @@ class ChatPermissions(TelegramObject):
new users to the chat.
can_pin_messages (:obj:`bool`): Optional. :obj:`True`, if the user is allowed to pin
messages. Ignored in public supergroups.
can_manage_topics (:obj: `bool`): Optional. :obj:`True`, if the user is allowed
to create, rename, close, and reopen forum topics; supergroups only

.. versionadded:: 20.0

"""

Expand All@@ -86,6 +99,7 @@ class ChatPermissions(TelegramObject):
"can_change_info",
"can_pin_messages",
"can_add_web_page_previews",
"can_manage_topics",
)

def __init__(
Expand All@@ -98,6 +112,7 @@ def __init__(
can_change_info: bool = None,
can_invite_users: bool = None,
can_pin_messages: bool = None,
can_manage_topics: bool = None,
*,
api_kwargs: JSONDict = None,
):
Expand All@@ -111,6 +126,7 @@ def __init__(
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.can_pin_messages = can_pin_messages
self.can_manage_topics = can_manage_topics

self._id_attrs = (
self.can_send_messages,
Expand All@@ -121,6 +137,7 @@ def __init__(
self.can_change_info,
self.can_invite_users,
self.can_pin_messages,
self.can_manage_topics,
)

@classmethod
Expand All@@ -133,7 +150,7 @@ def all_permissions(cls) -> "ChatPermissions":
.. versionadded:: 20.0

"""
return cls(True, True, True, True, True, True, True, True)
return cls(True, True, True, True, True, True, True, True, True)

@classmethod
def no_permissions(cls) -> "ChatPermissions":
Expand All@@ -143,4 +160,4 @@ def no_permissions(cls) -> "ChatPermissions":

.. versionadded:: 20.0
"""
return cls(False, False, False, False, False, False, False, False)
return cls(False, False, False, False, False, False, False, False, False)
2 changes: 2 additions & 0 deletionstelegram/ext/_extbot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1783,6 +1783,7 @@ async def promote_chat_member(
is_anonymous: bool = None,
can_manage_chat: bool = None,
can_manage_video_chats: bool = None,
can_manage_topics: bool = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand All@@ -1805,6 +1806,7 @@ async def promote_chat_member(
is_anonymous=is_anonymous,
can_manage_chat=can_manage_chat,
can_manage_video_chats=can_manage_video_chats,
can_manage_topics=can_manage_topics,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
Expand Down
4 changes: 4 additions & 0 deletionstests/test_bot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2129,6 +2129,7 @@ async def test_promote_chat_member(self, bot, channel_id, monkeypatch):
can_promote_members=True,
can_manage_chat=True,
can_manage_video_chats=True,
can_manage_topics=True,
)

# Test that we pass the correct params to TG
Expand All@@ -2148,6 +2149,7 @@ async def make_assertion(*args, **_):
and data.get("can_promote_members") == 9
and data.get("can_manage_chat") == 10
and data.get("can_manage_video_chats") == 11
and data.get("can_manage_topics") == 12
)

monkeypatch.setattr(bot, "_post", make_assertion)
Expand All@@ -2165,6 +2167,7 @@ async def make_assertion(*args, **_):
can_promote_members=9,
can_manage_chat=10,
can_manage_video_chats=11,
can_manage_topics=12,
)

@flaky(3, 1)
Expand DownExpand Up@@ -2579,6 +2582,7 @@ async def test_get_set_my_default_administrator_rights(self, bot):
assert my_admin_rights_ch.can_promote_members is my_rights.can_promote_members
assert my_admin_rights_ch.can_restrict_members is my_rights.can_restrict_members
assert my_admin_rights_ch.can_pin_messages is None # Not returned for channels
assert my_admin_rights_ch.can_manage_topics is None # Not returned for channels

@pytest.mark.asyncio
async def test_get_set_chat_menu_button(self, bot, chat_id):
Expand Down
17 changes: 10 additions & 7 deletionstests/test_chatadministratorrights.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,6 +34,7 @@ def chat_admin_rights():
can_edit_messages=True,
can_manage_chat=True,
can_manage_video_chats=True,
can_manage_topics=True,
is_anonymous=True,
)

Expand All@@ -57,6 +58,7 @@ def test_de_json(self, bot, chat_admin_rights):
"can_edit_messages": True,
"can_manage_chat": True,
"can_manage_video_chats": True,
"can_manage_topics": True,
"is_anonymous": True,
}
chat_administrator_rights_de = ChatAdministratorRights.de_json(json_dict, bot)
Expand All@@ -80,13 +82,14 @@ def test_to_dict(self, chat_admin_rights):
assert admin_rights_dict["can_manage_chat"] == car.can_manage_chat
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

def test_equality(self):
a = ChatAdministratorRights(True, False, False, False, False, False, False, False)
b = ChatAdministratorRights(True, False, False, False, False, False, False, False)
c = ChatAdministratorRights(False, False, False, False, False, False, False, False)
d = ChatAdministratorRights(True, True, False, False, False, False, False, False)
e = ChatAdministratorRights(True, True, False, False, False, False, False, False)
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)

assert a == b
assert hash(a) == hash(b)
Expand All@@ -102,7 +105,7 @@ def test_equality(self):
assert hash(d) == hash(e)

def test_all_rights(self):
f = ChatAdministratorRights(True, True, True, True, True, True, True, True)
f = ChatAdministratorRights(True, True, True, True, True, True, True, True, True)
t = ChatAdministratorRights.all_rights()
# if the dirs are the same, the attributes will all be there
assert dir(f) == dir(t)
Expand All@@ -114,7 +117,7 @@ def test_all_rights(self):
assert f != t

def test_no_rights(self):
f = ChatAdministratorRights(False, False, False, False, False, False, False, False)
f = ChatAdministratorRights(False, False, False, False, False, False, False, False, False)
t = ChatAdministratorRights.no_rights()
# if the dirs are the same, the attributes will all be there
assert dir(f) == dir(t)
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp