allow Numerics() with params
use NUMERICS list from ircstates
This commit is contained in:
parent
9265fd0c48
commit
9f832df2f1
4 changed files with 37 additions and 40 deletions
|
@ -1,43 +1,55 @@
|
|||
from typing import List, Optional
|
||||
from irctokens import Line
|
||||
from .numerics import NUMERIC_NAMES
|
||||
from ircstates import NUMERIC_NAMES
|
||||
from .interface import IServer, IMatchResponse, IMatchResponseParam
|
||||
|
||||
class Response(IMatchResponse):
|
||||
class Responses(IMatchResponse):
|
||||
def __init__(self,
|
||||
command: str,
|
||||
params: List[IMatchResponseParam]):
|
||||
self._command = command
|
||||
self._params = params
|
||||
commands: List[str],
|
||||
params: List[IMatchResponseParam]=[]):
|
||||
self._commands = commands
|
||||
self._params = params
|
||||
def __repr__(self) -> str:
|
||||
return f"Response({self._command}: {self._params!r})"
|
||||
return f"Responses({self._commands!r}: {self._params!r})"
|
||||
|
||||
def match(self, server: IServer, line: Line) -> bool:
|
||||
if line.command == self._command:
|
||||
for i, param in enumerate(self._params):
|
||||
if (i >= len(line.params) or
|
||||
not param.match(server, line.params[i])):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
for command in self._commands:
|
||||
if line.command == command:
|
||||
for i, param in enumerate(self._params):
|
||||
if (i >= len(line.params) or
|
||||
not param.match(server, line.params[i])):
|
||||
continue
|
||||
else:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
class Response(Responses):
|
||||
def __init__(self,
|
||||
command: str,
|
||||
params: List[IMatchResponseParam]=[]):
|
||||
super().__init__([command], params)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Response({self._commands[0]}: {self._params!r})"
|
||||
|
||||
|
||||
class Numeric(Response):
|
||||
def __init__(self,
|
||||
name: str,
|
||||
params: List[IMatchResponseParam]=[]):
|
||||
super().__init__(NUMERIC_NAMES.get(name, name), params)
|
||||
|
||||
class Numerics(IMatchResponse):
|
||||
class Numerics(Responses):
|
||||
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})"
|
||||
numerics: List[str],
|
||||
params: List[IMatchResponseParam]=[]):
|
||||
self._numerics = numerics
|
||||
numerics = [NUMERIC_NAMES.get(n, n) for n in numerics]
|
||||
super().__init__(numerics, params)
|
||||
|
||||
def match(self, server: IServer, line: Line):
|
||||
return line.command in self._numerics
|
||||
def __repr__(self) -> str:
|
||||
return f"Numerics({self._numerics!r}: {self._params!r})"
|
||||
|
||||
class ResponseOr(IMatchResponse):
|
||||
def __init__(self, *responses: IMatchResponse):
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
NUMERIC_NUMBERS = {}
|
||||
NUMERIC_NAMES = {}
|
||||
|
||||
def _numeric(number: str, name: str):
|
||||
NUMERIC_NUMBERS[number] = name
|
||||
NUMERIC_NAMES[name] = number
|
||||
|
||||
_numeric("001", "RPL_WELCOME")
|
||||
_numeric("005", "RPL_ISUPPORT")
|
||||
|
||||
_numeric("903", "RPL_SASLSUCCESS")
|
||||
_numeric("904", "ERR_SASLFAIL")
|
||||
_numeric("905", "ERR_SASLTOOLONG")
|
||||
_numeric("906", "ERR_SASLABORTED")
|
||||
_numeric("907", "ERR_SASLALREADY")
|
||||
_numeric("908", "RPL_SASLMECHS")
|
|
@ -3,13 +3,14 @@ from typing import Awaitable, Deque, Dict, List, Optional, Set, Tuple
|
|||
from collections import deque
|
||||
|
||||
from asyncio_throttle import Throttler
|
||||
from ircstates import Emit, Channel
|
||||
from ircstates import Emit, Channel, NUMERIC_NAMES
|
||||
from irctokens import build, Line, tokenise
|
||||
|
||||
from .ircv3 import CAPContext, CAP_SASL
|
||||
from .sasl import SASLContext, SASLResult
|
||||
from .matching import Numeric, ParamAny, ParamFolded
|
||||
from .matching import ResponseOr, Numerics, Numeric, ParamAny, ParamFolded
|
||||
from .asyncs import MaybeAwait
|
||||
from .struct import Whois
|
||||
|
||||
from .interface import (ConnectionParams, ICapability, IServer, SentLine,
|
||||
SendPriority, SASLParams, IMatchResponse)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
anyio ==1.3.0
|
||||
asyncio-throttle ==1.0.1
|
||||
dataclasses ==0.6
|
||||
ircstates ==0.8.3
|
||||
ircstates ==0.8.7
|
||||
|
|
Loading…
Reference in a new issue