Commit 8a3ddfae authored by Philipp Hörist's avatar Philipp Hörist
Browse files

[triggers] Add classmethod for creating ExtendedEvents

parent 67f20eb8
Pipeline #8970 failed with stage
......@@ -15,6 +15,8 @@
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import annotations
from typing import Optional
from dataclasses import dataclass
......@@ -41,6 +43,12 @@ class ExtendedEvent(Notification):
command: Optional[str] = None
sound_file: Optional[str] = None
@classmethod
def from_event(cls, event) -> ExtendedEvent:
attr_dict = asdict(event)
attr_dict.pop('name')
return cls(**attr_dict, origin=event)
class Triggers(GajimPlugin):
def init(self):
......@@ -72,20 +80,19 @@ class Triggers(GajimPlugin):
return True
return False
def _on_notification(self, event: Notification):
extended_event = ExtendedEvent(**asdict(event), origin=event)
def _on_notification(self, event: Notification) -> bool:
extended_event = ExtendedEvent.from_event(event)
self._check_all(extended_event,
self._check_rule_apply_notification,
self._apply_rule)
return self._excecute(extended_event)
def _on_message_received(self, event):
event = ExtendedEvent(**asdict(event), origin=event)
self._check_all(event,
def _on_message_received(self, event: Notification) -> bool:
extended_event = ExtendedEvent.from_event(event)
self._check_all(extended_event,
self._check_rule_apply_msg_received,
self._apply_rule)
return self._excecute(event)
return self._excecute(extended_event)
def _on_presence_received(self, event):
# TODO
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment