mirror of
https://github.com/onyx-and-iris/obsws-python.git
synced 2024-11-22 04:40:53 +00:00
add attrs to dataclasses
This commit is contained in:
parent
00a97b1d8b
commit
ce9bc7e8d6
@ -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"""
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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()},
|
||||
},
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user