mirror of
https://github.com/onyx-and-iris/streamlabs-socketio-py
synced 2024-11-21 15:00:48 +00:00
raw property added.
lets you set raw mode during runtime
This commit is contained in:
parent
e92c3b2e6f
commit
d9e8c5391a
@ -33,8 +33,26 @@ class Client:
|
|||||||
raise SteamlabsSIOConnectionError(
|
raise SteamlabsSIOConnectionError(
|
||||||
"no connection could be established to the Streamlabs SIO server"
|
"no connection could be established to the Streamlabs SIO server"
|
||||||
) from e
|
) from e
|
||||||
|
self.log_mode()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@property
|
||||||
|
def raw(self):
|
||||||
|
return self._raw
|
||||||
|
|
||||||
|
@raw.setter
|
||||||
|
def raw(self, val):
|
||||||
|
self._raw = val
|
||||||
|
self.log_mode()
|
||||||
|
|
||||||
|
def log_mode(self):
|
||||||
|
INFO_MSG = (f"Running client in {'raw' if self.raw else 'normal'} mode.",)
|
||||||
|
if self.raw:
|
||||||
|
INFO_MSG += ("raw JSON messages will be passed to callbacks",)
|
||||||
|
else:
|
||||||
|
INFO_MSG += ("event data objects will be passed to callbacks",)
|
||||||
|
self.logger.info(" ".join(INFO_MSG))
|
||||||
|
|
||||||
def _token_from_toml(self) -> str:
|
def _token_from_toml(self) -> str:
|
||||||
try:
|
try:
|
||||||
import tomllib
|
import tomllib
|
||||||
@ -56,10 +74,10 @@ class Client:
|
|||||||
raise FileNotFoundError("config.toml was not found")
|
raise FileNotFoundError("config.toml was not found")
|
||||||
with open(filepath, "rb") as f:
|
with open(filepath, "rb") as f:
|
||||||
conn = tomllib.load(f)
|
conn = tomllib.load(f)
|
||||||
assert "token" in conn.get(
|
assert (
|
||||||
"streamlabs"
|
"streamlabs" in conn and "token" in conn["streamlabs"]
|
||||||
), "token not found in config.toml"
|
), "expected [streamlabs][token] in config.toml"
|
||||||
return conn["streamlabs"].get("token")
|
return conn["streamlabs"]["token"]
|
||||||
except (FileNotFoundError, tomllib.TOMLDecodeError) as e:
|
except (FileNotFoundError, tomllib.TOMLDecodeError) as e:
|
||||||
self.logger.error(f"{type(e).__name__}: {e}")
|
self.logger.error(f"{type(e).__name__}: {e}")
|
||||||
raise
|
raise
|
||||||
@ -71,13 +89,11 @@ class Client:
|
|||||||
if "for" in data and data["type"] in set(
|
if "for" in data and data["type"] in set(
|
||||||
self.streamlabs + self.twitch + self.youtube
|
self.streamlabs + self.twitch + self.youtube
|
||||||
):
|
):
|
||||||
message = data["message"][0] if isinstance(data["message"][0], dict) else {}
|
message = data["message"][0]
|
||||||
self.obs.trigger(
|
self.obs.trigger(
|
||||||
data["for"],
|
data["for"],
|
||||||
data["type"],
|
data["type"],
|
||||||
message
|
message if self.raw else as_dataclass(data["type"], message),
|
||||||
if self._raw
|
|
||||||
else as_dataclass(data["type"], message),
|
|
||||||
)
|
)
|
||||||
self.logger.debug(data)
|
self.logger.debug(data)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user