mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-05 04:30:22 +03:00
Implemented delete_messages
This commit is contained in:
parent
3805aa3772
commit
c69eb02f2a
|
@ -1,9 +1,11 @@
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from mimetypes import guess_type
|
from mimetypes import guess_type
|
||||||
|
|
||||||
import re
|
from .tl.functions import channels
|
||||||
|
from .tl.functions import messages
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import socks
|
import socks
|
||||||
|
@ -346,6 +348,40 @@ class TelegramClient(TelegramBareClient):
|
||||||
|
|
||||||
return None # Should not happen
|
return None # Should not happen
|
||||||
|
|
||||||
|
def delete_messages(self, entity, message_ids, revoke=True):
|
||||||
|
"""
|
||||||
|
Deletes a message from a chat, optionally "for everyone" with argument
|
||||||
|
`revoke` set to `True`.
|
||||||
|
|
||||||
|
The `revoke` argument has no effect for Channels and Supergroups,
|
||||||
|
where it inherently behaves as being `True`.
|
||||||
|
|
||||||
|
Note: The `entity` argument can be `None` for normal chats, but it's
|
||||||
|
mandatory to delete messages from Channels and Supergroups. It is also
|
||||||
|
possible to supply a chat_id which will be automatically resolved to
|
||||||
|
the right type of InputPeer.
|
||||||
|
|
||||||
|
:param entity: ID or Entity of the chat
|
||||||
|
:param list message_ids: IDs (or a single ID) of the message to delete
|
||||||
|
:param revoke: Delete the message for everyone or just this client
|
||||||
|
:returns messages.AffectedMessages: Messages affected by deletion.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not isinstance(message_ids, list):
|
||||||
|
message_ids = [message_ids]
|
||||||
|
|
||||||
|
if entity is None:
|
||||||
|
return self(messages.DeleteMessagesRequest(message_ids, revoke=revoke))
|
||||||
|
|
||||||
|
entity = self.get_input_entity(entity)
|
||||||
|
|
||||||
|
if isinstance(entity, InputPeerChannel):
|
||||||
|
return self(channels.DeleteMessagesRequest(entity, message_ids))
|
||||||
|
else:
|
||||||
|
return self(messages.DeleteMessagesRequest(message_ids, revoke=revoke))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_message_history(self,
|
def get_message_history(self,
|
||||||
entity,
|
entity,
|
||||||
limit=20,
|
limit=20,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user