Browse Source

Implement queries for user MODE message

master
Forest Belton 3 years ago
parent
commit
4f3b255e31
4 changed files with 21 additions and 3 deletions
  1. +10
    -0
      paircd/client.py
  2. +3
    -1
      paircd/handler/away.py
  3. +6
    -2
      paircd/handler/mode.py
  4. +2
    -0
      paircd/reply.py

+ 10
- 0
paircd/client.py View File

@ -20,6 +20,7 @@ class Client:
registered: bool = False registered: bool = False
away: str = "" away: str = ""
modes: Set[str] = field(default_factory=set)
channels: Set[str] = field(default_factory=set) channels: Set[str] = field(default_factory=set)
def id(self) -> str: def id(self) -> str:
@ -57,3 +58,12 @@ class Client:
self.write_message( self.write_message(
RPL_MYINFO(self.nickname, "localhost", "paircd-0.0.1", "", "") 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)

+ 3
- 1
paircd/handler/away.py View File

@ -12,7 +12,9 @@ class AwayHandler(CommandHandler):
async def handle(self, server: Server, client: Client, msg: Message) -> None: async def handle(self, server: Server, client: Client, msg: Message) -> None:
if len(msg.args) == 0 or len(msg.args[0]) == 0: if len(msg.args) == 0 or len(msg.args[0]) == 0:
client.away = "" client.away = ""
client.remove_mode("a")
client.write_message(RPL_UNAWAY(client.nickname)) client.write_message(RPL_UNAWAY(client.nickname))
else: else:
client.away = msg.args[0] client.away = msg.args[0]
client.write_message(RPL_NOWAWAY(client.nickname))
client.add_mode("a")
client.write_message(RPL_NOWAWAY(client.nickname))

+ 6
- 2
paircd/handler/mode.py View File

@ -1,5 +1,5 @@
import logging 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.client import Client
from paircd.command_handler import CommandHandler from paircd.command_handler import CommandHandler
@ -14,7 +14,11 @@ class ModeHandler(CommandHandler):
async def handle(self, server: Server, client: Client, msg: Message) -> None: async def handle(self, server: Server, client: Client, msg: Message) -> None:
name = msg.args[0] name = msg.args[0]
if not name.startswith("#"): 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 return
channel = server.get_channel_by_name(name) channel = server.get_channel_by_name(name)

+ 2
- 0
paircd/reply.py View File

@ -40,12 +40,14 @@ ERR_NONICKNAMEGIVEN = reply_fn(431, ":No nickname given")
ERR_NICKNAMEINUSE = reply_fn(433, "{0} :Nickname is already in use") ERR_NICKNAMEINUSE = reply_fn(433, "{0} :Nickname is already in use")
ERR_NOTEXTTOSEND = reply_fn(412, ":No text to send") ERR_NOTEXTTOSEND = reply_fn(412, ":No text to send")
ERR_NOTREGISTERED = reply_fn(451, ":You have not registered") ERR_NOTREGISTERED = reply_fn(451, ":You have not registered")
ERR_USERSDONTMATCH = reply_fn(502, ":Cannot change mode for other users")
# Command responses # Command responses
RPL_WELCOME = reply_fn("001", "Welcome to the Internet Relay Network {0}") 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_YOURHOST = reply_fn("002", "Your host is {0}, running version {1}")
RPL_CREATED = reply_fn("003", "This server was created {0}") RPL_CREATED = reply_fn("003", "This server was created {0}")
RPL_MYINFO = reply_fn("004", "{0} {1} {2} {3}") RPL_MYINFO = reply_fn("004", "{0} {1} {2} {3}")
RPL_UMODEIS = reply_fn(221, "{0}")
RPL_AWAY = reply_fn(301, "{0} :{1}") RPL_AWAY = reply_fn(301, "{0} :{1}")
RPL_UNAWAY = reply_fn(305, ":You are no longer marked as being away") 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") RPL_NOWAWAY = reply_fn(306, ":You have been marked as being away")

Loading…
Cancel
Save