Fix EventCommon/custom.Message conflicting properties

This commit is contained in:
Lonami Exo 2018-06-03 16:41:13 +02:00
parent 8c8a0153ef
commit 997f2b62ce
2 changed files with 4 additions and 13 deletions

View File

@ -151,7 +151,6 @@ class EventCommon(abc.ABC):
Note that this might be ``None`` if the library can't find it.
"""
if self._input_chat is None and self._chat_peer is not None:
try:
self._input_chat = self._client.get_input_entity(

View File

@ -129,8 +129,7 @@ class NewMessage(EventBuilder):
available members and methods.
"""
def __init__(self, message):
# Having to override __setattr__ makes things... complicated
self.__dict__['_init'] = False
self.__dict__ = message.__dict__
if not message.out and isinstance(message.to_id, types.PeerUser):
# Incoming message (e.g. from a bot) has to_id=us, and
# from_id=bot (the actual "chat" from an user's perspective).
@ -145,15 +144,8 @@ class NewMessage(EventBuilder):
def _set_client(self, client):
super()._set_client(client)
# Note that this new message also shares the same __dict__.
# By treating everything as the same message it simplifies
# the mess that would otherwise be using get/setattr.
self.message = custom.Message(
client, self.message, self._entities, None)
self._init = True
def __getattr__(self, item):
return getattr(self.message, item)
def __setattr__(self, name, value):
if self._init:
setattr(self.__dict__['message'], name, value)
else:
super().__setattr__(name, value)