spamCheck #1

Merged
nolan merged 4 commits from spamCheck into master 2025-10-07 18:35:43 -04:00
Showing only changes of commit 3d6ae21a7d - Show all commits

View File

@ -18,11 +18,16 @@ class WebSocketServer:
async def handleConnection(self, connection: ServerConnection) -> None: #TODO: Make this actually do something
print(f"{connection.remote_address} Connected")
connected: bool = True
task: asyncio.Task = None
while (connected):
raw: str = await connection.recv()
if task != None and task.cancel(): print("TASK CANCELED")
task = asyncio.create_task(self.respond(raw, connection))
async def respond(self, raw: str, connection: ServerConnection) -> None:
message = json.loads(raw)
print(f"Received: {message["message"]} width id {message["ID"]}")
time.sleep(random.randrange(1, 10) / 10)
await asyncio.sleep(random.randrange(1, 10) / 10)
response = {"ID": message["ID"], "message": f"received: {message["message"]}"}
await connection.send(json.dumps(response))
print("Server replied")