|
@ -9,6 +9,7 @@ from paircd.message import Message |
|
|
@dataclass |
|
|
@dataclass |
|
|
class Channel: |
|
|
class Channel: |
|
|
name: str |
|
|
name: 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) |
|
|
msg_queue: Queue = field(default_factory=Queue) |
|
|
|
|
|
|
|
@ -18,17 +19,12 @@ class Channel: |
|
|
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] |
|
|
|
|
|
|
|
|
async def process(self) -> None: |
|
|
|
|
|
while True: |
|
|
|
|
|
msg = await self.msg_queue.get() |
|
|
|
|
|
for client in self.clients_by_nick.values(): |
|
|
|
|
|
# Don't broadcast client's messages back to themselves |
|
|
|
|
|
if msg.cmd == "PRIVMSG" and msg.prefix == client.id(): |
|
|
|
|
|
continue |
|
|
|
|
|
client.write_message(msg) |
|
|
|
|
|
|
|
|
|
|
|
def write_message(self, msg: Message) -> None: |
|
|
def write_message(self, msg: Message) -> None: |
|
|
self.msg_queue.put_nowait(msg) |
|
|
|
|
|
|
|
|
for client in self.clients_by_nick.values(): |
|
|
|
|
|
# Don't broadcast client's messages back to themselves |
|
|
|
|
|
if msg.cmd == "PRIVMSG" and msg.prefix == client.id(): |
|
|
|
|
|
continue |
|
|
|
|
|
client.write_message(msg) |
|
|
|
|
|
|
|
|
def get_modes(self) -> List[str]: |
|
|
def get_modes(self) -> List[str]: |
|
|
return [] |
|
|
return [] |