mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Use custom.Message in events
This commit is contained in:
parent
b241d80958
commit
9e4854fcce
|
@ -1,6 +1,6 @@
|
||||||
from .common import EventBuilder, EventCommon, name_inner_event
|
from .common import EventBuilder, EventCommon, name_inner_event
|
||||||
from .. import utils
|
from .. import utils
|
||||||
from ..tl import types, functions
|
from ..tl import types, functions, custom
|
||||||
|
|
||||||
|
|
||||||
@name_inner_event
|
@name_inner_event
|
||||||
|
@ -158,6 +158,12 @@ class ChatAction(EventBuilder):
|
||||||
self.new_title = new_title
|
self.new_title = new_title
|
||||||
self.unpin = unpin
|
self.unpin = unpin
|
||||||
|
|
||||||
|
def _set_client(self, client):
|
||||||
|
super()._set_client(client)
|
||||||
|
if self.action_message:
|
||||||
|
self.action_message = custom.Message(
|
||||||
|
client, self.action_message, self._entities, None)
|
||||||
|
|
||||||
def respond(self, *args, **kwargs):
|
def respond(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Responds to the chat action message (not as a reply). Shorthand for
|
Responds to the chat action message (not as a reply). Shorthand for
|
||||||
|
|
|
@ -103,6 +103,12 @@ class EventCommon(abc.ABC):
|
||||||
)
|
)
|
||||||
self.is_channel = isinstance(chat_peer, types.PeerChannel)
|
self.is_channel = isinstance(chat_peer, types.PeerChannel)
|
||||||
|
|
||||||
|
def _set_client(self, client):
|
||||||
|
"""
|
||||||
|
Setter so subclasses can act accordingly when the client is set.
|
||||||
|
"""
|
||||||
|
self._client = client
|
||||||
|
|
||||||
def _get_entity(self, msg_id, entity_id, chat=None):
|
def _get_entity(self, msg_id, entity_id, chat=None):
|
||||||
"""
|
"""
|
||||||
Helper function to call :tl:`GetMessages` on the give msg_id and
|
Helper function to call :tl:`GetMessages` on the give msg_id and
|
||||||
|
|
|
@ -100,16 +100,9 @@ class MessageRead(EventBuilder):
|
||||||
chat = self.input_chat
|
chat = self.input_chat
|
||||||
if not chat:
|
if not chat:
|
||||||
self._messages = []
|
self._messages = []
|
||||||
elif isinstance(chat, types.InputPeerChannel):
|
|
||||||
self._messages =\
|
|
||||||
self._client(functions.channels.GetMessagesRequest(
|
|
||||||
chat, self._message_ids
|
|
||||||
)).messages
|
|
||||||
else:
|
else:
|
||||||
self._messages =\
|
self._messages = self._client.get_messages(
|
||||||
self._client(functions.messages.GetMessagesRequest(
|
chat, ids=self._message_ids)
|
||||||
self._message_ids
|
|
||||||
)).messages
|
|
||||||
|
|
||||||
return self._messages
|
return self._messages
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import re
|
||||||
from .common import EventBuilder, EventCommon, name_inner_event
|
from .common import EventBuilder, EventCommon, name_inner_event
|
||||||
from .. import utils
|
from .. import utils
|
||||||
from ..extensions import markdown
|
from ..extensions import markdown
|
||||||
from ..tl import types, functions
|
from ..tl import types, functions, custom
|
||||||
|
|
||||||
|
|
||||||
@name_inner_event
|
@name_inner_event
|
||||||
|
@ -154,6 +154,11 @@ class NewMessage(EventBuilder):
|
||||||
self.is_reply = bool(message.reply_to_msg_id)
|
self.is_reply = bool(message.reply_to_msg_id)
|
||||||
self._reply_message = None
|
self._reply_message = None
|
||||||
|
|
||||||
|
def _set_client(self, client):
|
||||||
|
super()._set_client(client)
|
||||||
|
self.message = custom.Message(
|
||||||
|
client, self.message, self._entities, None)
|
||||||
|
|
||||||
def respond(self, *args, **kwargs):
|
def respond(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Responds to the message (not as a reply). Shorthand for
|
Responds to the message (not as a reply). Shorthand for
|
||||||
|
|
|
@ -2416,7 +2416,7 @@ class TelegramClient(TelegramBareClient):
|
||||||
for builder, callback in self._event_builders:
|
for builder, callback in self._event_builders:
|
||||||
event = builder.build(update)
|
event = builder.build(update)
|
||||||
if event:
|
if event:
|
||||||
event._client = self
|
event._set_client(self)
|
||||||
event.original_update = update
|
event.original_update = update
|
||||||
try:
|
try:
|
||||||
callback(event)
|
callback(event)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user