forked from platypush/platypush
🐛 Fixed proper support for event package alias platypush.events
.
Even though `platypush.events` is just a symlink to `platypush.message.event`, imports from those two modules will be treated as different imports, thus hook conditions build on `platypush.events` imports will never match.
This commit is contained in:
parent
fa318882a5
commit
3986549326
1 changed files with 19 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
import copy
|
||||
import json
|
||||
import importlib
|
||||
import logging
|
||||
import threading
|
||||
from functools import wraps
|
||||
|
@ -46,8 +47,7 @@ class EventCondition:
|
|||
kwargs -- Fields rules as a key-value (e.g. source_button=btn_id
|
||||
or recognized_phrase='Your phrase')
|
||||
"""
|
||||
|
||||
self.type = type or Event.__class__ # type: ignore
|
||||
self.type = self._get_event_type(type)
|
||||
self.args = {}
|
||||
self.parsed_args = {}
|
||||
self.priority = priority
|
||||
|
@ -55,6 +55,23 @@ class EventCondition:
|
|||
for key, value in kwargs.items():
|
||||
self.args[key] = value
|
||||
|
||||
@staticmethod
|
||||
def _get_event_type(type: Optional[Type[Event]] = None) -> Type[Event]:
|
||||
if not type:
|
||||
return Event
|
||||
|
||||
# The package alias `platypush.events` -> `platypush.message.event` is
|
||||
# supported
|
||||
if type.__module__.startswith('platypush.events'):
|
||||
module = importlib.import_module(
|
||||
'platypush.message.event' + type.__module__[len('platypush.events') :]
|
||||
)
|
||||
|
||||
type = getattr(module, type.__name__)
|
||||
assert type, f'Invalid event type: {type}'
|
||||
|
||||
return type
|
||||
|
||||
@classmethod
|
||||
def build(cls, rule):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue