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

  1. import logging
  2. from paircd.client import Client
  3. from paircd.command_handler import CommandHandler
  4. from paircd.log import log_client
  5. from paircd.message import Message
  6. from paircd.server import Server
  7. class PrivmsgHandler(CommandHandler):
  8. def __init__(self) -> None:
  9. super().__init__("PRIVMSG", 2)
  10. async def handle(self, server: Server, client: Client, msg: Message) -> None:
  11. recipient = msg.args[0]
  12. raw_msg = msg.args[1]
  13. out = Message(
  14. "PRIVMSG", [recipient, f":{raw_msg}"], prefix=client.id()
  15. ).encode()
  16. for name, other_client in server.clients_by_nick.items():
  17. if name == recipient:
  18. other_client.msg_queue.put_nowait(out)
  19. return
  20. for name, channel in server.channels_by_name.items():
  21. if name == recipient:
  22. channel.msg_queue.put_nowait(out)
  23. return
  24. log_client(client, "unknown recipient", level=logging.WARN)