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.

31 lines
955 B

  1. import logging
  2. from paircd.client import Client
  3. from paircd.command_handler import CommandHandler
  4. from paircd.message import Message
  5. from paircd.server import Server
  6. class JoinHandler(CommandHandler):
  7. def __init__(self) -> None:
  8. super().__init__("JOIN", 1)
  9. async def handle(self, server: Server, client: Client, msg: Message) -> None:
  10. if not client.registered:
  11. client.log("join: not registered", level=logging.WARN)
  12. return
  13. channel_name = msg.args[0]
  14. if not channel_name.startswith("#"):
  15. client.log("tried to join invalid channel", level=logging.WARN)
  16. return
  17. channel = server.get_channel_by_name(channel_name)
  18. channel.add_client(client)
  19. client.channels.add(channel_name)
  20. client.log(f"joined {channel_name}")
  21. await channel.msg_queue.put(
  22. Message(cmd="JOIN", args=[channel_name], prefix=client.id())
  23. )