Browse Source

Implement NOTICE command

master
Forest Belton 2 years ago
parent
commit
d9976f4626
3 changed files with 34 additions and 1 deletions
  1. +28
    -0
      paircd/handler/notice.py
  2. +5
    -1
      paircd/handlers.py
  3. +1
    -0
      paircd/reply.py

+ 28
- 0
paircd/handler/notice.py View File

@ -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

+ 5
- 1
paircd/handlers.py View File

@ -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,

+ 1
- 0
paircd/reply.py View File

@ -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}")

Loading…
Cancel
Save