diff --git a/app/client.py b/app/client.py index f59e541..f70d877 100644 --- a/app/client.py +++ b/app/client.py @@ -30,11 +30,20 @@ drb_api = DRBCDBAPI(CLIENT_API_URL) srv_api = RadioAPIClient(SERVER_API_URL) # --- Define the client status object --- -class StatusValues(Enum): - ONLINE = "online" # The client is online - LISTENING = "listening" # The client bot is online and listening to a system +class StatusValues(str, Enum): + ONLINE = "online" # The discord client is online + OFFLINE = "offline" # The discord client is offline +class DiscordStatusValues(StatusValues): + INVOICE = "in_voice" # The discord client is in at least one voice channel -client_status = StatusValues.ONLINE +class OP25StatusValues(StatusValues): + LISTENING = "listening" # OP25 is online and listening + + +client_status = { + "op25_status": OP25StatusValues.OFFLINE, + "discord_status": DiscordStatusValues.OFFLINE +} # --- Define decorator creation function --- def command(func): @@ -45,8 +54,8 @@ def command(func): # --- Define Client-Side Command Handlers (The "API" functions) --- # Join server @command -async def join_server(system_id, guild_id, channel_id): -# Takes system ID, guild ID, channel ID +async def join_server(websocket, system_id, guild_id, channel_id): + # Takes system ID, guild ID, channel ID bot_status = await drb_api.get_bot_status() print("Bot status:", bot_status) # Check if the bot is running @@ -63,7 +72,7 @@ async def join_server(system_id, guild_id, channel_id): # Join the server await drb_api.join_voice_channel(guild_id, channel_id) # Update status - client_status = StatusValues.LISTENING + client_status['discord_status'] = DiscordStatusValues.INVOICE op25_status = await drb_api.get_op25_status() print("OP25 status:", op25_status) @@ -92,13 +101,15 @@ async def join_server(system_id, guild_id, channel_id): # Start OP25 await drb_api.start_op25() + + client_status['op25_status'] = OP25StatusValues.LISTENING print("Join server completed") # Leave server @command async def leave_server(guild_id): -# Takes guild ID + # Takes guild ID bot_status = await drb_api.get_bot_status() print("Bot status:", bot_status) @@ -115,12 +126,18 @@ async def leave_server(guild_id): await drb_api.leave_voice_channel(guild_id) # Update status - client_status = StatusValues.ONLINE + client_status['discord_status'] = DiscordStatusValues.ONLINE print("Leave server completed") +# Get the client status @command -async def run_task(task_id, duration_seconds): +async def get_status(websocket, request_id): + # Return the status object + await websocket.send({"request_id": request_id, "status": client_status}) + +@command +async def run_task(websocket, task_id, duration_seconds): """Example command: Simulates running a task.""" print(f"\n--- Server Command: run_task ---") print(f"Starting task {task_id} for {duration_seconds} seconds...") @@ -141,7 +158,7 @@ async def receive_commands(websocket): if command_name in command_handlers: print(f"Executing command: {command_name} with args {args}") # Execute the registered async function - await command_handlers[command_name](*args) + await command_handlers[command_name](websocket, *args) else: print(f"Received unknown command: {command_name}") elif data.get("type") == "handshake_ack": @@ -154,6 +171,7 @@ async def receive_commands(websocket): except Exception as e: print(f"Error processing message: {e}") + async def main_client(): """Connects to the server and handles communication.""" print(f"Client {CLIENT_ID} connecting to {SERVER_WS_URI}...")