Add get status function
This commit is contained in:
@@ -30,11 +30,20 @@ drb_api = DRBCDBAPI(CLIENT_API_URL)
|
|||||||
srv_api = RadioAPIClient(SERVER_API_URL)
|
srv_api = RadioAPIClient(SERVER_API_URL)
|
||||||
|
|
||||||
# --- Define the client status object ---
|
# --- Define the client status object ---
|
||||||
class StatusValues(Enum):
|
class StatusValues(str, Enum):
|
||||||
ONLINE = "online" # The client is online
|
ONLINE = "online" # The discord client is online
|
||||||
LISTENING = "listening" # The client bot is online and listening to a system
|
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 ---
|
# --- Define decorator creation function ---
|
||||||
def command(func):
|
def command(func):
|
||||||
@@ -45,8 +54,8 @@ def command(func):
|
|||||||
# --- Define Client-Side Command Handlers (The "API" functions) ---
|
# --- Define Client-Side Command Handlers (The "API" functions) ---
|
||||||
# Join server
|
# Join server
|
||||||
@command
|
@command
|
||||||
async def join_server(system_id, guild_id, channel_id):
|
async def join_server(websocket, system_id, guild_id, channel_id):
|
||||||
# Takes system ID, guild ID, channel ID
|
# Takes system ID, guild ID, channel ID
|
||||||
bot_status = await drb_api.get_bot_status()
|
bot_status = await drb_api.get_bot_status()
|
||||||
print("Bot status:", bot_status)
|
print("Bot status:", bot_status)
|
||||||
# Check if the bot is running
|
# Check if the bot is running
|
||||||
@@ -63,7 +72,7 @@ async def join_server(system_id, guild_id, channel_id):
|
|||||||
# Join the server
|
# Join the server
|
||||||
await drb_api.join_voice_channel(guild_id, channel_id)
|
await drb_api.join_voice_channel(guild_id, channel_id)
|
||||||
# Update status
|
# Update status
|
||||||
client_status = StatusValues.LISTENING
|
client_status['discord_status'] = DiscordStatusValues.INVOICE
|
||||||
|
|
||||||
op25_status = await drb_api.get_op25_status()
|
op25_status = await drb_api.get_op25_status()
|
||||||
print("OP25 status:", op25_status)
|
print("OP25 status:", op25_status)
|
||||||
@@ -93,12 +102,14 @@ async def join_server(system_id, guild_id, channel_id):
|
|||||||
# Start OP25
|
# Start OP25
|
||||||
await drb_api.start_op25()
|
await drb_api.start_op25()
|
||||||
|
|
||||||
|
client_status['op25_status'] = OP25StatusValues.LISTENING
|
||||||
|
|
||||||
print("Join server completed")
|
print("Join server completed")
|
||||||
|
|
||||||
# Leave server
|
# Leave server
|
||||||
@command
|
@command
|
||||||
async def leave_server(guild_id):
|
async def leave_server(guild_id):
|
||||||
# Takes guild ID
|
# Takes guild ID
|
||||||
bot_status = await drb_api.get_bot_status()
|
bot_status = await drb_api.get_bot_status()
|
||||||
print("Bot status:", 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)
|
await drb_api.leave_voice_channel(guild_id)
|
||||||
|
|
||||||
# Update status
|
# Update status
|
||||||
client_status = StatusValues.ONLINE
|
client_status['discord_status'] = DiscordStatusValues.ONLINE
|
||||||
|
|
||||||
print("Leave server completed")
|
print("Leave server completed")
|
||||||
|
|
||||||
|
# Get the client status
|
||||||
@command
|
@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."""
|
"""Example command: Simulates running a task."""
|
||||||
print(f"\n--- Server Command: run_task ---")
|
print(f"\n--- Server Command: run_task ---")
|
||||||
print(f"Starting task {task_id} for {duration_seconds} seconds...")
|
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:
|
if command_name in command_handlers:
|
||||||
print(f"Executing command: {command_name} with args {args}")
|
print(f"Executing command: {command_name} with args {args}")
|
||||||
# Execute the registered async function
|
# Execute the registered async function
|
||||||
await command_handlers[command_name](*args)
|
await command_handlers[command_name](websocket, *args)
|
||||||
else:
|
else:
|
||||||
print(f"Received unknown command: {command_name}")
|
print(f"Received unknown command: {command_name}")
|
||||||
elif data.get("type") == "handshake_ack":
|
elif data.get("type") == "handshake_ack":
|
||||||
@@ -154,6 +171,7 @@ async def receive_commands(websocket):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error processing message: {e}")
|
print(f"Error processing message: {e}")
|
||||||
|
|
||||||
|
|
||||||
async def main_client():
|
async def main_client():
|
||||||
"""Connects to the server and handles communication."""
|
"""Connects to the server and handles communication."""
|
||||||
print(f"Client {CLIENT_ID} connecting to {SERVER_WS_URI}...")
|
print(f"Client {CLIENT_ID} connecting to {SERVER_WS_URI}...")
|
||||||
|
|||||||
Reference in New Issue
Block a user