diff --git a/paircd/handler/notice.py b/paircd/handler/notice.py new file mode 100644 index 0000000..353507c --- /dev/null +++ b/paircd/handler/notice.py @@ -0,0 +1,28 @@ +from paircd.client import Client +from paircd.command_handler import CommandHandler +from paircd.message import Message +from paircd.reply import NOTICE +from paircd.server import Server + + +class NoticeHandler(CommandHandler): + def __init__(self) -> None: + super().__init__("NOTICE", 2) + + async def handle(self, server: Server, client: Client, msg: Message) -> None: + recipient, raw_msg = msg.args + if len(raw_msg) == 0: + return + + out = NOTICE(recipient, raw_msg, prefix=client.id()) + + # Directly message a user + if recipient in server.clients_by_nick: + other_client = server.clients_by_nick[recipient] + other_client.write_message(out) + return + + # Broadcast to channel + if recipient in server.channels_by_name: + server.channels_by_name[recipient].write_message(out) + return diff --git a/paircd/handlers.py b/paircd/handlers.py index 1985d23..cf634c8 100644 --- a/paircd/handlers.py +++ b/paircd/handlers.py @@ -1,5 +1,6 @@ from logging import WARN -from paircd.handler.away import AwayHandler + + from typing import Dict from paircd.client import Client @@ -7,9 +8,11 @@ from paircd.command_handler import CommandHandler from paircd.message import Message from paircd.server import Server +from paircd.handler.away import AwayHandler from paircd.handler.join import JoinHandler from paircd.handler.mode import ModeHandler from paircd.handler.nick import NickHandler +from paircd.handler.notice import NoticeHandler from paircd.handler.ping import PingHandler from paircd.handler.privmsg import PrivmsgHandler from paircd.handler.user import UserHandler @@ -20,6 +23,7 @@ HANDLER_CLASSES = [ JoinHandler, ModeHandler, NickHandler, + NoticeHandler, PingHandler, PrivmsgHandler, UserHandler, diff --git a/paircd/reply.py b/paircd/reply.py index f01eca4..a116221 100644 --- a/paircd/reply.py +++ b/paircd/reply.py @@ -27,6 +27,7 @@ def reply_fn(cmd: Union[int, str], tmpl: str) -> Callable: JOIN = cmd_fn("JOIN", "{0}") MODE = cmd_fn("MODE", "{0} {1}") NICK = cmd_fn("NICK", "{0}") +NOTICE = cmd_fn("NOTICE", "{0} :{1}") PONG = cmd_fn("PONG", ":{0}") PRIVMSG = cmd_fn("PRIVMSG", "{0} :{1}")