Implemented bot endpoint with DB requests and other tweaks

This commit is contained in:
Logan Cusano
2025-05-24 18:12:59 -04:00
parent 15b12ecd5f
commit 107ab049ff
6 changed files with 350 additions and 35 deletions

View File

@@ -2,17 +2,14 @@ import json
from quart import Blueprint, jsonify, request, abort, current_app
from werkzeug.exceptions import HTTPException
from enum import Enum
from internal.types import ActiveClient, NodeCommands
nodes_bp = Blueprint('nodes', __name__)
class NodeCommands(str, Enum):
JOIN = "join_server"
LEAVE = "leave_server"
async def register_client(websocket, client_id):
"""Registers a new client connection."""
current_app.active_clients[client_id] = websocket
current_app.active_clients[client_id] = ActiveClient(websocket)
print(f"Client {client_id} connected.")
@@ -26,7 +23,7 @@ async def unregister_client(client_id):
async def send_command_to_client(client_id, command_name, *args):
"""Sends a command to a specific client."""
if client_id in current_app.active_clients:
websocket = current_app.active_clients[client_id]
websocket = current_app.active_clients[client_id].websocket
message = json.dumps({"type": "command", "name": command_name, "args": args})
try:
await websocket.send(message)
@@ -52,7 +49,6 @@ async def send_command_to_all_clients(command_name, *args):
await unregister_client(client_id)
@nodes_bp.route("/", methods=['GET'])
async def get_nodes():
"""API endpoint to list currently connected client IDs."""