From 423623fec1f9fcd2ef23e55ccaaa0a9abcf6f919 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 5 Apr 2020 17:16:19 +0100 Subject: [PATCH] add a Response subclass just to take RPL_/ERR_ names along with params --- ircrobots/matching.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ircrobots/matching.py b/ircrobots/matching.py index ea84a87..f19c7a8 100644 --- a/ircrobots/matching.py +++ b/ircrobots/matching.py @@ -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