feat: Упрощено взаимодействие по вебсокетам между клиентом и сервером

This commit is contained in:
AURUMVORXX
2025-10-29 22:57:04 +05:00
parent aa6b5700ce
commit a31b565967
3 changed files with 16 additions and 13 deletions

View File

@@ -1,4 +1,6 @@
import inspect
import server
from fastapi import WebSocket
_EVENTS = {}
@@ -15,9 +17,12 @@ def event(event_name: str, priority: int = 9999):
return func
return inlineEvent
async def call_event(event_name: str, *args, **kwargs):
async def call_event(event_name: str, connection: WebSocket, uuid: str | None, *args, **kwargs):
if event_name not in _EVENTS:
return
for item in _EVENTS[event_name]:
await item['function'](*args, **kwargs)
result = await item['function'](*args, **kwargs)
if uuid is None or result is None:
return
await server.Server.send(connection = connection, uuid = uuid, message = result)