Skip to content

Commit

Permalink
fix crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
iiPythonx committed Nov 26, 2024
1 parent e40663a commit 97cb84d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion nextgen_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def __init__(self) -> None:
NextgenerationBot().run(
username = "Next-gen Bot",
hex = "ff0000",
address = "localhost:8000"
address = "nightwatch.k4ffu.dev"
)
5 changes: 2 additions & 3 deletions nightwatch/bot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<Context rics={self.rics} message={getattr(self, 'message', None)} user={getattr(self, 'user', None)}>"
Expand Down
7 changes: 2 additions & 5 deletions nightwatch/rics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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}})
Expand Down

0 comments on commit 97cb84d

Please sign in to comment.