mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-09 13:29:47 +00:00
Update to layer 129 and other additions/enhancements (#3074)
* Apply code corrections for the new layer types. * Support not passing `user` to `get_permissions`. * `download_profile_photo` now supports `MessageService`. * `thumb` in send and edit message. * Document new known errors.
This commit is contained in:
@@ -162,11 +162,15 @@ class _ParticipantsIter(RequestIter):
|
||||
|
||||
users = {user.id: user for user in full.users}
|
||||
for participant in full.full_chat.participants.participants:
|
||||
user = users[participant.user_id]
|
||||
if isinstance(participant, types.ChannelParticipantBanned):
|
||||
user_id = participant.peer.user_id
|
||||
else:
|
||||
user_id = participant.user_id
|
||||
user = users[user_id]
|
||||
if not self.filter_entity(user):
|
||||
continue
|
||||
|
||||
user = users[participant.user_id]
|
||||
user = users[user_id]
|
||||
user.participant = participant
|
||||
self.buffer.append(user)
|
||||
|
||||
@@ -207,12 +211,17 @@ class _ParticipantsIter(RequestIter):
|
||||
self.requests[i].offset += len(participants.participants)
|
||||
users = {user.id: user for user in participants.users}
|
||||
for participant in participants.participants:
|
||||
user = users[participant.user_id]
|
||||
|
||||
if isinstance(participant, types.ChannelParticipantBanned):
|
||||
user_id = participant.peer.user_id
|
||||
else:
|
||||
user_id = participant.user_id
|
||||
|
||||
user = users[user_id]
|
||||
if not self.filter_entity(user) or user.id in self.seen:
|
||||
continue
|
||||
|
||||
self.seen.add(participant.user_id)
|
||||
user = users[participant.user_id]
|
||||
self.seen.add(user_id)
|
||||
user = users[user_id]
|
||||
user.participant = participant
|
||||
self.buffer.append(user)
|
||||
|
||||
@@ -475,6 +484,7 @@ class ChatMethods:
|
||||
|
||||
get_participants.__signature__ = inspect.signature(iter_participants)
|
||||
|
||||
|
||||
def iter_admin_log(
|
||||
self: 'TelegramClient',
|
||||
entity: 'hints.EntityLike',
|
||||
@@ -789,7 +799,8 @@ class ChatMethods:
|
||||
try:
|
||||
action = _ChatAction._str_mapping[action.lower()]
|
||||
except KeyError:
|
||||
raise ValueError('No such action "{}"'.format(action)) from None
|
||||
raise ValueError(
|
||||
'No such action "{}"'.format(action)) from None
|
||||
elif not isinstance(action, types.TLObject) or action.SUBCLASS_OF_ID != 0x20b2cc21:
|
||||
# 0x20b2cc21 = crc32(b'SendMessageAction')
|
||||
if isinstance(action, type):
|
||||
@@ -954,7 +965,8 @@ class ChatMethods:
|
||||
entity, user, is_admin=is_admin))
|
||||
|
||||
else:
|
||||
raise ValueError('You can only edit permissions in groups and channels')
|
||||
raise ValueError(
|
||||
'You can only edit permissions in groups and channels')
|
||||
|
||||
async def edit_permissions(
|
||||
self: 'TelegramClient',
|
||||
@@ -1108,7 +1120,7 @@ class ChatMethods:
|
||||
|
||||
return await self(functions.channels.EditBannedRequest(
|
||||
channel=entity,
|
||||
user_id=user,
|
||||
participant=user,
|
||||
banned_rights=rights
|
||||
))
|
||||
|
||||
@@ -1165,14 +1177,14 @@ class ChatMethods:
|
||||
else:
|
||||
resp = await self(functions.channels.EditBannedRequest(
|
||||
channel=entity,
|
||||
user_id=user,
|
||||
participant=user,
|
||||
banned_rights=types.ChatBannedRights(
|
||||
until_date=None, view_messages=True)
|
||||
))
|
||||
await asyncio.sleep(0.5)
|
||||
await self(functions.channels.EditBannedRequest(
|
||||
channel=entity,
|
||||
user_id=user,
|
||||
participant=user,
|
||||
banned_rights=types.ChatBannedRights(until_date=None)
|
||||
))
|
||||
else:
|
||||
@@ -1183,10 +1195,11 @@ class ChatMethods:
|
||||
async def get_permissions(
|
||||
self: 'TelegramClient',
|
||||
entity: 'hints.EntityLike',
|
||||
user: 'hints.EntityLike'
|
||||
user: 'hints.EntityLike' = None
|
||||
) -> 'typing.Optional[custom.ParticipantPermissions]':
|
||||
"""
|
||||
Fetches the permissions of a user in a specific chat or channel.
|
||||
Fetches the permissions of a user in a specific chat or channel or
|
||||
get Default Restricted Rights of Chat or Channel.
|
||||
|
||||
.. note::
|
||||
|
||||
@@ -1197,7 +1210,7 @@ class ChatMethods:
|
||||
entity (`entity`):
|
||||
The channel or chat the user is participant of.
|
||||
|
||||
user (`entity`):
|
||||
user (`entity`, optional):
|
||||
Target user.
|
||||
|
||||
Returns
|
||||
@@ -1211,7 +1224,21 @@ class ChatMethods:
|
||||
permissions = await client.get_permissions(chat, user)
|
||||
if permissions.is_admin:
|
||||
# do something
|
||||
|
||||
# Get Banned Permissions of Chat
|
||||
await client.get_permissions(chat)
|
||||
"""
|
||||
entity = await self.get_entity(entity)
|
||||
|
||||
if not user:
|
||||
if isinstance(entity, types.Channel):
|
||||
FullChat = await self(functions.channels.GetFullChannelRequest(entity))
|
||||
elif isinstance(entity, types.Chat):
|
||||
FullChat = await self(functions.messages.GetFullChatRequest(entity))
|
||||
else:
|
||||
return
|
||||
return FullChat.chats[0].default_banned_rights
|
||||
|
||||
entity = await self.get_input_entity(entity)
|
||||
user = await self.get_input_entity(user)
|
||||
if helpers._entity_type(user) != helpers._EntityType.USER:
|
||||
|
@@ -271,11 +271,9 @@ class DownloadMethods:
|
||||
|
||||
if isinstance(photo, (types.UserProfilePhoto, types.ChatPhoto)):
|
||||
dc_id = photo.dc_id
|
||||
which = photo.photo_big if download_big else photo.photo_small
|
||||
loc = types.InputPeerPhotoFileLocation(
|
||||
peer=await self.get_input_entity(entity),
|
||||
local_id=which.local_id,
|
||||
volume_id=which.volume_id,
|
||||
photo_id=photo.photo_id,
|
||||
big=download_big
|
||||
)
|
||||
else:
|
||||
@@ -400,6 +398,11 @@ class DownloadMethods:
|
||||
if isinstance(media, str):
|
||||
media = utils.resolve_bot_file_id(media)
|
||||
|
||||
if isinstance(media, types.MessageService):
|
||||
if isinstance(message.action,
|
||||
types.MessageActionChatEditPhoto):
|
||||
media = media.photo
|
||||
|
||||
if isinstance(media, types.MessageMediaWebPage):
|
||||
if isinstance(media.webpage, types.WebPage):
|
||||
media = media.webpage.document or media.webpage.photo
|
||||
|
@@ -603,6 +603,7 @@ class MessageMethods:
|
||||
formatting_entities: typing.Optional[typing.List[types.TypeMessageEntity]] = None,
|
||||
link_preview: bool = True,
|
||||
file: 'typing.Union[hints.FileLike, typing.Sequence[hints.FileLike]]' = None,
|
||||
thumb: 'hints.FileLike' = None,
|
||||
force_document: bool = False,
|
||||
clear_draft: bool = False,
|
||||
buttons: 'hints.MarkupLike' = None,
|
||||
@@ -664,6 +665,17 @@ class MessageMethods:
|
||||
Sends a message with a file attached (e.g. a photo,
|
||||
video, audio or document). The ``message`` may be empty.
|
||||
|
||||
thumb (`str` | `bytes` | `file`, optional):
|
||||
Optional JPEG thumbnail (for documents). **Telegram will
|
||||
ignore this parameter** unless you pass a ``.jpg`` file!
|
||||
The file must also be small in dimensions and in disk size.
|
||||
Successful thumbnails were files below 20kB and 320x320px.
|
||||
Width/height and dimensions/size ratios may be important.
|
||||
For Telegram to accept a thumbnail, you must provide the
|
||||
dimensions of the underlying media through ``attributes=``
|
||||
with :tl:`DocumentAttributesVideo` or by installing the
|
||||
optional ``hachoir`` dependency.
|
||||
|
||||
force_document (`bool`, optional):
|
||||
Whether to send the given file as a document or not.
|
||||
|
||||
@@ -772,7 +784,7 @@ class MessageMethods:
|
||||
return await self.send_file(
|
||||
entity, file, caption=message, reply_to=reply_to,
|
||||
attributes=attributes, parse_mode=parse_mode,
|
||||
force_document=force_document,
|
||||
force_document=force_document, thumb=thumb,
|
||||
buttons=buttons, clear_draft=clear_draft, silent=silent,
|
||||
schedule=schedule, supports_streaming=supports_streaming,
|
||||
formatting_entities=formatting_entities,
|
||||
@@ -986,6 +998,7 @@ class MessageMethods:
|
||||
formatting_entities: typing.Optional[typing.List[types.TypeMessageEntity]] = None,
|
||||
link_preview: bool = True,
|
||||
file: 'hints.FileLike' = None,
|
||||
thumb: 'hints.FileLike' = None,
|
||||
force_document: bool = False,
|
||||
buttons: 'hints.MarkupLike' = None,
|
||||
supports_streaming: bool = False,
|
||||
@@ -1038,6 +1051,17 @@ class MessageMethods:
|
||||
The file object that should replace the existing media
|
||||
in the message.
|
||||
|
||||
thumb (`str` | `bytes` | `file`, optional):
|
||||
Optional JPEG thumbnail (for documents). **Telegram will
|
||||
ignore this parameter** unless you pass a ``.jpg`` file!
|
||||
The file must also be small in dimensions and in disk size.
|
||||
Successful thumbnails were files below 20kB and 320x320px.
|
||||
Width/height and dimensions/size ratios may be important.
|
||||
For Telegram to accept a thumbnail, you must provide the
|
||||
dimensions of the underlying media through ``attributes=``
|
||||
with :tl:`DocumentAttributesVideo` or by installing the
|
||||
optional ``hachoir`` dependency.
|
||||
|
||||
force_document (`bool`, optional):
|
||||
Whether to send the given file as a document or not.
|
||||
|
||||
@@ -1102,6 +1126,7 @@ class MessageMethods:
|
||||
text, formatting_entities = await self._parse_message_text(text, parse_mode)
|
||||
file_handle, media, image = await self._file_to_media(file,
|
||||
supports_streaming=supports_streaming,
|
||||
thumb=thumb,
|
||||
attributes=attributes,
|
||||
force_document=force_document)
|
||||
|
||||
|
Reference in New Issue
Block a user