|
|
@ -1,8 +1,20 @@ |
|
|
|
from typing import Any, Callable, List |
|
|
|
from typing import Any, Callable, List, Optional |
|
|
|
|
|
|
|
from paircd.message import Message |
|
|
|
|
|
|
|
|
|
|
|
def cmd_fn(cmd: str, tmpl: str) -> Callable: |
|
|
|
def fn(prefix: Optional[str] = None, *args: List[Any]) -> Message: |
|
|
|
msg = tmpl.format(*args) |
|
|
|
return ( |
|
|
|
Message(cmd=cmd, args=[msg], prefix=prefix) |
|
|
|
if prefix is not None |
|
|
|
else Message(cmd=str(cmd), args=[msg]) |
|
|
|
) |
|
|
|
|
|
|
|
return fn |
|
|
|
|
|
|
|
|
|
|
|
def reply_fn(cmd: int, tmpl: str) -> Callable: |
|
|
|
def fn(target: str, *args: List[Any]) -> Message: |
|
|
|
msg = f"{target} {tmpl.format(*args)}" |
|
|
@ -11,6 +23,11 @@ def reply_fn(cmd: int, tmpl: str) -> Callable: |
|
|
|
return fn |
|
|
|
|
|
|
|
|
|
|
|
# Commands |
|
|
|
JOIN = cmd_fn("JOIN", "{0}") |
|
|
|
MODE = cmd_fn("MODE", "{0} {1}") |
|
|
|
PRIVMSG = cmd_fn("PRIVMSG", "{0} :{1}") |
|
|
|
|
|
|
|
# Error replies |
|
|
|
ERR_NOSUCHNICK = reply_fn(401, "{0} :No such nick/channel") |
|
|
|
ERR_NOSUCHSERVER = reply_fn(402, "{0}: No such server") |
|
|
|