mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-03 19:00:21 +03:00
Stop using InputPeerSelf() on events and special case edit()
Used to fail on the chat with your own (where messages are "incoming" instead outgoing). Now the ID of the chat and sender are compared to achieve the same effect. Fixes #632.
This commit is contained in:
parent
f13a7e4afd
commit
448a04a7c5
|
@ -21,8 +21,7 @@ def _into_id_set(client, chats):
|
|||
for chat in chats:
|
||||
chat = client.get_input_entity(chat)
|
||||
if isinstance(chat, types.InputPeerSelf):
|
||||
chat = getattr(_into_id_set, 'me', None) or client.get_me()
|
||||
_into_id_set.me = chat
|
||||
chat = client.get_me(input_peer=True)
|
||||
result.add(utils.get_peer_id(chat))
|
||||
return result
|
||||
|
||||
|
@ -43,6 +42,7 @@ class _EventBuilder(abc.ABC):
|
|||
def __init__(self, chats=None, blacklist_chats=False):
|
||||
self.chats = chats
|
||||
self.blacklist_chats = blacklist_chats
|
||||
self._self_id = None
|
||||
|
||||
@abc.abstractmethod
|
||||
def build(self, update):
|
||||
|
@ -51,6 +51,7 @@ class _EventBuilder(abc.ABC):
|
|||
def resolve(self, client):
|
||||
"""Helper method to allow event builders to be resolved before usage"""
|
||||
self.chats = _into_id_set(client, self.chats)
|
||||
self._self_id = client.get_me(input_peer=True).user_id
|
||||
|
||||
def _filter_event(self, event):
|
||||
"""
|
||||
|
@ -179,11 +180,6 @@ class NewMessage(_EventBuilder):
|
|||
You can specify a regex-like string which will be matched
|
||||
against the message, a callable function that returns ``True``
|
||||
if a message is acceptable, or a compiled regex pattern.
|
||||
|
||||
Notes:
|
||||
The ``message.from_id`` might not only be an integer or ``None``,
|
||||
but also ``InputPeerSelf()`` for short private messages (the API
|
||||
would not return such thing, this is a custom modification).
|
||||
"""
|
||||
def __init__(self, incoming=None, outgoing=None,
|
||||
chats=None, blacklist_chats=False, pattern=None):
|
||||
|
@ -216,7 +212,7 @@ class NewMessage(_EventBuilder):
|
|||
silent=update.silent,
|
||||
id=update.id,
|
||||
to_id=types.PeerUser(update.user_id),
|
||||
from_id=types.InputPeerSelf() if update.out else update.user_id,
|
||||
from_id=self._self_id if update.out else update.user_id,
|
||||
message=update.message,
|
||||
date=update.date,
|
||||
fwd_from=update.fwd_from,
|
||||
|
@ -317,7 +313,11 @@ class NewMessage(_EventBuilder):
|
|||
or the edited message otherwise.
|
||||
"""
|
||||
if not self.message.out:
|
||||
return None
|
||||
if not isinstance(self.message.to_id, types.PeerUser):
|
||||
return None
|
||||
me = self._client.get_me(input_peer=True)
|
||||
if self.message.to_id.user_id != me.user_id:
|
||||
return None
|
||||
|
||||
return self._client.edit_message(self.input_chat,
|
||||
self.message,
|
||||
|
|
Loading…
Reference in New Issue
Block a user