mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-11 14:58:11 +03:00
Cleanup events code
This commit is contained in:
parent
8d1379f3d4
commit
8de375323e
|
@ -444,9 +444,10 @@ class EventBuilderDict:
|
|||
return self.__dict__[builder]
|
||||
except KeyError:
|
||||
event = self.__dict__[builder] = builder.build(
|
||||
self.update, self.others, self.client._session_state.user_id)
|
||||
self.update, self.others, self.client._session_state.user_id, self.entities or {}, self.client)
|
||||
|
||||
if isinstance(event, EventCommon):
|
||||
# TODO eww
|
||||
event.original_update = self.update
|
||||
event._entities = self.entities or {}
|
||||
event._set_client(self.client)
|
||||
|
|
|
@ -96,7 +96,7 @@ class Album(EventBuilder):
|
|||
super().__init__(chats, blacklist_chats=blacklist_chats, func=func)
|
||||
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
def build(cls, update, others=None, self_id=None, *todo, **todo2):
|
||||
if not others:
|
||||
return # We only care about albums which come inside the same Updates
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ class CallbackQuery(EventBuilder):
|
|||
))
|
||||
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
def build(cls, update, others=None, self_id=None, *todo, **todo2):
|
||||
if isinstance(update, _tl.UpdateBotCallbackQuery):
|
||||
return cls.Event(update, update.peer, update.msg_id)
|
||||
elif isinstance(update, _tl.UpdateInlineBotCallbackQuery):
|
||||
|
|
|
@ -33,7 +33,7 @@ class ChatAction(EventBuilder):
|
|||
"""
|
||||
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
def build(cls, update, others=None, self_id=None, *todo, **todo2):
|
||||
# Rely on specific pin updates for unpins, but otherwise ignore them
|
||||
# for new pins (we'd rather handle the new service message with pin,
|
||||
# so that we can act on that message').
|
||||
|
@ -206,9 +206,6 @@ class ChatAction(EventBuilder):
|
|||
self.new_score = new_score
|
||||
self.unpin = not pin
|
||||
|
||||
def _set_client(self, client):
|
||||
super()._set_client(client)
|
||||
|
||||
async def respond(self, *args, **kwargs):
|
||||
"""
|
||||
Responds to the chat action message (not as a reply). Shorthand for
|
||||
|
|
|
@ -67,7 +67,7 @@ class EventBuilder(abc.ABC):
|
|||
|
||||
@classmethod
|
||||
@abc.abstractmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
def build(cls, update, others, self_id, entities, client):
|
||||
"""
|
||||
Builds an event for the given update if possible, or returns None.
|
||||
|
||||
|
@ -144,6 +144,7 @@ class EventCommon(ChatGetter, abc.ABC):
|
|||
"""
|
||||
Setter so subclasses can act accordingly when the client is set.
|
||||
"""
|
||||
# TODO Nuke
|
||||
self._client = client
|
||||
if self._chat_peer:
|
||||
self._chat, self._input_chat = utils._get_entity_pair(
|
||||
|
|
|
@ -61,7 +61,7 @@ class InlineQuery(EventBuilder):
|
|||
raise TypeError('Invalid pattern type given')
|
||||
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
def build(cls, update, others=None, self_id=None, *todo, **todo2):
|
||||
if isinstance(update, _tl.UpdateBotInlineQuery):
|
||||
return cls.Event(update)
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class MessageDeleted(EventBuilder):
|
|||
print('Message', msg_id, 'was deleted in', event.chat_id)
|
||||
"""
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
def build(cls, update, others=None, self_id=None, *todo, **todo2):
|
||||
if isinstance(update, _tl.UpdateDeleteMessages):
|
||||
return cls.Event(
|
||||
deleted_ids=update.messages,
|
||||
|
|
|
@ -43,7 +43,7 @@ class MessageEdited(NewMessage):
|
|||
print('Message', event.id, 'changed at', event.date)
|
||||
"""
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
def build(cls, update, others=None, self_id=None, *todo, **todo2):
|
||||
if isinstance(update, (_tl.UpdateEditMessage,
|
||||
_tl.UpdateEditChannelMessage)):
|
||||
return cls.Event(update.message)
|
||||
|
|
|
@ -35,7 +35,7 @@ class MessageRead(EventBuilder):
|
|||
self.inbox = inbox
|
||||
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
def build(cls, update, others=None, self_id=None, *todo, **todo2):
|
||||
if isinstance(update, _tl.UpdateReadHistoryInbox):
|
||||
return cls.Event(update.peer, update.max_id, False)
|
||||
elif isinstance(update, _tl.UpdateReadHistoryOutbox):
|
||||
|
|
|
@ -95,14 +95,14 @@ class NewMessage(EventBuilder):
|
|||
self.from_users = await _into_id_set(client, self.from_users)
|
||||
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
def build(cls, update, others, self_id, entities, client):
|
||||
if isinstance(update,
|
||||
(_tl.UpdateNewMessage, _tl.UpdateNewChannelMessage)):
|
||||
if not isinstance(update.message, _tl.Message):
|
||||
return # We don't care about MessageService's here
|
||||
event = cls.Event(update.message)
|
||||
msg = update.message
|
||||
elif isinstance(update, _tl.UpdateShortMessage):
|
||||
event = cls.Event(_tl.Message(
|
||||
msg = _tl.Message(
|
||||
out=update.out,
|
||||
mentioned=update.mentioned,
|
||||
media_unread=update.media_unread,
|
||||
|
@ -117,9 +117,9 @@ class NewMessage(EventBuilder):
|
|||
reply_to=update.reply_to,
|
||||
entities=update.entities,
|
||||
ttl_period=update.ttl_period
|
||||
))
|
||||
)
|
||||
elif isinstance(update, _tl.UpdateShortChatMessage):
|
||||
event = cls.Event(_tl.Message(
|
||||
msg = _tl.Message(
|
||||
out=update.out,
|
||||
mentioned=update.mentioned,
|
||||
media_unread=update.media_unread,
|
||||
|
@ -134,11 +134,11 @@ class NewMessage(EventBuilder):
|
|||
reply_to=update.reply_to,
|
||||
entities=update.entities,
|
||||
ttl_period=update.ttl_period
|
||||
))
|
||||
)
|
||||
else:
|
||||
return
|
||||
|
||||
return event
|
||||
return cls.Event(_custom.Message._new(client, msg, entities, None))
|
||||
|
||||
def filter(self, event):
|
||||
if self._no_check:
|
||||
|
|
|
@ -42,7 +42,7 @@ class Raw(EventBuilder):
|
|||
self.resolved = True
|
||||
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
def build(cls, update, others=None, self_id=None, *todo, **todo2):
|
||||
return update
|
||||
|
||||
def filter(self, event):
|
||||
|
|
|
@ -49,7 +49,7 @@ class UserUpdate(EventBuilder):
|
|||
await client.send_message(event.user_id, 'What are you sending?')
|
||||
"""
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
def build(cls, update, others=None, self_id=None, *todo, **todo2):
|
||||
if isinstance(update, _tl.UpdateUserStatus):
|
||||
return cls.Event(_tl.PeerUser(update.user_id),
|
||||
status=update.status)
|
||||
|
|
Loading…
Reference in New Issue
Block a user