from asyncio import Queue
|
|
from dataclasses import dataclass, field
|
|
from typing import Dict
|
|
|
|
from paircd.client import Client
|
|
|
|
|
|
@dataclass
|
|
class Channel:
|
|
name: str
|
|
clients_by_nick: Dict[str, Client] = field(default_factory=dict)
|
|
msg_queue: Queue = field(default_factory=Queue)
|
|
|
|
def add_client(self, client: Client) -> None:
|
|
self.clients_by_nick[client.nickname] = client
|
|
|
|
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.startswith(f":{client.id()} PRIVMSG".encode("utf-8")):
|
|
continue
|
|
client.msg_queue.put_nowait(msg)
|