2022-01-28 13:34:16 +03:00
|
|
|
from .base import EventBuilder
|
2021-09-12 13:16:02 +03:00
|
|
|
from .. import _tl
|
2022-01-28 13:34:16 +03:00
|
|
|
from ..types import _custom
|
2018-04-05 21:14:22 +03:00
|
|
|
|
|
|
|
|
2022-01-28 13:34:16 +03:00
|
|
|
class MessageDeleted(EventBuilder, _custom.chatgetter.ChatGetter):
|
2018-04-05 21:14:22 +03:00
|
|
|
"""
|
2019-06-11 12:09:22 +03:00
|
|
|
Occurs whenever a message is deleted. Note that this event isn't 100%
|
|
|
|
reliable, since Telegram doesn't always notify the clients that a message
|
|
|
|
was deleted.
|
2019-05-07 22:25:55 +03:00
|
|
|
|
|
|
|
.. important::
|
|
|
|
|
|
|
|
Telegram **does not** send information about *where* a message
|
|
|
|
was deleted if it occurs in private conversations with other users
|
|
|
|
or in small group chats, because message IDs are *unique* and you
|
|
|
|
can identify the chat with the message ID alone if you saved it
|
|
|
|
previously.
|
|
|
|
|
|
|
|
Telethon **does not** save information of where messages occur,
|
|
|
|
so it cannot know in which chat a message was deleted (this will
|
|
|
|
only work in channels, where the channel ID *is* present).
|
|
|
|
|
|
|
|
This means that the ``chats=`` parameter will not work reliably,
|
|
|
|
unless you intend on working with channels and super-groups only.
|
2020-02-20 12:18:26 +03:00
|
|
|
|
|
|
|
Example
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
from telethon import events
|
|
|
|
|
|
|
|
@client.on(events.MessageDeleted)
|
|
|
|
async def handler(event):
|
|
|
|
# Log all deleted message IDs
|
|
|
|
for msg_id in event.deleted_ids:
|
|
|
|
print('Message', msg_id, 'was deleted in', event.chat_id)
|
2018-04-05 21:14:22 +03:00
|
|
|
"""
|
2018-07-19 02:47:32 +03:00
|
|
|
@classmethod
|
2022-02-15 13:57:55 +03:00
|
|
|
def _build(cls, client, update, entities):
|
2021-09-12 13:16:02 +03:00
|
|
|
if isinstance(update, _tl.UpdateDeleteMessages):
|
2022-02-15 13:57:55 +03:00
|
|
|
peer = None
|
2021-09-12 13:16:02 +03:00
|
|
|
elif isinstance(update, _tl.UpdateDeleteChannelMessages):
|
2022-02-15 13:57:55 +03:00
|
|
|
peer = _tl.PeerChannel(update.channel_id)
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
self = cls.__new__(cls)
|
|
|
|
self._client = client
|
|
|
|
self._chat = entities.get(peer)
|
|
|
|
self.deleted_id = None if not update.messages else update.messages[0]
|
|
|
|
self.deleted_ids = update.messages
|
|
|
|
return self
|