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