add a Response subclass just to take RPL_/ERR_ names along with params
This commit is contained in:
parent
0829fd9499
commit
423623fec1
1 changed files with 16 additions and 10 deletions
|
@ -3,16 +3,6 @@ from irctokens import Line
|
|||
from .numerics import NUMERIC_NAMES
|
||||
from .interface import IServer, IMatchResponse, IMatchResponseParam
|
||||
|
||||
class Numerics(IMatchResponse):
|
||||
def __init__(self,
|
||||
numerics: List[str]):
|
||||
self._numerics = [NUMERIC_NAMES.get(n, n) for n in numerics]
|
||||
def __repr__(self) -> str:
|
||||
return f"Numerics({self._numerics!r})"
|
||||
|
||||
def match(self, server: IServer, line: Line):
|
||||
return line.command in self._numerics
|
||||
|
||||
class Response(IMatchResponse):
|
||||
def __init__(self,
|
||||
command: str,
|
||||
|
@ -33,6 +23,22 @@ class Response(IMatchResponse):
|
|||
else:
|
||||
return False
|
||||
|
||||
class Numeric(Response):
|
||||
def __init__(self,
|
||||
name: str,
|
||||
params: List[IMatchResponseParam]=[]):
|
||||
super().__init__(NUMERIC_NAMES.get(name, name), params)
|
||||
|
||||
class Numerics(IMatchResponse):
|
||||
def __init__(self,
|
||||
numerics: List[str]):
|
||||
self._numerics = [NUMERIC_NAMES.get(n, n) for n in numerics]
|
||||
def __repr__(self) -> str:
|
||||
return f"Numerics({self._numerics!r})"
|
||||
|
||||
def match(self, server: IServer, line: Line):
|
||||
return line.command in self._numerics
|
||||
|
||||
class ResponseOr(IMatchResponse):
|
||||
def __init__(self, *responses: IMatchResponse):
|
||||
self._responses = responses
|
||||
|
|
Loading…
Reference in a new issue