mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Update Chat and ChatPermissions to accommodate default chat permissions
This commit is contained in:
parent
8c9e5e6753
commit
b6038c4f2e
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
|
from .chat_permissions import ChatPermissions
|
||||||
from .chat_photo import ChatPhoto
|
from .chat_photo import ChatPhoto
|
||||||
from ..pyrogram_type import PyrogramType
|
from ..pyrogram_type import PyrogramType
|
||||||
|
|
||||||
@ -44,9 +45,6 @@ class Chat(PyrogramType):
|
|||||||
last_name (``str``, *optional*):
|
last_name (``str``, *optional*):
|
||||||
Last name of the other party in a private chat.
|
Last name of the other party in a private chat.
|
||||||
|
|
||||||
all_members_are_administrators (``bool``, *optional*):
|
|
||||||
True if a basic group has "All Members Are Admins" enabled.
|
|
||||||
|
|
||||||
photo (:obj:`ChatPhoto <pyrogram.ChatPhoto>`, *optional*):
|
photo (:obj:`ChatPhoto <pyrogram.ChatPhoto>`, *optional*):
|
||||||
Chat photo. Suitable for downloads only.
|
Chat photo. Suitable for downloads only.
|
||||||
|
|
||||||
@ -86,7 +84,6 @@ class Chat(PyrogramType):
|
|||||||
username: str = None,
|
username: str = None,
|
||||||
first_name: str = None,
|
first_name: str = None,
|
||||||
last_name: str = None,
|
last_name: str = None,
|
||||||
all_members_are_administrators: bool = None,
|
|
||||||
photo: ChatPhoto = None,
|
photo: ChatPhoto = None,
|
||||||
description: str = None,
|
description: str = None,
|
||||||
invite_link: str = None,
|
invite_link: str = None,
|
||||||
@ -94,7 +91,8 @@ class Chat(PyrogramType):
|
|||||||
sticker_set_name: str = None,
|
sticker_set_name: str = None,
|
||||||
can_set_sticker_set: bool = None,
|
can_set_sticker_set: bool = None,
|
||||||
members_count: int = None,
|
members_count: int = None,
|
||||||
restriction_reason: str = None):
|
restriction_reason: str = None,
|
||||||
|
default_permissions: "pyrogram.ChatPermissions" = None):
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
|
|
||||||
self.id = id
|
self.id = id
|
||||||
@ -103,7 +101,6 @@ class Chat(PyrogramType):
|
|||||||
self.username = username
|
self.username = username
|
||||||
self.first_name = first_name
|
self.first_name = first_name
|
||||||
self.last_name = last_name
|
self.last_name = last_name
|
||||||
self.all_members_are_administrators = all_members_are_administrators
|
|
||||||
self.photo = photo
|
self.photo = photo
|
||||||
self.description = description
|
self.description = description
|
||||||
self.invite_link = invite_link
|
self.invite_link = invite_link
|
||||||
@ -112,6 +109,7 @@ class Chat(PyrogramType):
|
|||||||
self.can_set_sticker_set = can_set_sticker_set
|
self.can_set_sticker_set = can_set_sticker_set
|
||||||
self.members_count = members_count
|
self.members_count = members_count
|
||||||
self.restriction_reason = restriction_reason
|
self.restriction_reason = restriction_reason
|
||||||
|
self.default_permissions = default_permissions
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_user_chat(client, user: types.User) -> "Chat":
|
def _parse_user_chat(client, user: types.User) -> "Chat":
|
||||||
@ -128,17 +126,12 @@ class Chat(PyrogramType):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_chat_chat(client, chat: types.Chat) -> "Chat":
|
def _parse_chat_chat(client, chat: types.Chat) -> "Chat":
|
||||||
admins_enabled = getattr(chat, "admins_enabled", None)
|
|
||||||
|
|
||||||
if admins_enabled is not None:
|
|
||||||
admins_enabled = not admins_enabled
|
|
||||||
|
|
||||||
return Chat(
|
return Chat(
|
||||||
id=-chat.id,
|
id=-chat.id,
|
||||||
type="group",
|
type="group",
|
||||||
title=chat.title,
|
title=chat.title,
|
||||||
all_members_are_administrators=admins_enabled,
|
|
||||||
photo=ChatPhoto._parse(client, getattr(chat, "photo", None)),
|
photo=ChatPhoto._parse(client, getattr(chat, "photo", None)),
|
||||||
|
default_permissions=ChatPermissions._parse(chat.default_banned_rights),
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -151,6 +144,7 @@ class Chat(PyrogramType):
|
|||||||
username=getattr(channel, "username", None),
|
username=getattr(channel, "username", None),
|
||||||
photo=ChatPhoto._parse(client, getattr(channel, "photo", None)),
|
photo=ChatPhoto._parse(client, getattr(channel, "photo", None)),
|
||||||
restriction_reason=getattr(channel, "restriction_reason", None),
|
restriction_reason=getattr(channel, "restriction_reason", None),
|
||||||
|
default_permissions=ChatPermissions._parse(channel.default_banned_rights),
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -138,12 +138,18 @@ class ChatPermissions(PyrogramType):
|
|||||||
self.can_send_polls = can_send_polls
|
self.can_send_polls = can_send_polls
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse(member: Union[types.ChannelParticipantAdmin, types.ChannelParticipantBanned]) -> "ChatPermissions":
|
def _parse(
|
||||||
if isinstance(member, types.ChannelParticipantAdmin):
|
entity: Union[
|
||||||
permissions = member.admin_rights
|
types.ChannelParticipantAdmin,
|
||||||
|
types.ChannelParticipantBanned,
|
||||||
|
types.ChatBannedRights
|
||||||
|
]
|
||||||
|
) -> "ChatPermissions":
|
||||||
|
if isinstance(entity, types.ChannelParticipantAdmin):
|
||||||
|
permissions = entity.admin_rights
|
||||||
|
|
||||||
return ChatPermissions(
|
return ChatPermissions(
|
||||||
can_be_edited=member.can_edit,
|
can_be_edited=entity.can_edit,
|
||||||
can_change_info=permissions.change_info,
|
can_change_info=permissions.change_info,
|
||||||
can_post_messages=permissions.post_messages,
|
can_post_messages=permissions.post_messages,
|
||||||
can_edit_messages=permissions.edit_messages,
|
can_edit_messages=permissions.edit_messages,
|
||||||
@ -154,8 +160,11 @@ class ChatPermissions(PyrogramType):
|
|||||||
can_promote_members=permissions.add_admins
|
can_promote_members=permissions.add_admins
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(member, types.ChannelParticipantBanned):
|
if isinstance(entity, (types.ChannelParticipantBanned, types.ChatBannedRights)):
|
||||||
denied_permissions = member.banned_rights # type: types.ChatBannedRights
|
if isinstance(entity, types.ChannelParticipantBanned):
|
||||||
|
denied_permissions = entity.banned_rights # type: types.ChatBannedRights
|
||||||
|
else:
|
||||||
|
denied_permissions = entity
|
||||||
|
|
||||||
return ChatPermissions(
|
return ChatPermissions(
|
||||||
until_date=0 if denied_permissions.until_date == (1 << 31) - 1 else denied_permissions.until_date,
|
until_date=0 if denied_permissions.until_date == (1 << 31) - 1 else denied_permissions.until_date,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user