Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Return the service message produced when kicking somebody
- Loading branch information
Showing
with
18 additions
and
8 deletions.
-
+16
−6
telethon/client/chats.py
-
+2
−2
telethon/client/messageparse.py
|
|
@@ -1135,11 +1135,16 @@ async def kick_participant( |
|
|
user (`entity`, optional): |
|
|
The user to kick. |
|
|
|
|
|
Returns |
|
|
Returns the service `Message <telethon.tl.custom.message.Message>` |
|
|
produced about a user being kicked, if any. |
|
|
|
|
|
Example |
|
|
.. code-block:: python |
|
|
|
|
|
# Kick some user from some chat |
|
|
await client.kick_participant(chat, user) |
|
|
# Kick some user from some chat, and deleting the service message |
|
|
msg = await client.kick_participant(chat, user) |
|
|
await msg.delete() |
|
|
|
|
|
# Leaving chat |
|
|
await client.kick_participant(chat, 'me') |
|
|
@@ -1151,15 +1156,18 @@ async def kick_participant( |
|
|
|
|
|
ty = helpers._entity_type(entity) |
|
|
if ty == helpers._EntityType.CHAT: |
|
|
await self(functions.messages.DeleteChatUserRequest(entity.chat_id, user)) |
|
|
resp = await self(functions.messages.DeleteChatUserRequest(entity.chat_id, user)) |
|
|
elif ty == helpers._EntityType.CHANNEL: |
|
|
if isinstance(user, types.InputPeerSelf): |
|
|
await self(functions.channels.LeaveChannelRequest(entity)) |
|
|
# Despite no longer being in the channel, the account still |
|
|
# seems to get the service message. |
|
|
resp = await self(functions.channels.LeaveChannelRequest(entity)) |
|
|
else: |
|
|
await self(functions.channels.EditBannedRequest( |
|
|
resp = await self(functions.channels.EditBannedRequest( |
|
|
channel=entity, |
|
|
user_id=user, |
|
|
banned_rights=types.ChatBannedRights(until_date=None, view_messages=True) |
|
|
banned_rights=types.ChatBannedRights( |
|
|
until_date=None, view_messages=True) |
|
|
)) |
|
|
await asyncio.sleep(0.5) |
|
|
await self(functions.channels.EditBannedRequest( |
|
|
@@ -1170,6 +1178,8 @@ async def kick_participant( |
|
|
else: |
|
|
raise ValueError('You must pass either a channel or a chat') |
|
|
|
|
|
return self._get_response_message(None, resp, entity) |
|
|
|
|
|
async def get_permissions( |
|
|
self: 'TelegramClient', |
|
|
entity: 'hints.EntityLike', |
|
|
|
|
|
@@ -67,7 +67,7 @@ async def _replace_with_mention(self: 'TelegramClient', entities, i, user): |
|
|
entities[i].offset, entities[i].length, |
|
|
await self.get_input_entity(user) |
|
|
) |
|
|
return True |
|
|
return True |
|
|
except (ValueError, TypeError): |
|
|
return False |
|
|
|
|
|
@@ -134,7 +134,7 @@ def _get_response_message(self: 'TelegramClient', request, result, input_chat): |
|
|
|
|
|
# Pinning a message with `updatePinnedMessage` seems to |
|
|
# always produce a service message we can't map so return |
|
|
# it directly. |
|
|
# it directly. The same happens for kicking users. |
|
|
# |
|
|
# It could also be a list (e.g. when sending albums). |
|
|
# |
|
|
|