diff --git a/nextgen_bot.py b/nextgen_bot.py index 58d8fd5..59444af 100644 --- a/nextgen_bot.py +++ b/nextgen_bot.py @@ -15,5 +15,5 @@ def __init__(self) -> None: NextgenerationBot().run( username = "Next-gen Bot", hex = "ff0000", - address = "localhost:8000" + address = "nightwatch.k4ffu.dev" ) diff --git a/nightwatch/bot/client.py b/nightwatch/bot/client.py index 04539c3..26d4eb2 100644 --- a/nightwatch/bot/client.py +++ b/nightwatch/bot/client.py @@ -100,11 +100,10 @@ def __init__( self.user = user async def send(self, message: str) -> None: - await self.state.socket.send("PENIS!!") - await self.state.socket.send(orjson.dumps({"type": "message", "data": {"message": message}})) + await self.state.socket.send(orjson.dumps({"type": "message", "data": {"message": message}}), text = True) async def reply(self, message: str) -> None: - await self.send(f"[↑ {self.user.name}] {message}") + await self.send(f"[↑ {self.message.user.name}] {message}") def __repr__(self) -> str: return f"" diff --git a/nightwatch/rics/__init__.py b/nightwatch/rics/__init__.py index 787725e..e9cd0a1 100644 --- a/nightwatch/rics/__init__.py +++ b/nightwatch/rics/__init__.py @@ -39,9 +39,6 @@ async def broadcast(payload: dict) -> None: app.state.message_log = app.state.message_log[-24:] + [payload["data"]] for client in app.state.clients.values(): - if client.websocket.client_state != WebSocketState.CONNECTED: - continue - await client.send(payload) app.state.broadcast = broadcast @@ -65,7 +62,7 @@ def cleanup(self) -> None: del self # Not sure if this helps, in case Python doesn't GC async def send(self, payload: dict) -> None: - if self.websocket.client_state != WebSocketState.CONNECTED: + if self.websocket.application_state != WebSocketState.CONNECTED: return try: @@ -159,7 +156,7 @@ async def connect_endpoint( await app.state.broadcast({"type": "message", "data": {"message": f"{client.username} has joined the server."}}) # Handle loop - while websocket.client_state == WebSocketState.CONNECTED: + while websocket.application_state == WebSocketState.CONNECTED: match await client.receive(): case {"type": "message", "data": {"message": message}}: await app.state.broadcast({"type": "message", "data": {"user": client.serialize(), "message": message}})