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.

29 lines
863 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. async def handle_privmsg(server: Server, client: Client, msg: Message) -> None:
  8. recipient = msg.args[0]
  9. raw_msg = msg.args[1]
  10. out = Message("PRIVMSG", [recipient, f":{raw_msg}"], prefix=client.id()).encode()
  11. for name, other_client in server.clients_by_nick.items():
  12. if name == recipient:
  13. other_client.msg_queue.put_nowait(out)
  14. return
  15. for name, channel in server.channels_by_name.items():
  16. if name == recipient:
  17. channel.msg_queue.put_nowait(out)
  18. return
  19. log_client(client, "unknown recipient", level=logging.WARN)
  20. PRIVMSG = CommandHandler("PRIVMSG", 2, handle_privmsg)