Adapt the rest of the library to layer 119

This commit is contained in:
Lonami Exo
2020-10-01 12:22:55 +02:00
parent 62737c1caf
commit d5e4398ace
14 changed files with 78 additions and 98 deletions

View File

@@ -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))