diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index e9d099d1..fa2c7af8 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -1364,7 +1364,4 @@ langpack.getLanguage#6a596502 lang_pack:string lang_code:string = LangPackLangua folders.editPeerFolders#6847d0ab folder_peers:Vector = Updates; folders.deleteFolder#1c295881 folder_id:int = Updates; -// LAYER 103 - -// Ports -channels.exportInvite#c7560885 channel:InputChannel = ExportedChatInvite; \ No newline at end of file +// LAYER 103 \ No newline at end of file diff --git a/compiler/api/source/sys_msgs.tl b/compiler/api/source/sys_msgs.tl index 067ab91e..6a3f6325 100644 --- a/compiler/api/source/sys_msgs.tl +++ b/compiler/api/source/sys_msgs.tl @@ -53,6 +53,15 @@ ipPortSecret#37982646 ipv4:int port:int secret:bytes = IpPort; accessPointRule#4679b65f phone_prefix_rules:string dc_id:int ips:vector = AccessPointRule; help.configSimple#5a592a6c date:int expires:int rules:vector = help.ConfigSimple; +// tlsClientHello blocks:vector = TlsClientHello; +// +// tlsBlockString data:string = TlsBlock; +// tlsBlockRandom length:int = TlsBlock; +// tlsBlockZero length:int = TlsBlock; +// tlsBlockDomain = TlsBlock; +// tlsBlockGrease seed:int = TlsBlock; +// tlsBlockScope entries:Vector = TlsBlock; + ---functions--- rpc_drop_answer#58e4a740 req_msg_id:long = RpcDropAnswer; diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index cb3ad5a2..e515dc77 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -146,7 +146,6 @@ def pyrogram_api(): send_audio send_document send_sticker - send_animated_sticker send_video send_animation send_voice @@ -190,6 +189,7 @@ def pyrogram_api(): delete_chat_photo set_chat_title set_chat_description + set_chat_permissions pin_chat_message unpin_chat_message get_chat @@ -200,7 +200,6 @@ def pyrogram_api(): get_dialogs iter_dialogs get_dialogs_count - restrict_chat update_chat_username archive_chats unarchive_chats diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index a7fc2792..fddb48ce 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -38,9 +38,9 @@ from .kick_chat_member import KickChatMember from .leave_chat import LeaveChat from .pin_chat_message import PinChatMessage from .promote_chat_member import PromoteChatMember -from .restrict_chat import RestrictChat from .restrict_chat_member import RestrictChatMember from .set_chat_description import SetChatDescription +from .set_chat_permissions import SetChatPermissions from .set_chat_photo import SetChatPhoto from .set_chat_title import SetChatTitle from .unarchive_chats import UnarchiveChats @@ -71,7 +71,7 @@ class Chats( IterDialogs, IterChatMembers, UpdateChatUsername, - RestrictChat, + SetChatPermissions, GetDialogsCount, ArchiveChats, UnarchiveChats, diff --git a/pyrogram/client/methods/chats/export_chat_invite_link.py b/pyrogram/client/methods/chats/export_chat_invite_link.py index 22586ae6..1d477021 100644 --- a/pyrogram/client/methods/chats/export_chat_invite_link.py +++ b/pyrogram/client/methods/chats/export_chat_invite_link.py @@ -57,17 +57,11 @@ class ExportChatInviteLink(BaseClient): """ peer = await self.resolve_peer(chat_id) - if isinstance(peer, types.InputPeerChat): + if isinstance(peer, (types.InputPeerChat, types.InputPeerChannel)): return (await self.send( functions.messages.ExportChatInvite( peer=peer ) )).link - elif isinstance(peer, types.InputPeerChannel): - return (await self.send( - functions.channels.ExportInvite( - channel=peer - ) - )).link else: raise ValueError('The chat_id "{}" belongs to a user'.format(chat_id)) diff --git a/pyrogram/client/methods/chats/restrict_chat_member.py b/pyrogram/client/methods/chats/restrict_chat_member.py index 35c5da72..4910e385 100644 --- a/pyrogram/client/methods/chats/restrict_chat_member.py +++ b/pyrogram/client/methods/chats/restrict_chat_member.py @@ -20,7 +20,7 @@ from typing import Union from pyrogram.api import functions, types from ...ext import BaseClient -from ...types.user_and_chats import Chat +from ...types.user_and_chats import Chat, ChatPermissions class RestrictChatMember(BaseClient): @@ -28,20 +28,13 @@ class RestrictChatMember(BaseClient): self, chat_id: Union[int, str], user_id: Union[int, str], - until_date: int = 0, - can_send_messages: bool = False, - 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 + permissions: ChatPermissions, + until_date: int = 0 ) -> Chat: """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. - Pass True for all boolean parameters to lift restrictions from a user. + You must be an administrator in the supergroup for this to work and must have the appropriate admin rights. + Pass True for all permissions to lift restrictions from a user. Parameters: chat_id (``int`` | ``str``): @@ -51,37 +44,14 @@ class RestrictChatMember(BaseClient): 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). + permissions (:obj:`ChatPermissions`): + New user permissions. + until_date (``int``, *optional*): 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 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: :obj:`Chat`: On success, a chat object is returned. @@ -90,14 +60,16 @@ class RestrictChatMember(BaseClient): from time import time - # Completely restrict chat member forever - app.restrict_chat_member(chat_id, user_id) + from pyrogram import ChatPermissions - # Chat member can't send messages for 24h - app.restrict_chat_member(chat_id, user_id, int(time.time() + 86400)) + # Completely restrict chat member (mute) forever + 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 - 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_media = True @@ -111,35 +83,35 @@ class RestrictChatMember(BaseClient): invite_users = True pin_messages = True - if can_send_messages: + if permissions.can_send_messages: send_messages = None - if can_send_media_messages: + if permissions.can_send_media_messages: send_messages = None send_media = None - if can_send_other_messages: + if permissions.can_send_other_messages: send_messages = None send_stickers = None send_gifs = None send_games = None send_inline = None - if can_add_web_page_previews: + if permissions.can_add_web_page_previews: send_messages = None embed_links = None - if can_send_polls: + if permissions.can_send_polls: send_messages = None send_polls = None - if can_change_info: + if permissions.can_change_info: change_info = None - if can_invite_users: + if permissions.can_invite_users: invite_users = None - if can_pin_messages: + if permissions.can_pin_messages: pin_messages = None r = await self.send( diff --git a/pyrogram/client/methods/chats/restrict_chat.py b/pyrogram/client/methods/chats/set_chat_permissions.py similarity index 56% rename from pyrogram/client/methods/chats/restrict_chat.py rename to pyrogram/client/methods/chats/set_chat_permissions.py index 20acd5e1..158cc269 100644 --- a/pyrogram/client/methods/chats/restrict_chat.py +++ b/pyrogram/client/methods/chats/set_chat_permissions.py @@ -20,54 +20,26 @@ from typing import Union from pyrogram.api import functions, types from ...ext import BaseClient -from ...types.user_and_chats import Chat +from ...types.user_and_chats import Chat, ChatPermissions -class RestrictChat(BaseClient): - def restrict_chat( +class SetChatPermissions(BaseClient): + async def set_chat_permissions( self, chat_id: Union[int, str], - can_send_messages: bool = False, - 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 + permissions: ChatPermissions, ) -> Chat: - """Restrict a chat. - Pass True for all boolean parameters to lift restrictions from a chat. + """Set default chat permissions for all members. + + 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: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - 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. + permissions (:obj:`ChatPermissions`): + New default chat permissions. Returns: :obj:`Chat`: On success, a chat object is returned. @@ -75,11 +47,20 @@ class RestrictChat(BaseClient): Example: .. code-block:: python - # Completely restrict chat - app.restrict_chat(chat_id) + from pyrogram import ChatPermissions - # All chat members can only send text messages - app.restrict_chat(chat_id, can_send_messages=True) + # Completely restrict chat + 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_media = True @@ -93,38 +74,38 @@ class RestrictChat(BaseClient): invite_users = True pin_messages = True - if can_send_messages: + if permissions.can_send_messages: send_messages = None - if can_send_media_messages: + if permissions.can_send_media_messages: send_messages = None send_media = None - if can_send_other_messages: + if permissions.can_send_other_messages: send_messages = None send_stickers = None send_gifs = None send_games = None send_inline = None - if can_add_web_page_previews: + if permissions.can_add_web_page_previews: send_messages = None embed_links = None - if can_send_polls: + if permissions.can_send_polls: send_messages = None send_polls = None - if can_change_info: + if permissions.can_change_info: change_info = None - if can_invite_users: + if permissions.can_invite_users: invite_users = None - if can_pin_messages: + if permissions.can_pin_messages: pin_messages = None - r = self.send( + r = await self.send( functions.messages.EditChatDefaultBannedRights( peer=self.resolve_peer(chat_id), banned_rights=types.ChatBannedRights( diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index aa0b0c94..6237b47c 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -33,7 +33,6 @@ from .get_messages import GetMessages from .iter_history import IterHistory from .read_history import ReadHistory from .retract_vote import RetractVote -from .send_animated_sticker import SendAnimatedSticker from .send_animation import SendAnimation from .send_audio import SendAudio from .send_cached_media import SendCachedMedia @@ -85,7 +84,6 @@ class Messages( IterHistory, SendCachedMedia, GetHistoryCount, - SendAnimatedSticker, ReadHistory, EditInlineText, EditInlineCaption, diff --git a/pyrogram/client/methods/messages/send_animated_sticker.py b/pyrogram/client/methods/messages/send_animated_sticker.py deleted file mode 100644 index 8e57c527..00000000 --- a/pyrogram/client/methods/messages/send_animated_sticker.py +++ /dev/null @@ -1,144 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2019 Dan Tès -# -# This file is part of Pyrogram. -# -# Pyrogram is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pyrogram 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 General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with Pyrogram. If not, see . - -import os -from typing import Union - -import pyrogram -from pyrogram.api import functions, types -from pyrogram.client.ext import BaseClient, utils -from pyrogram.errors import FilePartMissing - - -class SendAnimatedSticker(BaseClient): - def send_animated_sticker( - self, - chat_id: Union[int, str], - animated_sticker: str, - disable_notification: bool = None, - reply_to_message_id: int = None, - reply_markup: Union[ - "pyrogram.InlineKeyboardMarkup", - "pyrogram.ReplyKeyboardMarkup", - "pyrogram.ReplyKeyboardRemove", - "pyrogram.ForceReply" - ] = None, - progress: callable = None, - progress_args: tuple = () - ) -> Union["pyrogram.Message", None]: - """Send .tgs animated stickers. - - Parameters: - chat_id (``int`` | ``str``): - Unique identifier (int) or username (str) of the target chat. - For your personal cloud (Saved Messages) you can simply use "me" or "self". - For a contact that exists in your Telegram address book you can use his phone number (str). - - animated_sticker (``str``): - Animated sticker to send. - Pass a file_id as string to send a animated sticker that exists on the Telegram servers, - pass an HTTP URL as a string for Telegram to get a .webp animated sticker file from the Internet, or - pass a file path as string to upload a new animated sticker that exists on your local machine. - - disable_notification (``bool``, *optional*): - Sends the message silently. - Users will receive a notification with no sound. - - reply_to_message_id (``int``, *optional*): - If the message is a reply, ID of the original message. - - reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): - Additional interface options. An object for an inline keyboard, custom reply keyboard, - instructions to remove reply keyboard or to force a reply from the user. - - progress (``callable``, *optional*): - Pass a callback function to view the file transmission progress. - The function must take *(current, total)* as positional arguments (look at Other Parameters below for a - detailed description) and will be called back each time a new file chunk has been successfully - transmitted. - - progress_args (``tuple``, *optional*): - Extra custom arguments for the progress callback function. - You can pass anything you need to be available in the progress callback scope; for example, a Message - object or a Client instance in order to edit the message with the updated progress status. - - Other Parameters: - current (``int``): - The amount of bytes transmitted so far. - - total (``int``): - The total size of the file. - - *args (``tuple``, *optional*): - Extra custom arguments as defined in the *progress_args* parameter. - You can either keep *\*args* or add every single extra argument in your function signature. - - Returns: - :obj:`Message` | ``None``: On success, the sent animated sticker message is returned, otherwise, in case the - upload is deliberately stopped with :meth:`~Client.stop_transmission`, None is returned. - - Example: - .. code-block:: python - - # Send animated sticker by uploading from local file - app.send_animated_sticker("me", "animated_sticker.tgs") - """ - file = None - - try: - if os.path.exists(animated_sticker): - file = self.save_file(animated_sticker, progress=progress, progress_args=progress_args) - media = types.InputMediaUploadedDocument( - mime_type=self.guess_mime_type(animated_sticker) or "application/x-tgsticker", - file=file, - attributes=[ - types.DocumentAttributeFilename(file_name=os.path.basename(animated_sticker)) - ] - ) - elif animated_sticker.startswith("http"): - media = types.InputMediaDocumentExternal( - url=animated_sticker - ) - else: - media = utils.get_input_media_from_file_id(animated_sticker, 5) - - while True: - try: - r = self.send( - functions.messages.SendMedia( - peer=self.resolve_peer(chat_id), - media=media, - silent=disable_notification or None, - reply_to_msg_id=reply_to_message_id, - random_id=self.rnd_id(), - reply_markup=reply_markup.write() if reply_markup else None, - message="" - ) - ) - except FilePartMissing as e: - self.save_file(animated_sticker, file_id=file.id, file_part=e.x) - else: - for i in r.updates: - if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message._parse( - self, i.message, - {i.id: i for i in r.users}, - {i.id: i for i in r.chats} - ) - except BaseClient.StopTransmission: - return None diff --git a/pyrogram/client/methods/messages/send_sticker.py b/pyrogram/client/methods/messages/send_sticker.py index 845b12bd..7cca77d5 100644 --- a/pyrogram/client/methods/messages/send_sticker.py +++ b/pyrogram/client/methods/messages/send_sticker.py @@ -41,7 +41,7 @@ class SendSticker(BaseClient): progress: callable = None, progress_args: tuple = () ) -> Union["pyrogram.Message", None]: - """Send .webp stickers. + """Send static .webp or animated .tgs stickers. Parameters: chat_id (``int`` | ``str``): diff --git a/pyrogram/client/types/messages_and_media/sticker.py b/pyrogram/client/types/messages_and_media/sticker.py index 4a9f6d8c..b1015199 100644 --- a/pyrogram/client/types/messages_and_media/sticker.py +++ b/pyrogram/client/types/messages_and_media/sticker.py @@ -42,6 +42,9 @@ class Sticker(Object): height (``int``): Sticker height. + is_animated (``bool``): + True, if the sticker is animated + file_name (``str``, *optional*): Sticker file name. @@ -73,6 +76,7 @@ class Sticker(Object): file_id: str, width: int, height: int, + is_animated: bool, file_name: str = None, mime_type: str = None, file_size: int = None, @@ -90,6 +94,7 @@ class Sticker(Object): self.date = date self.width = width self.height = height + self.is_animated = is_animated self.emoji = emoji self.set_name = set_name self.thumbs = thumbs @@ -131,8 +136,9 @@ class Sticker(Object): sticker.access_hash ) ), - width=image_size_attributes.w if image_size_attributes else 0, - height=image_size_attributes.h if image_size_attributes else 0, + width=image_size_attributes.w if image_size_attributes else 512, + height=image_size_attributes.h if image_size_attributes else 512, + is_animated=sticker.mime_type == "application/x-tgsticker", # TODO: mask_position set_name=set_name, emoji=sticker_attributes.alt or None, diff --git a/pyrogram/client/types/user_and_chats/chat.py b/pyrogram/client/types/user_and_chats/chat.py index d3606b82..fbd22c66 100644 --- a/pyrogram/client/types/user_and_chats/chat.py +++ b/pyrogram/client/types/user_and_chats/chat.py @@ -92,7 +92,7 @@ class Chat(Object): This field is available only in case *is_restricted* is True. permissions (:obj:`ChatPermissions` *optional*): - Information about the chat default permissions, for groups and supergroups. + Default chat member permissions, for groups and supergroups. """ def __init__( @@ -231,6 +231,7 @@ class Chat(Object): if isinstance(full_chat, types.ChatFull): parsed_chat = Chat._parse_chat_chat(client, chat) + parsed_chat.description = full_chat.about or None if isinstance(full_chat.participants, types.ChatParticipants): parsed_chat.members_count = len(full_chat.participants.participants) diff --git a/pyrogram/client/types/user_and_chats/chat_member.py b/pyrogram/client/types/user_and_chats/chat_member.py index 42eb08f3..812a3204 100644 --- a/pyrogram/client/types/user_and_chats/chat_member.py +++ b/pyrogram/client/types/user_and_chats/chat_member.py @@ -33,11 +33,13 @@ class ChatMember(Object): The member's status in the chat. Can be "creator", "administrator", "member", "restricted", "left" or "kicked". - date (``int``, *optional*): - Date when the user joined, unix time. Not available for creator. + until_date (``int``, *optional*): + Restricted and kicked only. + Date when restrictions will be lifted for this user; unix time. - is_member (``bool``, *optional*): - Restricted only. True, if the user is a member of the chat at the moment of the request. + joined_date (``int``, *optional*): + Date when the user joined, unix time. + Not available for creator. invited_by (:obj:`User`, *optional*): 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 and kicked only. Information about the user who restricted or kicked this member. - permissions (:obj:`ChatPermissions` *optional*): - Administrators, restricted and kicked members only. - Information about the member permissions. + is_member (``bool``, *optional*): + Restricted only. True, if the user is a member of the chat at the moment of the request. + + 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__( @@ -60,23 +119,57 @@ class ChatMember(Object): client: "pyrogram.BaseClient" = None, user: "pyrogram.User", status: str, - date: int = None, - is_member: bool = None, + until_date: int = None, + joined_date: int = None, invited_by: "pyrogram.User" = None, promoted_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) self.user = user self.status = status - self.date = date - self.is_member = is_member + self.until_date = until_date + self.joined_date = joined_date self.invited_by = invited_by self.promoted_by = promoted_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 def _parse(client, member, users) -> "ChatMember": @@ -91,7 +184,7 @@ class ChatMember(Object): return ChatMember( user=user, status="member", - date=member.date, + joined_date=member.date, invited_by=invited_by, client=client ) @@ -107,29 +200,52 @@ class ChatMember(Object): return ChatMember( user=user, status="administrator", - date=member.date, + joined_date=member.date, invited_by=invited_by, client=client ) if isinstance(member, types.ChannelParticipantAdmin): + permissions = member.admin_rights + return ChatMember( user=user, status="administrator", - date=member.date, + joined_date=member.date, invited_by=invited_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 ) if isinstance(member, types.ChannelParticipantBanned): + denied_permissions = member.banned_rights + return ChatMember( user=user, 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, 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 ) diff --git a/pyrogram/client/types/user_and_chats/chat_permissions.py b/pyrogram/client/types/user_and_chats/chat_permissions.py index 551dc667..09c33089 100644 --- a/pyrogram/client/types/user_and_chats/chat_permissions.py +++ b/pyrogram/client/types/user_and_chats/chat_permissions.py @@ -16,8 +16,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Union - from pyrogram.api import types from ..object import Object @@ -29,145 +27,62 @@ class ChatPermissions(Object): administrators in groups or channels. 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*): - Applicable to default chat permissions and restricted members only. - True, if text messages, contacts, locations and venues can be sent. + True, if the user is allowed to send text messages, contacts, locations and venues. can_send_media_messages (``bool``, *optional*): - Applicable to default chat permissions and restricted members only. - True, if audios, documents, photos, videos, video notes and voice notes can be sent, implies + True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages. can_send_other_messages (``bool``, *optional*): - Applicable to default chat permissions and restricted members only. - True, if animations, games, stickers and inline bot results can be sent, implies can_send_media_messages. + True, if the user is allowed to send animations, games, stickers and use inline bots, implies + can_send_media_messages can_add_web_page_previews (``bool``, *optional*): - Applicable to default chat permissions and restricted members only. - True, if web page previews can be attached to text messages, implies can_send_media_messages. + True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages. can_send_polls (``bool``, *optional*): - Applicable to default chat permissions and restricted members only. - True, if polls can be sent, implies can_send_media_messages. + True, if the user is allowed to send polls, implies can_send_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__( 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_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 + can_send_polls: bool = None, + can_change_info: bool = None, + can_invite_users: bool = None, + can_pin_messages: bool = 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_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 + self.can_change_info = can_change_info + self.can_invite_users = can_invite_users + self.can_pin_messages = can_pin_messages @staticmethod - def _parse( - entity: Union[ - types.ChannelParticipantAdmin, - types.ChannelParticipantBanned, - types.ChatBannedRights - ] - ) -> "ChatPermissions": - if isinstance(entity, types.ChannelParticipantAdmin): - permissions = entity.admin_rights - + def _parse(denied_permissions: types.ChatBannedRights) -> "ChatPermissions": + if isinstance(denied_permissions, types.ChatBannedRights): return ChatPermissions( - can_be_edited=entity.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 - ) - - 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=( diff --git a/pyrogram/client/types/user_and_chats/chat_photo.py b/pyrogram/client/types/user_and_chats/chat_photo.py index 70e114af..623aaca8 100644 --- a/pyrogram/client/types/user_and_chats/chat_photo.py +++ b/pyrogram/client/types/user_and_chats/chat_photo.py @@ -29,10 +29,12 @@ class ChatPhoto(Object): Parameters: small_file_id (``str``): - Unique file identifier of small (160x160) chat photo. This file_id can be used only for photo download. + File identifier of small (160x160) chat photo. + This file_id can be used only for photo download and only for as long as the photo is not changed. big_file_id (``str``): - Unique file identifier of big (640x640) chat photo. This file_id can be used only for photo download. + File identifier of big (640x640) chat photo. + This file_id can be used only for photo download and only for as long as the photo is not changed. """ def __init__(