2020-05-24 00:05:51 +00:00
|
|
|
from asyncio import Future
|
|
|
|
from typing import (Any, Awaitable, Callable, Generator, Generic, Optional,
|
|
|
|
TypeVar)
|
2020-09-24 19:43:03 +00:00
|
|
|
|
|
|
|
from irctokens import Line
|
2020-05-24 00:05:51 +00:00
|
|
|
from .matching import IMatchResponse
|
2020-04-29 11:13:06 +00:00
|
|
|
from .interface import IServer
|
2020-05-24 00:05:51 +00:00
|
|
|
from .ircv3 import TAG_LABEL
|
2020-04-05 22:37:54 +00:00
|
|
|
|
|
|
|
TEvent = TypeVar("TEvent")
|
|
|
|
class MaybeAwait(Generic[TEvent]):
|
|
|
|
def __init__(self, func: Callable[[], Awaitable[TEvent]]):
|
|
|
|
self._func = func
|
|
|
|
|
|
|
|
def __await__(self) -> Generator[Any, None, TEvent]:
|
|
|
|
coro = self._func()
|
|
|
|
return coro.__await__()
|
2020-04-23 14:22:30 +00:00
|
|
|
|
|
|
|
class WaitFor(object):
|
2020-04-30 10:22:47 +00:00
|
|
|
def __init__(self,
|
2020-09-24 19:43:03 +00:00
|
|
|
response: IMatchResponse,
|
2021-02-18 14:50:01 +00:00
|
|
|
label: Optional[str]=None):
|
2020-09-24 19:43:03 +00:00
|
|
|
self.response = response
|
2021-02-18 14:50:01 +00:00
|
|
|
self._label = label
|
2020-04-23 14:22:30 +00:00
|
|
|
|
2020-04-29 11:13:06 +00:00
|
|
|
def match(self, server: IServer, line: Line):
|
2020-05-24 00:05:51 +00:00
|
|
|
if (self._label is not None and
|
|
|
|
line.tags is not None):
|
|
|
|
label = TAG_LABEL.get(line.tags)
|
|
|
|
if (label is not None and
|
|
|
|
label == self._label):
|
|
|
|
return True
|
2020-04-29 11:13:06 +00:00
|
|
|
return self.response.match(server, line)
|