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.
 

32 lines
988 B

import logging
from paircd.client import Client
from paircd.command_handler import CommandHandler
from paircd.log import log_client
from paircd.message import Message
from paircd.server import Server
class PrivmsgHandler(CommandHandler):
def __init__(self) -> None:
super().__init__("PRIVMSG", 2)
async def handle(self, server: Server, client: Client, msg: Message) -> None:
recipient = msg.args[0]
raw_msg = msg.args[1]
out = Message(
"PRIVMSG", [recipient, f":{raw_msg}"], prefix=client.id()
).encode()
for name, other_client in server.clients_by_nick.items():
if name == recipient:
other_client.msg_queue.put_nowait(out)
return
for name, channel in server.channels_by_name.items():
if name == recipient:
channel.msg_queue.put_nowait(out)
return
log_client(client, "unknown recipient", level=logging.WARN)