diff --git a/obsstudio_sdk/callback.py b/obsstudio_sdk/callback.py index 8aa9a0c..1924848 100644 --- a/obsstudio_sdk/callback.py +++ b/obsstudio_sdk/callback.py @@ -21,7 +21,7 @@ class Callback: for fn in self._callbacks: if fn.__name__ == f"on_{to_snake_case(event)}": - fn(as_dataclass(event, data.get("eventData"))) + fn(as_dataclass(event, data)) def register(self, fns: Union[Iterable, Callable]): """registers callback functions""" diff --git a/obsstudio_sdk/events.py b/obsstudio_sdk/events.py index fa34a13..6abc89d 100644 --- a/obsstudio_sdk/events.py +++ b/obsstudio_sdk/events.py @@ -57,7 +57,10 @@ class EventClient(object): self.running = True while self.running: self.data = json.loads(self.base_client.ws.recv()) - event, data = (self.data["d"].get("eventType"), self.data["d"]) + event, data = ( + self.data["d"].get("eventType"), + self.data["d"].get("eventData"), + ) self.callback.trigger(event, data) time.sleep(self.DELAY) diff --git a/obsstudio_sdk/util.py b/obsstudio_sdk/util.py index 51fe39a..7f1ec48 100644 --- a/obsstudio_sdk/util.py +++ b/obsstudio_sdk/util.py @@ -11,10 +11,16 @@ def to_snake_case(s): def as_dataclass(identifier, data): + def attrs(): + return list(data.keys()) + return dataclass( type( f"{identifier}Dataclass", (), - {**{to_snake_case(k): v for k, v in data.items()}}, + { + "attrs": attrs, + **{to_snake_case(k): v for k, v in data.items()}, + }, ) )