python ircd using asyncio
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

24 lines
808 B

from dataclasses import dataclass, field
from datetime import datetime
from typing import Dict
from paircd.client import Client
from paircd.channel import Channel
@dataclass
class Server:
clients_by_nick: Dict[str, Client] = field(default_factory=dict)
channels_by_name: Dict[str, Channel] = field(default_factory=dict)
create_time: datetime = field(default_factory=datetime.utcnow)
def add_client(self, client: Client) -> None:
self.clients_by_nick[client.nickname] = client
def get_channel_by_name(self, name: str) -> Channel:
if name not in self.channels_by_name:
self.channels_by_name[name] = Channel(name=name)
return self.channels_by_name[name]
def remove_client_by_name(self, name: str) -> None:
del self.clients_by_nick[name]