diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 73b5a578..57f4827f 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -88,7 +88,7 @@ def generate(source_path, base): inner_path = base + "/" + k + "/index" + ".rst" module = "pyrogram.api.{}.{}".format(base, k) else: - for i in list(all_entities)[::-1]: + for i in sorted(list(all_entities), reverse=True): if i != base: entities.insert(0, "{0}/index".format(i)) diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index ed332838..3ef57b83 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -66,4 +66,5 @@ MEDIA_CAPTION_TOO_LONG The media caption is longer than 200 characters USER_NOT_MUTUAL_CONTACT The user is not a mutual contact USER_CHANNELS_TOO_MUCH The user is already in too many channels or supergroups API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server side -USER_NOT_PARTICIPANT The user is not a member of this chat \ No newline at end of file +USER_NOT_PARTICIPANT The user is not a member of this chat +CHANNEL_PRIVATE The channel/supergroup is not accessible \ No newline at end of file diff --git a/compiler/error/source/403_FORBIDDEN.tsv b/compiler/error/source/403_FORBIDDEN.tsv index 7bacbe7d..a2d06832 100644 --- a/compiler/error/source/403_FORBIDDEN.tsv +++ b/compiler/error/source/403_FORBIDDEN.tsv @@ -1,2 +1,4 @@ id message -CHAT_WRITE_FORBIDDEN You don't have rights to send messages in this chat \ No newline at end of file +CHAT_WRITE_FORBIDDEN You don't have rights to send messages in this chat +RIGHT_FORBIDDEN One or more admin rights can't be applied to this kind of chat (channel/supergroup) +CHAT_ADMIN_INVITE_REQUIRED You don't have rights to invite other users \ No newline at end of file diff --git a/pyrogram/api/core/object.py b/pyrogram/api/core/object.py index 3cf12329..a1e20726 100644 --- a/pyrogram/api/core/object.py +++ b/pyrogram/api/core/object.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -import logging from collections import OrderedDict from datetime import datetime from io import BytesIO @@ -24,23 +23,13 @@ from json import JSONEncoder, dumps from ..all import objects -log = logging.getLogger(__name__) - class Object: all = {} @staticmethod def read(b: BytesIO, *args): - constructor_id = int.from_bytes(b.read(4), "little") - - try: - return Object.all[constructor_id].read(b, *args) - except KeyError: - log.error("Unknown constructor found: {}. Full data: {}".format( - hex(constructor_id), - b.getvalue().hex()) - ) + return Object.all[int.from_bytes(b.read(4), "little")].read(b, *args) def write(self, *args) -> bytes: pass diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index b03e73c6..3115648a 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -42,7 +42,7 @@ from pyrogram.api.errors import ( PhoneNumberUnoccupied, PhoneCodeInvalid, PhoneCodeHashEmpty, PhoneCodeExpired, PhoneCodeEmpty, SessionPasswordNeeded, PasswordHashInvalid, FloodWait, PeerIdInvalid, FirstnameInvalid, PhoneNumberBanned, - VolumeLocNotFound, UserMigrate, FileIdInvalid) + VolumeLocNotFound, UserMigrate, FileIdInvalid, ChannelPrivate) from pyrogram.crypto import AES from pyrogram.session import Auth, Session from .dispatcher import Dispatcher @@ -801,23 +801,26 @@ class Client(Methods, BaseClient): message = update.message if not isinstance(message, types.MessageEmpty): - diff = await self.send( - functions.updates.GetChannelDifference( - channel=await self.resolve_peer(int("-100" + str(channel_id))), - filter=types.ChannelMessagesFilter( - ranges=[types.MessageRange( - min_id=update.message.id, - max_id=update.message.id - )] - ), - pts=pts - pts_count, - limit=pts + try: + diff = await self.send( + functions.updates.GetChannelDifference( + channel=await self.resolve_peer(int("-100" + str(channel_id))), + filter=types.ChannelMessagesFilter( + ranges=[types.MessageRange( + min_id=update.message.id, + max_id=update.message.id + )] + ), + pts=pts - pts_count, + limit=pts + ) ) - ) - - if not isinstance(diff, types.updates.ChannelDifferenceEmpty): - updates.users += diff.users - updates.chats += diff.chats + except ChannelPrivate: + pass + else: + if not isinstance(diff, types.updates.ChannelDifferenceEmpty): + updates.users += diff.users + updates.chats += diff.chats if channel_id and pts: if channel_id not in self.channels_pts: diff --git a/pyrogram/client/dispatcher/dispatcher.py b/pyrogram/client/dispatcher/dispatcher.py index 2b597a72..e4d03881 100644 --- a/pyrogram/client/dispatcher/dispatcher.py +++ b/pyrogram/client/dispatcher/dispatcher.py @@ -90,43 +90,46 @@ class Dispatcher: tasks = [] for group in self.groups.values(): - for handler in group: - if is_raw: - if not isinstance(handler, RawUpdateHandler): - continue - - args = (self.client, update, users, chats) - else: - message = (update.message - or update.channel_post - or update.edited_message - or update.edited_channel_post) - - deleted_messages = (update.deleted_channel_posts - or update.deleted_messages) - - callback_query = update.callback_query - - if message and isinstance(handler, MessageHandler): - if not handler.check(message): + try: + for handler in group: + if is_raw: + if not isinstance(handler, RawUpdateHandler): continue - args = (self.client, message) - elif deleted_messages and isinstance(handler, DeletedMessagesHandler): - if not handler.check(deleted_messages): - continue - - args = (self.client, deleted_messages) - elif callback_query and isinstance(handler, CallbackQueryHandler): - if not handler.check(callback_query): - continue - - args = (self.client, callback_query) + args = (self.client, update, users, chats) else: - continue + message = (update.message + or update.channel_post + or update.edited_message + or update.edited_channel_post) - tasks.append(handler.callback(*args)) - break + deleted_messages = (update.deleted_channel_posts + or update.deleted_messages) + + callback_query = update.callback_query + + if message and isinstance(handler, MessageHandler): + if not handler.check(message): + continue + + args = (self.client, message) + elif deleted_messages and isinstance(handler, DeletedMessagesHandler): + if not handler.check(deleted_messages): + continue + + args = (self.client, deleted_messages) + elif callback_query and isinstance(handler, CallbackQueryHandler): + if not handler.check(callback_query): + continue + + args = (self.client, callback_query) + else: + continue + + tasks.append(handler.callback(*args)) + break + except Exception as e: + log.error(e, exc_info=True) await asyncio.gather(*tasks) diff --git a/pyrogram/client/methods/chats/promote_chat_member.py b/pyrogram/client/methods/chats/promote_chat_member.py index 172e126a..2afa5fe3 100644 --- a/pyrogram/client/methods/chats/promote_chat_member.py +++ b/pyrogram/client/methods/chats/promote_chat_member.py @@ -25,12 +25,12 @@ class PromoteChatMember(BaseClient): chat_id: int or str, user_id: int or str, can_change_info: bool = True, - can_post_messages: bool = True, - can_edit_messages: bool = True, + can_post_messages: bool = False, + can_edit_messages: bool = False, can_delete_messages: bool = True, can_invite_users: bool = True, can_restrict_members: bool = True, - can_pin_messages: bool = True, + can_pin_messages: bool = False, can_promote_members: bool = False): """Use this method to promote or demote a user in a supergroup or a channel. You must be an administrator in the chat for this to work and must have the appropriate admin rights.