Trying to resolve discord functions to see if audio works there but just not being relayed to liq
This commit is contained in:
@@ -30,6 +30,9 @@ NODE_LONG = os.getenv("NODE_LONG")
|
||||
# Global flag to track MQTT connection state
|
||||
MQTT_CONNECTED = False
|
||||
|
||||
# Global variable to hold the main event loop
|
||||
main_loop = None
|
||||
|
||||
# Initialize the Discord Bot
|
||||
discord_bot = DiscordRadioBot(listen_port=23457, forward_ports=[23456])
|
||||
|
||||
@@ -113,11 +116,17 @@ def handle_c2_command(topic, payload):
|
||||
token = data.get("token")
|
||||
channel_id = data.get("channel_id")
|
||||
if token and channel_id:
|
||||
asyncio.create_task(discord_bot.start_session(token, channel_id))
|
||||
if main_loop and main_loop.is_running():
|
||||
asyncio.run_coroutine_threadsafe(discord_bot.start_session(token, channel_id), main_loop)
|
||||
else:
|
||||
LOGGER.error("Main event loop not available to start Discord session.")
|
||||
LOGGER.info("Initiating Discord Session...")
|
||||
|
||||
elif command_type == "discord_leave":
|
||||
asyncio.create_task(discord_bot.stop_session())
|
||||
if main_loop and main_loop.is_running():
|
||||
asyncio.run_coroutine_threadsafe(discord_bot.stop_session(), main_loop)
|
||||
else:
|
||||
LOGGER.error("Main event loop not available to stop Discord session.")
|
||||
LOGGER.info("Ending Discord Session...")
|
||||
|
||||
else:
|
||||
@@ -465,6 +474,8 @@ async def mqtt_lifecycle_manager():
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
global main_loop
|
||||
main_loop = asyncio.get_running_loop()
|
||||
# Store the task so we can cancel it if needed (optional)
|
||||
app.state.mqtt_task = asyncio.create_task(mqtt_lifecycle_manager())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user