|
@ -1,6 +1,6 @@ |
|
|
from asyncio import Queue |
|
|
|
|
|
|
|
|
from collections import defaultdict |
|
|
from dataclasses import dataclass, field |
|
|
from dataclasses import dataclass, field |
|
|
from typing import Dict, List |
|
|
|
|
|
|
|
|
from typing import Dict, Set |
|
|
|
|
|
|
|
|
from paircd.client import Client |
|
|
from paircd.client import Client |
|
|
from paircd.message import Message |
|
|
from paircd.message import Message |
|
@ -11,13 +11,16 @@ class Channel: |
|
|
name: str |
|
|
name: str |
|
|
topic: str = "" |
|
|
topic: str = "" |
|
|
clients_by_nick: Dict[str, Client] = field(default_factory=dict) |
|
|
clients_by_nick: Dict[str, Client] = field(default_factory=dict) |
|
|
msg_queue: Queue = field(default_factory=Queue) |
|
|
|
|
|
|
|
|
modes_by_nick: Dict[str, Set[str]] = field(default_factory=lambda: defaultdict(set)) |
|
|
|
|
|
|
|
|
def add_client(self, client: Client) -> None: |
|
|
def add_client(self, client: Client) -> None: |
|
|
self.clients_by_nick[client.nickname] = client |
|
|
self.clients_by_nick[client.nickname] = client |
|
|
|
|
|
if len(self.clients_by_nick) == 1: |
|
|
|
|
|
self.modes_by_nick[client.nickname].add("@") |
|
|
|
|
|
|
|
|
def remove_client_by_nick(self, nick: str) -> None: |
|
|
def remove_client_by_nick(self, nick: str) -> None: |
|
|
del self.clients_by_nick[nick] |
|
|
del self.clients_by_nick[nick] |
|
|
|
|
|
del self.modes_by_nick[nick] |
|
|
|
|
|
|
|
|
def write_message(self, msg: Message) -> None: |
|
|
def write_message(self, msg: Message) -> None: |
|
|
for client in self.clients_by_nick.values(): |
|
|
for client in self.clients_by_nick.values(): |
|
@ -26,5 +29,8 @@ class Channel: |
|
|
continue |
|
|
continue |
|
|
client.write_message(msg) |
|
|
client.write_message(msg) |
|
|
|
|
|
|
|
|
def get_modes(self) -> List[str]: |
|
|
|
|
|
return [] |
|
|
|
|
|
|
|
|
def get_modes(self) -> Set[str]: |
|
|
|
|
|
return set() |
|
|
|
|
|
|
|
|
|
|
|
def get_user_modes_by_nick(self, nick: str) -> Set[str]: |
|
|
|
|
|
return self.modes_by_nick[nick] |