mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 12:51:18 +00:00
[Bot API 4.4] Update chat permissions
- Move can_* permissions back to ChatMember objects - Rename restrict_chat to set_chat_permissions - Update restrict_chat_member to accept a single ChatPermissions arg. - Update ChatPermissions to be the same as the one on the Bot API
This commit is contained in:
parent
091552e5d9
commit
c6f346f83d
@ -189,6 +189,7 @@ def pyrogram_api():
|
|||||||
delete_chat_photo
|
delete_chat_photo
|
||||||
set_chat_title
|
set_chat_title
|
||||||
set_chat_description
|
set_chat_description
|
||||||
|
set_chat_permissions
|
||||||
pin_chat_message
|
pin_chat_message
|
||||||
unpin_chat_message
|
unpin_chat_message
|
||||||
get_chat
|
get_chat
|
||||||
@ -199,7 +200,6 @@ def pyrogram_api():
|
|||||||
get_dialogs
|
get_dialogs
|
||||||
iter_dialogs
|
iter_dialogs
|
||||||
get_dialogs_count
|
get_dialogs_count
|
||||||
restrict_chat
|
|
||||||
update_chat_username
|
update_chat_username
|
||||||
archive_chats
|
archive_chats
|
||||||
unarchive_chats
|
unarchive_chats
|
||||||
|
@ -38,9 +38,9 @@ from .kick_chat_member import KickChatMember
|
|||||||
from .leave_chat import LeaveChat
|
from .leave_chat import LeaveChat
|
||||||
from .pin_chat_message import PinChatMessage
|
from .pin_chat_message import PinChatMessage
|
||||||
from .promote_chat_member import PromoteChatMember
|
from .promote_chat_member import PromoteChatMember
|
||||||
from .restrict_chat import RestrictChat
|
|
||||||
from .restrict_chat_member import RestrictChatMember
|
from .restrict_chat_member import RestrictChatMember
|
||||||
from .set_chat_description import SetChatDescription
|
from .set_chat_description import SetChatDescription
|
||||||
|
from .set_chat_permissions import SetChatPermissions
|
||||||
from .set_chat_photo import SetChatPhoto
|
from .set_chat_photo import SetChatPhoto
|
||||||
from .set_chat_title import SetChatTitle
|
from .set_chat_title import SetChatTitle
|
||||||
from .unarchive_chats import UnarchiveChats
|
from .unarchive_chats import UnarchiveChats
|
||||||
@ -71,7 +71,7 @@ class Chats(
|
|||||||
IterDialogs,
|
IterDialogs,
|
||||||
IterChatMembers,
|
IterChatMembers,
|
||||||
UpdateChatUsername,
|
UpdateChatUsername,
|
||||||
RestrictChat,
|
SetChatPermissions,
|
||||||
GetDialogsCount,
|
GetDialogsCount,
|
||||||
ArchiveChats,
|
ArchiveChats,
|
||||||
UnarchiveChats,
|
UnarchiveChats,
|
||||||
|
@ -20,7 +20,7 @@ from typing import Union
|
|||||||
|
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions, types
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
from ...types.user_and_chats import Chat
|
from ...types.user_and_chats import Chat, ChatPermissions
|
||||||
|
|
||||||
|
|
||||||
class RestrictChatMember(BaseClient):
|
class RestrictChatMember(BaseClient):
|
||||||
@ -28,20 +28,13 @@ class RestrictChatMember(BaseClient):
|
|||||||
self,
|
self,
|
||||||
chat_id: Union[int, str],
|
chat_id: Union[int, str],
|
||||||
user_id: Union[int, str],
|
user_id: Union[int, str],
|
||||||
until_date: int = 0,
|
permissions: ChatPermissions,
|
||||||
can_send_messages: bool = False,
|
until_date: int = 0
|
||||||
can_send_media_messages: bool = False,
|
|
||||||
can_send_other_messages: bool = False,
|
|
||||||
can_add_web_page_previews: bool = False,
|
|
||||||
can_send_polls: bool = False,
|
|
||||||
can_change_info: bool = False,
|
|
||||||
can_invite_users: bool = False,
|
|
||||||
can_pin_messages: bool = False
|
|
||||||
) -> Chat:
|
) -> Chat:
|
||||||
"""Restrict a user in a supergroup.
|
"""Restrict a user in a supergroup.
|
||||||
|
|
||||||
The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights.
|
You must be an administrator in the supergroup for this to work and must have the appropriate admin rights.
|
||||||
Pass True for all boolean parameters to lift restrictions from a user.
|
Pass True for all permissions to lift restrictions from a user.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
chat_id (``int`` | ``str``):
|
chat_id (``int`` | ``str``):
|
||||||
@ -51,37 +44,14 @@ class RestrictChatMember(BaseClient):
|
|||||||
Unique identifier (int) or username (str) of the target user.
|
Unique identifier (int) or username (str) of the target user.
|
||||||
For a contact that exists in your Telegram address book you can use his phone number (str).
|
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||||
|
|
||||||
|
permissions (:obj:`ChatPermissions`):
|
||||||
|
New user permissions.
|
||||||
|
|
||||||
until_date (``int``, *optional*):
|
until_date (``int``, *optional*):
|
||||||
Date when the user will be unbanned, unix time.
|
Date when the user will be unbanned, unix time.
|
||||||
If user is banned for more than 366 days or less than 30 seconds from the current time they are
|
If user is banned for more than 366 days or less than 30 seconds from the current time they are
|
||||||
considered to be banned forever. Defaults to 0 (ban forever).
|
considered to be banned forever. Defaults to 0 (ban forever).
|
||||||
|
|
||||||
can_send_messages (``bool``, *optional*):
|
|
||||||
Pass True, if the user can send text messages, contacts, locations and venues.
|
|
||||||
|
|
||||||
can_send_media_messages (``bool``, *optional*):
|
|
||||||
Pass True, if the user can send audios, documents, photos, videos, video notes and voice notes,
|
|
||||||
implies can_send_messages.
|
|
||||||
|
|
||||||
can_send_other_messages (``bool``, *optional*):
|
|
||||||
Pass True, if the user can send animations, games, stickers and use inline bots,
|
|
||||||
implies can_send_messages.
|
|
||||||
|
|
||||||
can_add_web_page_previews (``bool``, *optional*):
|
|
||||||
Pass True, if the user may add web page previews to their messages, implies can_send_messages.
|
|
||||||
|
|
||||||
can_send_polls (``bool``, *optional*):
|
|
||||||
Pass True, if the user can send polls, implies can_send_messages.
|
|
||||||
|
|
||||||
can_change_info (``bool``, *optional*):
|
|
||||||
Pass True, if the user can change the chat title, photo and other settings.
|
|
||||||
|
|
||||||
can_invite_users (``bool``, *optional*):
|
|
||||||
Pass True, if the user can invite new users to the chat.
|
|
||||||
|
|
||||||
can_pin_messages (``bool``, *optional*):
|
|
||||||
Pass True, if the user can pin messages.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
:obj:`Chat`: On success, a chat object is returned.
|
:obj:`Chat`: On success, a chat object is returned.
|
||||||
|
|
||||||
@ -90,14 +60,16 @@ class RestrictChatMember(BaseClient):
|
|||||||
|
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
# Completely restrict chat member forever
|
from pyrogram import ChatPermissions
|
||||||
app.restrict_chat_member(chat_id, user_id)
|
|
||||||
|
|
||||||
# Chat member can't send messages for 24h
|
# Completely restrict chat member (mute) forever
|
||||||
app.restrict_chat_member(chat_id, user_id, int(time.time() + 86400))
|
app.restrict_chat_member(chat_id, user_id, ChatPermissions())
|
||||||
|
|
||||||
|
# Chat member muted for 24h
|
||||||
|
app.restrict_chat_member(chat_id, user_id, ChatPermissions(), int(time.time() + 86400))
|
||||||
|
|
||||||
# Chat member can only send text messages
|
# Chat member can only send text messages
|
||||||
app.restrict_chat_member(chat_id, user_id, can_send_messages=True)
|
app.restrict_chat_member(chat_id, user_id, ChatPermissions(can_send_messages=True))
|
||||||
"""
|
"""
|
||||||
send_messages = True
|
send_messages = True
|
||||||
send_media = True
|
send_media = True
|
||||||
@ -111,35 +83,35 @@ class RestrictChatMember(BaseClient):
|
|||||||
invite_users = True
|
invite_users = True
|
||||||
pin_messages = True
|
pin_messages = True
|
||||||
|
|
||||||
if can_send_messages:
|
if permissions.can_send_messages:
|
||||||
send_messages = None
|
send_messages = None
|
||||||
|
|
||||||
if can_send_media_messages:
|
if permissions.can_send_media_messages:
|
||||||
send_messages = None
|
send_messages = None
|
||||||
send_media = None
|
send_media = None
|
||||||
|
|
||||||
if can_send_other_messages:
|
if permissions.can_send_other_messages:
|
||||||
send_messages = None
|
send_messages = None
|
||||||
send_stickers = None
|
send_stickers = None
|
||||||
send_gifs = None
|
send_gifs = None
|
||||||
send_games = None
|
send_games = None
|
||||||
send_inline = None
|
send_inline = None
|
||||||
|
|
||||||
if can_add_web_page_previews:
|
if permissions.can_add_web_page_previews:
|
||||||
send_messages = None
|
send_messages = None
|
||||||
embed_links = None
|
embed_links = None
|
||||||
|
|
||||||
if can_send_polls:
|
if permissions.can_send_polls:
|
||||||
send_messages = None
|
send_messages = None
|
||||||
send_polls = None
|
send_polls = None
|
||||||
|
|
||||||
if can_change_info:
|
if permissions.can_change_info:
|
||||||
change_info = None
|
change_info = None
|
||||||
|
|
||||||
if can_invite_users:
|
if permissions.can_invite_users:
|
||||||
invite_users = None
|
invite_users = None
|
||||||
|
|
||||||
if can_pin_messages:
|
if permissions.can_pin_messages:
|
||||||
pin_messages = None
|
pin_messages = None
|
||||||
|
|
||||||
r = self.send(
|
r = self.send(
|
||||||
|
@ -20,54 +20,26 @@ from typing import Union
|
|||||||
|
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions, types
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
from ...types.user_and_chats import Chat
|
from ...types.user_and_chats import Chat, ChatPermissions
|
||||||
|
|
||||||
|
|
||||||
class RestrictChat(BaseClient):
|
class SetChatPermissions(BaseClient):
|
||||||
def restrict_chat(
|
def set_chat_permissions(
|
||||||
self,
|
self,
|
||||||
chat_id: Union[int, str],
|
chat_id: Union[int, str],
|
||||||
can_send_messages: bool = False,
|
permissions: ChatPermissions,
|
||||||
can_send_media_messages: bool = False,
|
|
||||||
can_send_other_messages: bool = False,
|
|
||||||
can_add_web_page_previews: bool = False,
|
|
||||||
can_send_polls: bool = False,
|
|
||||||
can_change_info: bool = False,
|
|
||||||
can_invite_users: bool = False,
|
|
||||||
can_pin_messages: bool = False
|
|
||||||
) -> Chat:
|
) -> Chat:
|
||||||
"""Restrict a chat.
|
"""Set default chat permissions for all members.
|
||||||
Pass True for all boolean parameters to lift restrictions from a chat.
|
|
||||||
|
You must be an administrator in the group or a supergroup for this to work and must have the
|
||||||
|
*can_restrict_members* admin rights.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
chat_id (``int`` | ``str``):
|
chat_id (``int`` | ``str``):
|
||||||
Unique identifier (int) or username (str) of the target chat.
|
Unique identifier (int) or username (str) of the target chat.
|
||||||
|
|
||||||
can_send_messages (``bool``, *optional*):
|
permissions (:obj:`ChatPermissions`):
|
||||||
Pass True, if the user can send text messages, contacts, locations and venues.
|
New default chat permissions.
|
||||||
|
|
||||||
can_send_media_messages (``bool``, *optional*):
|
|
||||||
Pass True, if the user can send audios, documents, photos, videos, video notes and voice notes,
|
|
||||||
implies can_send_messages.
|
|
||||||
|
|
||||||
can_send_other_messages (``bool``, *optional*):
|
|
||||||
Pass True, if the user can send animations, games, stickers and use inline bots,
|
|
||||||
implies can_send_messages.
|
|
||||||
|
|
||||||
can_add_web_page_previews (``bool``, *optional*):
|
|
||||||
Pass True, if the user may add web page previews to their messages, implies can_send_messages.
|
|
||||||
|
|
||||||
can_send_polls (``bool``, *optional*):
|
|
||||||
Pass True, if the user can send polls, implies can_send_messages.
|
|
||||||
|
|
||||||
can_change_info (``bool``, *optional*):
|
|
||||||
Pass True, if the user can change the chat title, photo and other settings.
|
|
||||||
|
|
||||||
can_invite_users (``bool``, *optional*):
|
|
||||||
Pass True, if the user can invite new users to the chat.
|
|
||||||
|
|
||||||
can_pin_messages (``bool``, *optional*):
|
|
||||||
Pass True, if the user can pin messages.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
:obj:`Chat`: On success, a chat object is returned.
|
:obj:`Chat`: On success, a chat object is returned.
|
||||||
@ -75,11 +47,20 @@ class RestrictChat(BaseClient):
|
|||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# Completely restrict chat
|
from pyrogram import ChatPermissions
|
||||||
app.restrict_chat(chat_id)
|
|
||||||
|
|
||||||
# All chat members can only send text messages
|
# Completely restrict chat
|
||||||
app.restrict_chat(chat_id, can_send_messages=True)
|
app.set_chat_permissions(chat_id, ChatPermissions())
|
||||||
|
|
||||||
|
# Chat members can only send text messages, media, stickers and GIFs
|
||||||
|
app.set_chat_permissions(
|
||||||
|
chat_id,
|
||||||
|
ChatPermissions(
|
||||||
|
can_send_messages=True,
|
||||||
|
can_send_media_messages=True,
|
||||||
|
can_send_other_messages=True
|
||||||
|
)
|
||||||
|
)
|
||||||
"""
|
"""
|
||||||
send_messages = True
|
send_messages = True
|
||||||
send_media = True
|
send_media = True
|
||||||
@ -93,35 +74,35 @@ class RestrictChat(BaseClient):
|
|||||||
invite_users = True
|
invite_users = True
|
||||||
pin_messages = True
|
pin_messages = True
|
||||||
|
|
||||||
if can_send_messages:
|
if permissions.can_send_messages:
|
||||||
send_messages = None
|
send_messages = None
|
||||||
|
|
||||||
if can_send_media_messages:
|
if permissions.can_send_media_messages:
|
||||||
send_messages = None
|
send_messages = None
|
||||||
send_media = None
|
send_media = None
|
||||||
|
|
||||||
if can_send_other_messages:
|
if permissions.can_send_other_messages:
|
||||||
send_messages = None
|
send_messages = None
|
||||||
send_stickers = None
|
send_stickers = None
|
||||||
send_gifs = None
|
send_gifs = None
|
||||||
send_games = None
|
send_games = None
|
||||||
send_inline = None
|
send_inline = None
|
||||||
|
|
||||||
if can_add_web_page_previews:
|
if permissions.can_add_web_page_previews:
|
||||||
send_messages = None
|
send_messages = None
|
||||||
embed_links = None
|
embed_links = None
|
||||||
|
|
||||||
if can_send_polls:
|
if permissions.can_send_polls:
|
||||||
send_messages = None
|
send_messages = None
|
||||||
send_polls = None
|
send_polls = None
|
||||||
|
|
||||||
if can_change_info:
|
if permissions.can_change_info:
|
||||||
change_info = None
|
change_info = None
|
||||||
|
|
||||||
if can_invite_users:
|
if permissions.can_invite_users:
|
||||||
invite_users = None
|
invite_users = None
|
||||||
|
|
||||||
if can_pin_messages:
|
if permissions.can_pin_messages:
|
||||||
pin_messages = None
|
pin_messages = None
|
||||||
|
|
||||||
r = self.send(
|
r = self.send(
|
@ -92,7 +92,7 @@ class Chat(Object):
|
|||||||
This field is available only in case *is_restricted* is True.
|
This field is available only in case *is_restricted* is True.
|
||||||
|
|
||||||
permissions (:obj:`ChatPermissions` *optional*):
|
permissions (:obj:`ChatPermissions` *optional*):
|
||||||
Information about the chat default permissions, for groups and supergroups.
|
Default chat member permissions, for groups and supergroups.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -33,11 +33,13 @@ class ChatMember(Object):
|
|||||||
The member's status in the chat.
|
The member's status in the chat.
|
||||||
Can be "creator", "administrator", "member", "restricted", "left" or "kicked".
|
Can be "creator", "administrator", "member", "restricted", "left" or "kicked".
|
||||||
|
|
||||||
date (``int``, *optional*):
|
until_date (``int``, *optional*):
|
||||||
Date when the user joined, unix time. Not available for creator.
|
Restricted and kicked only.
|
||||||
|
Date when restrictions will be lifted for this user; unix time.
|
||||||
|
|
||||||
is_member (``bool``, *optional*):
|
joined_date (``int``, *optional*):
|
||||||
Restricted only. True, if the user is a member of the chat at the moment of the request.
|
Date when the user joined, unix time.
|
||||||
|
Not available for creator.
|
||||||
|
|
||||||
invited_by (:obj:`User`, *optional*):
|
invited_by (:obj:`User`, *optional*):
|
||||||
Administrators and self member only. Information about the user who invited this member.
|
Administrators and self member only. Information about the user who invited this member.
|
||||||
@ -49,9 +51,66 @@ class ChatMember(Object):
|
|||||||
restricted_by (:obj:`User`, *optional*):
|
restricted_by (:obj:`User`, *optional*):
|
||||||
Restricted and kicked only. Information about the user who restricted or kicked this member.
|
Restricted and kicked only. Information about the user who restricted or kicked this member.
|
||||||
|
|
||||||
permissions (:obj:`ChatPermissions` *optional*):
|
is_member (``bool``, *optional*):
|
||||||
Administrators, restricted and kicked members only.
|
Restricted only. True, if the user is a member of the chat at the moment of the request.
|
||||||
Information about the member permissions.
|
|
||||||
|
can_be_edited (``bool``, *optional*):
|
||||||
|
Administrators only.
|
||||||
|
True, if you are allowed to edit administrator privileges of the user.
|
||||||
|
|
||||||
|
can_post_messages (``bool``, *optional*):
|
||||||
|
Administrators only. Channels only.
|
||||||
|
True, if the administrator can post messages in the channel.
|
||||||
|
|
||||||
|
can_edit_messages (``bool``, *optional*):
|
||||||
|
Administrators only. Channels only.
|
||||||
|
True, if the administrator can edit messages of other users and can pin messages.
|
||||||
|
|
||||||
|
can_delete_messages (``bool``, *optional*):
|
||||||
|
Administrators only.
|
||||||
|
True, if the administrator can delete messages of other users.
|
||||||
|
|
||||||
|
can_restrict_members (``bool``, *optional*):
|
||||||
|
Administrators only.
|
||||||
|
True, if the administrator can restrict, ban or unban chat members.
|
||||||
|
|
||||||
|
can_promote_members (``bool``, *optional*):
|
||||||
|
Administrators only.
|
||||||
|
True, if the administrator can 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 the user).
|
||||||
|
|
||||||
|
can_change_info (``bool``, *optional*):
|
||||||
|
Administrators and restricted only.
|
||||||
|
True, if the user is allowed to change the chat title, photo and other settings.
|
||||||
|
|
||||||
|
can_invite_users (``bool``, *optional*):
|
||||||
|
Administrators and restricted only.
|
||||||
|
True, if the user is allowed to invite new users to the chat.
|
||||||
|
|
||||||
|
can_pin_messages (``bool``, *optional*):
|
||||||
|
Administrators and restricted only. Groups and supergroups only.
|
||||||
|
True, if the user is allowed to pin messages.
|
||||||
|
|
||||||
|
can_send_messages (``bool``, *optional*):
|
||||||
|
Restricted only.
|
||||||
|
True, if the user is allowed to send text messages, contacts, locations and venues.
|
||||||
|
|
||||||
|
can_send_media_messages (``bool``, *optional*):
|
||||||
|
Restricted only.
|
||||||
|
True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes.
|
||||||
|
|
||||||
|
can_send_other_messages (``bool``, *optional*):
|
||||||
|
Restricted only.
|
||||||
|
True, if the user is allowed to send animations, games, stickers and use inline bots.
|
||||||
|
|
||||||
|
can_add_web_page_previews (``bool``, *optional*):
|
||||||
|
Restricted only.
|
||||||
|
True, if the user is allowed to add web page previews to their messages.
|
||||||
|
|
||||||
|
can_send_polls (``bool``, *optional*):
|
||||||
|
Restricted only.
|
||||||
|
True, if the user is allowed to send polls.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -60,23 +119,57 @@ class ChatMember(Object):
|
|||||||
client: "pyrogram.BaseClient" = None,
|
client: "pyrogram.BaseClient" = None,
|
||||||
user: "pyrogram.User",
|
user: "pyrogram.User",
|
||||||
status: str,
|
status: str,
|
||||||
date: int = None,
|
until_date: int = None,
|
||||||
is_member: bool = None,
|
joined_date: int = None,
|
||||||
invited_by: "pyrogram.User" = None,
|
invited_by: "pyrogram.User" = None,
|
||||||
promoted_by: "pyrogram.User" = None,
|
promoted_by: "pyrogram.User" = None,
|
||||||
restricted_by: "pyrogram.User" = None,
|
restricted_by: "pyrogram.User" = None,
|
||||||
permissions: "pyrogram.ChatPermissions" = None
|
is_member: bool = None,
|
||||||
|
|
||||||
|
# Admin permissions
|
||||||
|
can_be_edited: bool = None,
|
||||||
|
can_post_messages: bool = None, # Channels only
|
||||||
|
can_edit_messages: bool = None, # Channels only
|
||||||
|
can_delete_messages: bool = None,
|
||||||
|
can_restrict_members: bool = None,
|
||||||
|
can_promote_members: bool = None,
|
||||||
|
can_change_info: bool = None,
|
||||||
|
can_invite_users: bool = None,
|
||||||
|
can_pin_messages: bool = None, # Groups and supergroups only
|
||||||
|
|
||||||
|
# Restricted user permissions
|
||||||
|
can_send_messages: bool = None, # Text, contacts, locations and venues
|
||||||
|
can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes
|
||||||
|
can_send_other_messages: bool = None, # Animations (GIFs), games, stickers, inline bot results
|
||||||
|
can_add_web_page_previews: bool = None,
|
||||||
|
can_send_polls: bool = None
|
||||||
):
|
):
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
|
|
||||||
self.user = user
|
self.user = user
|
||||||
self.status = status
|
self.status = status
|
||||||
self.date = date
|
self.until_date = until_date
|
||||||
self.is_member = is_member
|
self.joined_date = joined_date
|
||||||
self.invited_by = invited_by
|
self.invited_by = invited_by
|
||||||
self.promoted_by = promoted_by
|
self.promoted_by = promoted_by
|
||||||
self.restricted_by = restricted_by
|
self.restricted_by = restricted_by
|
||||||
self.permissions = permissions
|
self.is_member = is_member
|
||||||
|
|
||||||
|
self.can_be_edited = can_be_edited
|
||||||
|
self.can_post_messages = can_post_messages
|
||||||
|
self.can_edit_messages = can_edit_messages
|
||||||
|
self.can_delete_messages = can_delete_messages
|
||||||
|
self.can_restrict_members = can_restrict_members
|
||||||
|
self.can_promote_members = can_promote_members
|
||||||
|
self.can_change_info = can_change_info
|
||||||
|
self.can_invite_users = can_invite_users
|
||||||
|
self.can_pin_messages = can_pin_messages
|
||||||
|
|
||||||
|
self.can_send_messages = can_send_messages
|
||||||
|
self.can_send_media_messages = can_send_media_messages
|
||||||
|
self.can_send_other_messages = can_send_other_messages
|
||||||
|
self.can_add_web_page_previews = can_add_web_page_previews
|
||||||
|
self.can_send_polls = can_send_polls
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse(client, member, users) -> "ChatMember":
|
def _parse(client, member, users) -> "ChatMember":
|
||||||
@ -91,7 +184,7 @@ class ChatMember(Object):
|
|||||||
return ChatMember(
|
return ChatMember(
|
||||||
user=user,
|
user=user,
|
||||||
status="member",
|
status="member",
|
||||||
date=member.date,
|
joined_date=member.date,
|
||||||
invited_by=invited_by,
|
invited_by=invited_by,
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
@ -107,29 +200,52 @@ class ChatMember(Object):
|
|||||||
return ChatMember(
|
return ChatMember(
|
||||||
user=user,
|
user=user,
|
||||||
status="administrator",
|
status="administrator",
|
||||||
date=member.date,
|
joined_date=member.date,
|
||||||
invited_by=invited_by,
|
invited_by=invited_by,
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(member, types.ChannelParticipantAdmin):
|
if isinstance(member, types.ChannelParticipantAdmin):
|
||||||
|
permissions = member.admin_rights
|
||||||
|
|
||||||
return ChatMember(
|
return ChatMember(
|
||||||
user=user,
|
user=user,
|
||||||
status="administrator",
|
status="administrator",
|
||||||
date=member.date,
|
joined_date=member.date,
|
||||||
invited_by=invited_by,
|
invited_by=invited_by,
|
||||||
promoted_by=pyrogram.User._parse(client, users[member.promoted_by]),
|
promoted_by=pyrogram.User._parse(client, users[member.promoted_by]),
|
||||||
permissions=pyrogram.ChatPermissions._parse(member),
|
can_be_edited=member.can_edit,
|
||||||
|
can_change_info=permissions.change_info,
|
||||||
|
can_post_messages=permissions.post_messages,
|
||||||
|
can_edit_messages=permissions.edit_messages,
|
||||||
|
can_delete_messages=permissions.delete_messages,
|
||||||
|
can_restrict_members=permissions.ban_users,
|
||||||
|
can_invite_users=permissions.invite_users,
|
||||||
|
can_pin_messages=permissions.pin_messages,
|
||||||
|
can_promote_members=permissions.add_admins,
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(member, types.ChannelParticipantBanned):
|
if isinstance(member, types.ChannelParticipantBanned):
|
||||||
|
denied_permissions = member.banned_rights
|
||||||
|
|
||||||
return ChatMember(
|
return ChatMember(
|
||||||
user=user,
|
user=user,
|
||||||
status="kicked" if member.banned_rights.view_messages else "restricted",
|
status="kicked" if member.banned_rights.view_messages else "restricted",
|
||||||
date=member.date,
|
until_date=denied_permissions.until_date,
|
||||||
|
joined_date=member.date,
|
||||||
is_member=not member.left,
|
is_member=not member.left,
|
||||||
restricted_by=pyrogram.User._parse(client, users[member.kicked_by]),
|
restricted_by=pyrogram.User._parse(client, users[member.kicked_by]),
|
||||||
permissions=pyrogram.ChatPermissions._parse(member),
|
can_send_messages=not denied_permissions.send_messages,
|
||||||
|
can_send_media_messages=not denied_permissions.send_media,
|
||||||
|
can_send_other_messages=(
|
||||||
|
not denied_permissions.send_stickers or not denied_permissions.send_gifs or
|
||||||
|
not denied_permissions.send_games or not denied_permissions.send_inline
|
||||||
|
),
|
||||||
|
can_add_web_page_previews=not denied_permissions.embed_links,
|
||||||
|
can_send_polls=not denied_permissions.send_polls,
|
||||||
|
can_change_info=not denied_permissions.change_info,
|
||||||
|
can_invite_users=not denied_permissions.invite_users,
|
||||||
|
can_pin_messages=not denied_permissions.pin_messages,
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
|
|
||||||
@ -29,154 +27,70 @@ class ChatPermissions(Object):
|
|||||||
administrators in groups or channels.
|
administrators in groups or channels.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
until_date (``int``, *optional*):
|
|
||||||
Applicable to restricted and kicked members only.
|
|
||||||
Date when user restrictions will be lifted, unix time.
|
|
||||||
0 means the restrictions will never be lifted (user restricted forever).
|
|
||||||
|
|
||||||
can_be_edited (``bool``, *optional*):
|
|
||||||
Applicable to administrators only.
|
|
||||||
True, if you are allowed to edit administrator privileges of the user.
|
|
||||||
|
|
||||||
can_change_info (``bool``, *optional*):
|
|
||||||
Applicable to default chat permissions in private groups and administrators in public groups only.
|
|
||||||
True, if the chat title, photo and other settings can be changed.
|
|
||||||
|
|
||||||
can_post_messages (``bool``, *optional*):
|
|
||||||
Applicable to channel administrators only.
|
|
||||||
True, if the administrator can post messages in the channel, channels only.
|
|
||||||
|
|
||||||
can_edit_messages (``bool``, *optional*):
|
|
||||||
Applicable to channel administrators only.
|
|
||||||
True, if the administrator can edit messages of other users and can pin messages, channels only.
|
|
||||||
|
|
||||||
can_delete_messages (``bool``, *optional*):
|
|
||||||
Applicable to administrators only.
|
|
||||||
True, if the administrator can delete messages of other users.
|
|
||||||
|
|
||||||
can_restrict_members (``bool``, *optional*):
|
|
||||||
Applicable to administrators only.
|
|
||||||
True, if the administrator can restrict, ban or unban chat members.
|
|
||||||
|
|
||||||
can_invite_users (``bool``, *optional*):
|
|
||||||
Applicable to default chat permissions and administrators only.
|
|
||||||
True, if new users can be invited to the chat.
|
|
||||||
|
|
||||||
can_pin_messages (``bool``, *optional*):
|
|
||||||
Applicable to default chat permissions in private groups and administrators in public groups only.
|
|
||||||
True, if messages can be pinned, supergroups only.
|
|
||||||
|
|
||||||
can_promote_members (``bool``, *optional*):
|
|
||||||
Applicable to administrators only.
|
|
||||||
True, if the administrator can 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 the user).
|
|
||||||
|
|
||||||
can_send_messages (``bool``, *optional*):
|
can_send_messages (``bool``, *optional*):
|
||||||
Applicable to default chat permissions and restricted members only.
|
True, if the user is allowed to send text messages, contacts, locations and venues.
|
||||||
True, if text messages, contacts, locations and venues can be sent.
|
|
||||||
|
|
||||||
can_send_media_messages (``bool``, *optional*):
|
can_send_media_messages (``bool``, *optional*):
|
||||||
Applicable to default chat permissions and restricted members only.
|
True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies
|
||||||
True, if audios, documents, photos, videos, video notes and voice notes can be sent, implies
|
|
||||||
can_send_messages.
|
can_send_messages.
|
||||||
|
|
||||||
can_send_other_messages (``bool``, *optional*):
|
can_send_other_messages (``bool``, *optional*):
|
||||||
Applicable to default chat permissions and restricted members only.
|
True, if the user is allowed to send animations, games, stickers and use inline bots, implies
|
||||||
True, if animations, games, stickers and inline bot results can be sent, implies can_send_media_messages.
|
can_send_media_messages
|
||||||
|
|
||||||
can_add_web_page_previews (``bool``, *optional*):
|
can_add_web_page_previews (``bool``, *optional*):
|
||||||
Applicable to default chat permissions and restricted members only.
|
True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages.
|
||||||
True, if web page previews can be attached to text messages, implies can_send_media_messages.
|
|
||||||
|
|
||||||
can_send_polls (``bool``, *optional*):
|
can_send_polls (``bool``, *optional*):
|
||||||
Applicable to default chat permissions and restricted members only.
|
True, if the user is allowed to send polls, implies can_send_messages.
|
||||||
True, if polls can be sent, implies can_send_media_messages.
|
|
||||||
|
can_change_info (``bool``, *optional*):
|
||||||
|
True, if the user is allowed to change the chat title, photo and other settings.
|
||||||
|
Ignored in public supergroups.
|
||||||
|
|
||||||
|
can_invite_users (``bool``, *optional*):
|
||||||
|
True, if the user is allowed to invite new users to the chat.
|
||||||
|
|
||||||
|
can_pin_messages (``bool``, *optional*):
|
||||||
|
True, if the user is allowed to pin messages.
|
||||||
|
Ignored in public supergroups.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
until_date: int = None,
|
|
||||||
|
|
||||||
# Admin permissions
|
|
||||||
can_be_edited: bool = None,
|
|
||||||
can_change_info: bool = None,
|
|
||||||
can_post_messages: bool = None, # Channels only
|
|
||||||
can_edit_messages: bool = None, # Channels only
|
|
||||||
can_delete_messages: bool = None,
|
|
||||||
can_restrict_members: bool = None,
|
|
||||||
can_invite_users: bool = None,
|
|
||||||
can_pin_messages: bool = None, # Supergroups only
|
|
||||||
can_promote_members: bool = None,
|
|
||||||
|
|
||||||
# Restricted user permissions
|
|
||||||
can_send_messages: bool = None, # Text, contacts, locations and venues
|
can_send_messages: bool = None, # Text, contacts, locations and venues
|
||||||
can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes
|
can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes
|
||||||
can_send_other_messages: bool = None, # Animations (GIFs), games, stickers, inline bot results
|
can_send_other_messages: bool = None, # Animations (GIFs), games, stickers, inline bot results
|
||||||
can_add_web_page_previews: bool = None,
|
can_add_web_page_previews: bool = None,
|
||||||
can_send_polls: bool = None
|
can_send_polls: bool = None,
|
||||||
|
can_change_info: bool = None,
|
||||||
|
can_invite_users: bool = None,
|
||||||
|
can_pin_messages: bool = None
|
||||||
):
|
):
|
||||||
super().__init__(None)
|
super().__init__(None)
|
||||||
|
|
||||||
self.until_date = until_date
|
|
||||||
self.can_be_edited = can_be_edited
|
|
||||||
|
|
||||||
self.can_change_info = can_change_info
|
|
||||||
self.can_post_messages = can_post_messages
|
|
||||||
self.can_edit_messages = can_edit_messages
|
|
||||||
self.can_delete_messages = can_delete_messages
|
|
||||||
self.can_restrict_members = can_restrict_members
|
|
||||||
self.can_invite_users = can_invite_users
|
|
||||||
self.can_pin_messages = can_pin_messages
|
|
||||||
self.can_promote_members = can_promote_members
|
|
||||||
|
|
||||||
self.can_send_messages = can_send_messages
|
self.can_send_messages = can_send_messages
|
||||||
self.can_send_media_messages = can_send_media_messages
|
self.can_send_media_messages = can_send_media_messages
|
||||||
self.can_send_other_messages = can_send_other_messages
|
self.can_send_other_messages = can_send_other_messages
|
||||||
self.can_add_web_page_previews = can_add_web_page_previews
|
self.can_add_web_page_previews = can_add_web_page_previews
|
||||||
self.can_send_polls = can_send_polls
|
self.can_send_polls = can_send_polls
|
||||||
|
self.can_change_info = can_change_info
|
||||||
|
self.can_invite_users = can_invite_users
|
||||||
|
self.can_pin_messages = can_pin_messages
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse(
|
def _parse(denied_permissions: types.ChatBannedRights) -> "ChatPermissions":
|
||||||
entity: Union[
|
return ChatPermissions(
|
||||||
types.ChannelParticipantAdmin,
|
can_send_messages=not denied_permissions.send_messages,
|
||||||
types.ChannelParticipantBanned,
|
can_send_media_messages=not denied_permissions.send_media,
|
||||||
types.ChatBannedRights
|
can_send_other_messages=(
|
||||||
]
|
not denied_permissions.send_stickers or not denied_permissions.send_gifs or
|
||||||
) -> "ChatPermissions":
|
not denied_permissions.send_games or not denied_permissions.send_inline
|
||||||
if isinstance(entity, types.ChannelParticipantAdmin):
|
),
|
||||||
permissions = entity.admin_rights
|
can_add_web_page_previews=not denied_permissions.embed_links,
|
||||||
|
can_send_polls=not denied_permissions.send_polls,
|
||||||
return ChatPermissions(
|
can_change_info=not denied_permissions.change_info,
|
||||||
can_be_edited=entity.can_edit,
|
can_invite_users=not denied_permissions.invite_users,
|
||||||
can_change_info=permissions.change_info,
|
can_pin_messages=not denied_permissions.pin_messages
|
||||||
can_post_messages=permissions.post_messages,
|
)
|
||||||
can_edit_messages=permissions.edit_messages,
|
|
||||||
can_delete_messages=permissions.delete_messages,
|
|
||||||
can_restrict_members=permissions.ban_users,
|
|
||||||
can_invite_users=permissions.invite_users,
|
|
||||||
can_pin_messages=permissions.pin_messages,
|
|
||||||
can_promote_members=permissions.add_admins
|
|
||||||
)
|
|
||||||
|
|
||||||
if isinstance(entity, (types.ChannelParticipantBanned, types.ChatBannedRights)):
|
|
||||||
if isinstance(entity, types.ChannelParticipantBanned):
|
|
||||||
denied_permissions = entity.banned_rights # type: types.ChatBannedRights
|
|
||||||
else:
|
|
||||||
denied_permissions = entity
|
|
||||||
|
|
||||||
return ChatPermissions(
|
|
||||||
until_date=0 if denied_permissions.until_date == (1 << 31) - 1 else denied_permissions.until_date,
|
|
||||||
can_send_messages=not denied_permissions.send_messages,
|
|
||||||
can_send_media_messages=not denied_permissions.send_media,
|
|
||||||
can_send_other_messages=(
|
|
||||||
not denied_permissions.send_stickers or not denied_permissions.send_gifs or
|
|
||||||
not denied_permissions.send_games or not denied_permissions.send_inline
|
|
||||||
),
|
|
||||||
can_add_web_page_previews=not denied_permissions.embed_links,
|
|
||||||
can_send_polls=not denied_permissions.send_polls,
|
|
||||||
can_change_info=not denied_permissions.change_info,
|
|
||||||
can_invite_users=not denied_permissions.invite_users,
|
|
||||||
can_pin_messages=not denied_permissions.pin_messages
|
|
||||||
)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user