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
1022 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 JoinHandler(CommandHandler):
  8. def __init__(self) -> None:
  9. super().__init__("JOIN", 1)
  10. async def handle(self, server: Server, client: Client, msg: Message) -> None:
  11. if not client.registered:
  12. log_client(client, "join: not registered", level=logging.WARN)
  13. return
  14. channel_name = msg.args[0]
  15. if not channel_name.startswith("#"):
  16. log_client(client, "tried to join invalid channel", level=logging.WARN)
  17. return
  18. channel = server.get_channel_by_name(channel_name)
  19. channel.add_client(client)
  20. client.channels.add(channel_name)
  21. log_client(client, f"joined {channel_name}")
  22. await channel.msg_queue.put(
  23. Message(cmd="JOIN", args=[channel_name], prefix=client.id()).encode()
  24. )