From 75e04130dc9de82dcc020228a2e533794fda7e85 Mon Sep 17 00:00:00 2001 From: aewens Date: Mon, 16 Mar 2020 16:18:28 -0500 Subject: [PATCH] First stable release, fixed various bugs in engine and updated example code to reflect current state of project --- README.md | 8 +++++++- VERSION | 2 +- ircevents/engine.py | 23 ++++++++++++----------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1eb4b2d..09861ae 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,14 @@ def _sent(source, state): for line in send_lines: print(f"< {line.format()}") -@events.when(_always=True) +@events.when(always_run=True) def _display(line, state): print(f"> {line.format()}") +@events.when(command="PING") +def _ping(line, state) + _send(f"PONG {line.params[0]}") + @events.when(command="001") def _join(line, state): channels = state.get("channels", list()) @@ -45,6 +49,8 @@ def _join(line, state): if channel not in server.channels: _send(f"JOIN {channel}") + state.set("joined_channels", True) + # Load ircstates as a state mutation events.use("ircstates", lambda raw: server.recv(raw)) diff --git a/VERSION b/VERSION index 20f4951..0ea3a94 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.11 +0.2.0 diff --git a/ircevents/engine.py b/ircevents/engine.py index 35202fe..8666ca1 100644 --- a/ircevents/engine.py +++ b/ircevents/engine.py @@ -148,25 +148,25 @@ class Engine: # Check if all required fields are found when_requires.remove(key) - if len(whens_requires) > 0: + if len(when_requires) > 0: continue # If all requirements are found, stop checking this skip_whens.add(using_when) - triggered = self._check_when(when) + triggered = self._check_when(when, mutation) if not triggered: continue - state = self._states[namespace] - func = self._whens_funcs.get(when_key) + state = self._states[using.namespace] + func = self._whens_funcs.get(using_data) if func is None: return None # Run callback using mutation data and state manager - func(data, state) + func(mutation, state) - def _check_when(self, when): + def _check_when(self, when, data): """ Checks if mutation state will trigger callback """ @@ -174,21 +174,22 @@ class Engine: trigger_when = True # Use magic pair to always trigger callback - if when.get("always_run") is True: + if getattr(when, "always_run", None) is True: return trigger_when # Check if conditions match mutation - for when_key, when_value in when.items(): + for when_key in when._fields: when_path = when_key.split("__") pointer = data for wpath in when_path: - if not isinstance(pointer, dict): - eprint(f"Invalid path: {when_key}") + if not hasattr(pointer, wpath): + eprint(f"Invalid path at '{wpath}' in {when_key}") break - pointer = pointer.get(wpath) + pointer = getattr(pointer, wpath, None) when_status = False + when_value = getattr(when, when_key, None) # Value can be a function complex checks if callable(when_value):