duckypad-twitch/duckypad_twitch/util.py

34 lines
945 B
Python
Raw Normal View History

2023-07-05 13:44:21 +01:00
import slobs_websocket
def ensure_sl(func):
"""ensure a streamlabs websocket connection has been established"""
def wrapper(self, *args):
if self._duckypad.streamlabs_controller.conn.ws is None:
try:
try:
self.connect()
except AttributeError:
self._duckypad.streamlabs_controller.connect()
except slobs_websocket.exceptions.ConnectionFailure:
self._duckypad.streamlabs_controller.conn.ws = None
return
return func(self, *args)
return wrapper
def ensure_obsws(func):
"""ensure an obs websocket connection has been established"""
def wrapper(self, *args):
if self.request is None:
try:
self.obs_connect()
except (ConnectionRefusedError, TimeoutError):
return
return func(self, *args)
return wrapper