Telethon/telethon/events/messagedeleted.py

35 lines
1.0 KiB
Python
Raw Normal View History

2018-04-05 21:14:22 +03:00
from .common import EventBuilder, EventCommon, name_inner_event
from ..tl import types
@name_inner_event
class MessageDeleted(EventBuilder):
"""
Event fired when one or more messages are deleted.
"""
2018-07-19 02:47:32 +03:00
@classmethod
def build(cls, update):
2018-04-05 21:14:22 +03:00
if isinstance(update, types.UpdateDeleteMessages):
2018-07-19 02:47:32 +03:00
event = cls.Event(
2018-04-05 21:14:22 +03:00
deleted_ids=update.messages,
peer=None
)
elif isinstance(update, types.UpdateDeleteChannelMessages):
2018-07-19 02:47:32 +03:00
event = cls.Event(
2018-04-05 21:14:22 +03:00
deleted_ids=update.messages,
peer=types.PeerChannel(update.channel_id)
)
else:
return
event._entities = update._entities
2018-07-11 12:22:43 +03:00
return event
2018-04-05 21:14:22 +03:00
class Event(EventCommon):
def __init__(self, deleted_ids, peer):
super().__init__(
chat_peer=peer, msg_id=(deleted_ids or [0])[0]
)
self.deleted_id = None if not deleted_ids else deleted_ids[0]
self.deleted_ids = deleted_ids