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 .numerics import NUMERIC_NAMES
|
||||||
from .interface import IServer, IMatchResponse, IMatchResponseParam
|
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):
|
class Response(IMatchResponse):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
command: str,
|
command: str,
|
||||||
|
@ -33,6 +23,22 @@ class Response(IMatchResponse):
|
||||||
else:
|
else:
|
||||||
return False
|
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):
|
class ResponseOr(IMatchResponse):
|
||||||
def __init__(self, *responses: IMatchResponse):
|
def __init__(self, *responses: IMatchResponse):
|
||||||
self._responses = responses
|
self._responses = responses
|
||||||
|
|
Loading…
Add table
Reference in a new issue