Skip to content

Commit

Permalink
implement server side bot tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
iiPythonx committed Nov 26, 2024
1 parent 97cb84d commit dcc4428
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions nightwatch/bot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ class User:
name: str
hex: str
admin: bool
bot: bool

def __repr__(self) -> str:
return f"<User name='{self.name}' hex='{self.hex}' admin={self.admin}>"
return f"<User name='{self.name}' hex='{self.hex}' admin={self.admin} bot={self.bot}>"

@dataclass
class Message:
Expand Down Expand Up @@ -149,7 +150,8 @@ async def __authorize(self, username: str, hex: str, address: str) -> tuple[str,
f"http{protocol}://{host}:{port}/api/join",
json = {
"username": username,
"hex": hex
"hex": hex,
"bot": True
},
timeout = 5
)
Expand Down
9 changes: 6 additions & 3 deletions nightwatch/rics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ async def broadcast(payload: dict) -> None:
class Client:
def __init__(self, websocket: WebSocket, user_data) -> None:
self.websocket = websocket
self.username, self.hex_code, self.admin = user_data["username"], user_data["hex"], False
self.username, self.hex_code = user_data["username"], user_data["hex"]

self._callback = None
# Attributes
self.admin, self.bot = False, user_data["bot"]

# Attach to client list
self._callback = None
app.state.clients[self.username] = self

def serialize(self) -> dict[str, str | bool]:
return {"name": self.username, "hex": self.hex_code, "admin": self.admin}
return {"name": self.username, "hex": self.hex_code, "admin": self.admin, "bot": self.bot}

def cleanup(self) -> None:
del app.state.clients[self.username]
Expand Down Expand Up @@ -100,6 +102,7 @@ async def receive(self) -> typing.Any:
class ClientJoinModel(BaseModel):
username: str = Field(..., min_length = 3, max_length = 30)
hex: str = Field(..., min_length = 6, max_length = 6, pattern = "^[0-9A-Fa-f]{6}$")
bot: bool = False

@app.post("/api/join")
async def route_index(client: ClientJoinModel) -> JSONResponse:
Expand Down

0 comments on commit dcc4428

Please sign in to comment.