mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-11-13 04:20:37 +00:00
Adapt the rest of the library to layer 119
This commit is contained in:
@@ -150,12 +150,12 @@ class Album(EventBuilder):
|
||||
"""
|
||||
def __init__(self, messages):
|
||||
message = messages[0]
|
||||
if not message.out and isinstance(message.to_id, types.PeerUser):
|
||||
# Incoming message (e.g. from a bot) has to_id=us, and
|
||||
if not message.out and isinstance(message.peer_id, types.PeerUser):
|
||||
# Incoming message (e.g. from a bot) has peer_id=us, and
|
||||
# from_id=bot (the actual "chat" from a user's perspective).
|
||||
chat_peer = types.PeerUser(message.from_id)
|
||||
chat_peer = message.from_id
|
||||
else:
|
||||
chat_peer = message.to_id
|
||||
chat_peer = message.peer_id
|
||||
|
||||
super().__init__(chat_peer=chat_peer,
|
||||
msg_id=message.id, broadcast=bool(message.post))
|
||||
|
||||
@@ -78,7 +78,7 @@ class ChatAction(EventBuilder):
|
||||
users=msg.from_id)
|
||||
elif isinstance(action, types.MessageActionChatAddUser):
|
||||
# If a user adds itself, it means they joined
|
||||
added_by = ([msg.from_id] == action.users) or msg.from_id
|
||||
added_by = ([utils.get_peer_id(msg.from_id)] == action.users) or msg.from_id
|
||||
return cls.Event(msg,
|
||||
added_by=added_by,
|
||||
users=action.users)
|
||||
@@ -108,12 +108,12 @@ class ChatAction(EventBuilder):
|
||||
return cls.Event(msg,
|
||||
users=msg.from_id,
|
||||
new_photo=True)
|
||||
elif isinstance(action, types.MessageActionPinMessage) and msg.reply_to_msg_id:
|
||||
elif isinstance(action, types.MessageActionPinMessage) and msg.reply_to:
|
||||
# Seems to not be reliable on unpins, but when pinning
|
||||
# we prefer this because we know who caused it.
|
||||
return cls.Event(msg,
|
||||
users=msg.from_id,
|
||||
new_pin=msg.reply_to_msg_id)
|
||||
new_pin=msg.reply_to.reply_to_msg_id)
|
||||
|
||||
class Event(EventCommon):
|
||||
"""
|
||||
@@ -158,7 +158,7 @@ class ChatAction(EventBuilder):
|
||||
users=None, new_title=None, unpin=None):
|
||||
if isinstance(where, types.MessageService):
|
||||
self.action_message = where
|
||||
where = where.to_id
|
||||
where = where.peer_id
|
||||
else:
|
||||
self.action_message = None
|
||||
|
||||
@@ -193,9 +193,9 @@ class ChatAction(EventBuilder):
|
||||
self.created = bool(created)
|
||||
|
||||
if isinstance(users, list):
|
||||
self._user_ids = users
|
||||
self._user_ids = [utils.get_peer_id(u) for u in users]
|
||||
elif users:
|
||||
self._user_ids = [users]
|
||||
self._user_ids = [utils.get_peer_id(users)]
|
||||
else:
|
||||
self._user_ids = []
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import re
|
||||
|
||||
from .common import EventBuilder, EventCommon, name_inner_event, _into_id_set
|
||||
from .. import utils
|
||||
from ..tl import types
|
||||
|
||||
|
||||
@@ -106,15 +107,15 @@ class NewMessage(EventBuilder):
|
||||
media_unread=update.media_unread,
|
||||
silent=update.silent,
|
||||
id=update.id,
|
||||
# Note that to_id/from_id complement each other in private
|
||||
# Note that peer_id/from_id complement each other in private
|
||||
# messages, depending on whether the message was outgoing.
|
||||
to_id=types.PeerUser(update.user_id if update.out else self_id),
|
||||
from_id=self_id if update.out else update.user_id,
|
||||
peer_id=types.PeerUser(update.user_id if update.out else self_id),
|
||||
from_id=types.PeerUser(self_id if update.out else update.user_id),
|
||||
message=update.message,
|
||||
date=update.date,
|
||||
fwd_from=update.fwd_from,
|
||||
via_bot_id=update.via_bot_id,
|
||||
reply_to_msg_id=update.reply_to_msg_id,
|
||||
reply_to=update.reply_to,
|
||||
entities=update.entities
|
||||
))
|
||||
elif isinstance(update, types.UpdateShortChatMessage):
|
||||
@@ -124,13 +125,13 @@ class NewMessage(EventBuilder):
|
||||
media_unread=update.media_unread,
|
||||
silent=update.silent,
|
||||
id=update.id,
|
||||
from_id=update.from_id,
|
||||
to_id=types.PeerChat(update.chat_id),
|
||||
from_id=types.PeerUser(update.from_id),
|
||||
peer_id=types.PeerChat(update.chat_id),
|
||||
message=update.message,
|
||||
date=update.date,
|
||||
fwd_from=update.fwd_from,
|
||||
via_bot_id=update.via_bot_id,
|
||||
reply_to_msg_id=update.reply_to_msg_id,
|
||||
reply_to=update.reply_to,
|
||||
entities=update.entities
|
||||
))
|
||||
else:
|
||||
@@ -139,8 +140,8 @@ class NewMessage(EventBuilder):
|
||||
# Make messages sent to ourselves outgoing unless they're forwarded.
|
||||
# This makes it consistent with official client's appearance.
|
||||
ori = event.message
|
||||
if isinstance(ori.to_id, types.PeerUser):
|
||||
if ori.from_id == ori.to_id.user_id and not ori.fwd_from:
|
||||
if isinstance(ori.peer_id, types.PeerUser):
|
||||
if ori.from_id == ori.peer_id and not ori.fwd_from:
|
||||
event.message.out = True
|
||||
|
||||
return event
|
||||
@@ -158,7 +159,7 @@ class NewMessage(EventBuilder):
|
||||
return
|
||||
|
||||
if self.from_users is not None:
|
||||
if event.message.from_id not in self.from_users:
|
||||
if utils.get_peer_id(event.message.from_id) not in self.from_users:
|
||||
return
|
||||
|
||||
if self.pattern:
|
||||
@@ -204,12 +205,12 @@ class NewMessage(EventBuilder):
|
||||
"""
|
||||
def __init__(self, message):
|
||||
self.__dict__['_init'] = False
|
||||
if not message.out and isinstance(message.to_id, types.PeerUser):
|
||||
# Incoming message (e.g. from a bot) has to_id=us, and
|
||||
if not message.out and isinstance(message.peer_id, types.PeerUser):
|
||||
# Incoming message (e.g. from a bot) has peer_id=us, and
|
||||
# from_id=bot (the actual "chat" from a user's perspective).
|
||||
chat_peer = types.PeerUser(message.from_id)
|
||||
chat_peer = message.from_id
|
||||
else:
|
||||
chat_peer = message.to_id
|
||||
chat_peer = message.peer_id
|
||||
|
||||
super().__init__(chat_peer=chat_peer,
|
||||
msg_id=message.id, broadcast=bool(message.post))
|
||||
|
||||
Reference in New Issue
Block a user