Implemented bot endpoint with DB requests and other tweaks
This commit is contained in:
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user