Simplify event building logic

This will also fix some bugs where the event type being accessed
would not be available, since it is now built on-demand, without
the need to keep track for the count of each event type.
This commit is contained in:
Lonami Exo
2018-08-21 10:27:12 +02:00
parent f0cd1fdd6e
commit 9f237cc928
3 changed files with 26 additions and 43 deletions

View File

@@ -273,26 +273,18 @@ class Conversation(ChatGetter):
self._custom[counter] = (event, future, False)
return await result()
async def _check_custom(self, built, update):
async def _check_custom(self, built):
# TODO This code is quite much a copy paste of registering events
# in the client, resolving them and setting the client; perhaps
# there is a better way?
for i, (ev, fut, resolved) in self._custom.items():
ev_type = type(ev)
if ev_type not in built:
built[ev_type] = ev.build(update)
if built[ev_type]:
if not resolved:
await ev.resolve(self._client)
self._custom[i] = (ev, fut, True)
if ev.filter(built[ev_type]):
if hasattr(built[ev_type], '_set_client'):
built[ev_type]._set_client(self._client)
else:
built[ev_type]._client = self._client
fut.set_result(built[ev_type])
def _on_new_message(self, response):