|
|
@ -1,4 +1,3 @@ |
|
|
|
import logging |
|
|
|
from paircd.reply import ERR_USERSDONTMATCH, MODE, RPL_CHANNELMODEIS, RPL_UMODEIS |
|
|
|
|
|
|
|
from paircd.client import Client |
|
|
@ -13,19 +12,36 @@ class ModeHandler(CommandHandler): |
|
|
|
|
|
|
|
async def handle(self, server: Server, client: Client, msg: Message) -> None: |
|
|
|
name = msg.args[0] |
|
|
|
if not name.startswith("#"): |
|
|
|
if name == client.nickname: |
|
|
|
settings = client.get_mode_settings() |
|
|
|
client.write_message(RPL_UMODEIS(client.nickname, settings)) |
|
|
|
else: |
|
|
|
client.write_message(ERR_USERSDONTMATCH(client.nickname)) |
|
|
|
|
|
|
|
if name.startswith("#"): |
|
|
|
self.handle_channel(server, client, msg) |
|
|
|
else: |
|
|
|
self.handle_user(client, msg) |
|
|
|
|
|
|
|
def handle_user(self, client: Client, msg: Message) -> None: |
|
|
|
name = msg.args[0] |
|
|
|
|
|
|
|
if name != client.nickname: |
|
|
|
client.write_message(ERR_USERSDONTMATCH(client.nickname)) |
|
|
|
return |
|
|
|
|
|
|
|
# Set user mode |
|
|
|
if len(msg.args) == 2: |
|
|
|
client.log("TODO: implement user mode set") |
|
|
|
|
|
|
|
settings = client.get_mode_settings() |
|
|
|
client.write_message(RPL_UMODEIS(client.nickname, settings)) |
|
|
|
|
|
|
|
def handle_channel(self, server: Server, client: Client, msg: Message) -> None: |
|
|
|
name = msg.args[0] |
|
|
|
channel = server.get_channel_by_name(name) |
|
|
|
|
|
|
|
if len(msg.args) == 2: |
|
|
|
client.log("TODO: implement channel mode set") |
|
|
|
|
|
|
|
modes = "".join(channel.get_modes()) |
|
|
|
if modes != "": |
|
|
|
modes = f"+{modes}" |
|
|
|
|
|
|
|
client.log("TODO: implement channel modes", level=logging.WARN) |
|
|
|
client.write_message(MODE(name, modes)) |
|
|
|
client.write_message(RPL_CHANNELMODEIS(client.nickname, name, modes, "")) |