From 4f3b255e31c01393f585998443d00d921c0574de Mon Sep 17 00:00:00 2001 From: Forest Belton <65484+forestbelton@users.noreply.github.com> Date: Tue, 22 Jun 2021 17:43:46 -0400 Subject: [PATCH] Implement queries for user MODE message --- paircd/client.py | 10 ++++++++++ paircd/handler/away.py | 4 +++- paircd/handler/mode.py | 8 ++++++-- paircd/reply.py | 2 ++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/paircd/client.py b/paircd/client.py index ce8defc..9a92bc6 100644 --- a/paircd/client.py +++ b/paircd/client.py @@ -20,6 +20,7 @@ class Client: registered: bool = False away: str = "" + modes: Set[str] = field(default_factory=set) channels: Set[str] = field(default_factory=set) def id(self) -> str: @@ -57,3 +58,12 @@ class Client: self.write_message( RPL_MYINFO(self.nickname, "localhost", "paircd-0.0.1", "", "") ) + + def add_mode(self, mode: str) -> None: + self.modes.add(mode) + + def get_mode_settings(self) -> str: + return f"+{''.join(sorted(self.modes))}" + + def remove_mode(self, mode: str) -> None: + self.modes.remove(mode) diff --git a/paircd/handler/away.py b/paircd/handler/away.py index 80775ca..dc21afe 100644 --- a/paircd/handler/away.py +++ b/paircd/handler/away.py @@ -12,7 +12,9 @@ class AwayHandler(CommandHandler): async def handle(self, server: Server, client: Client, msg: Message) -> None: if len(msg.args) == 0 or len(msg.args[0]) == 0: client.away = "" + client.remove_mode("a") client.write_message(RPL_UNAWAY(client.nickname)) else: client.away = msg.args[0] - client.write_message(RPL_NOWAWAY(client.nickname)) \ No newline at end of file + client.add_mode("a") + client.write_message(RPL_NOWAWAY(client.nickname)) diff --git a/paircd/handler/mode.py b/paircd/handler/mode.py index 7124ac7..f865e0a 100644 --- a/paircd/handler/mode.py +++ b/paircd/handler/mode.py @@ -1,5 +1,5 @@ import logging -from paircd.reply import MODE, RPL_CHANNELMODEIS +from paircd.reply import ERR_USERSDONTMATCH, MODE, RPL_CHANNELMODEIS, RPL_UMODEIS from paircd.client import Client from paircd.command_handler import CommandHandler @@ -14,7 +14,11 @@ class ModeHandler(CommandHandler): async def handle(self, server: Server, client: Client, msg: Message) -> None: name = msg.args[0] if not name.startswith("#"): - client.log("TODO: implement user mode queries", level=logging.WARN) + 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)) return channel = server.get_channel_by_name(name) diff --git a/paircd/reply.py b/paircd/reply.py index 77bdd2b..f01eca4 100644 --- a/paircd/reply.py +++ b/paircd/reply.py @@ -40,12 +40,14 @@ ERR_NONICKNAMEGIVEN = reply_fn(431, ":No nickname given") ERR_NICKNAMEINUSE = reply_fn(433, "{0} :Nickname is already in use") ERR_NOTEXTTOSEND = reply_fn(412, ":No text to send") ERR_NOTREGISTERED = reply_fn(451, ":You have not registered") +ERR_USERSDONTMATCH = reply_fn(502, ":Cannot change mode for other users") # Command responses RPL_WELCOME = reply_fn("001", "Welcome to the Internet Relay Network {0}") RPL_YOURHOST = reply_fn("002", "Your host is {0}, running version {1}") RPL_CREATED = reply_fn("003", "This server was created {0}") RPL_MYINFO = reply_fn("004", "{0} {1} {2} {3}") +RPL_UMODEIS = reply_fn(221, "{0}") RPL_AWAY = reply_fn(301, "{0} :{1}") RPL_UNAWAY = reply_fn(305, ":You are no longer marked as being away") RPL_NOWAWAY = reply_fn(306, ":You have been marked as being away")