Initial commit

This commit is contained in:
SolidLiquid
2025-06-05 20:15:38 +12:00
commit fa1cc5035e
16 changed files with 581 additions and 0 deletions

20
util/room/data.py Normal file
View File

@@ -0,0 +1,20 @@
from dataclasses import dataclass, field
from typing import List, Dict
from datetime import datetime
@dataclass
class Room:
code: str
created_at: datetime = field(default_factory=datetime.utcnow)
messages: List[Dict] = field(default_factory=list) # Could include sender, timestamp, etc.
password: str = None # Optional
def add_message(self, sender: str, text: str):
self.messages.append({
"sender": sender,
"text": text,
"timestamp": datetime.now().isoformat()
})
def check_password(self, attempt: str) -> bool:
return self.password is None or self.password == attempt

6
util/room/logic.py Normal file
View File

@@ -0,0 +1,6 @@
import secrets
import string
def generate_room_code(length=10):
chars = string.ascii_letters + string.digits
return ''.join(secrets.choice(chars) for _ in range(length))

17
util/room/registry.py Normal file
View File

@@ -0,0 +1,17 @@
from util.room.data import Room
class RoomRegistry:
def __init__(self):
self.rooms: dict[str, Room] = {}
def create_room(self, code: str, password: str = None) -> Room:
room = Room(code=code, password=password)
self.rooms[code] = room
return room
def get_room(self, code: str) -> Room:
return self.rooms.get(code)
def delete_room(self, code: str):
if code in self.rooms:
del self.rooms[code]