diff --git a/ircrobots/ircv3.py b/ircrobots/ircv3.py index 833b46b..a31efe6 100644 --- a/ircrobots/ircv3.py +++ b/ircrobots/ircv3.py @@ -75,6 +75,14 @@ def _cap_dict(s: str) -> Dict[str, str]: d[key] = value return d +async def sts_transmute(params: ConnectionParams): + if not params.sts is None and not params.tls: + now = time() + since = (now-params.sts.created) + if since <= params.sts.duration: + params.port = params.sts.port + params.tls = True + class CAPContext(ServerContext): async def on_ls(self, tokens: Dict[str, str]): caps = list(self.server.desired_caps)+CAPS @@ -126,12 +134,3 @@ class CAPContext(ServerContext): await self.on_ls(self.server.available_caps) await self.server.send(build("CAP", ["END"])) - -class STSContext(ServerContext): - async def transmute(self, params: ConnectionParams): - if not params.sts is None and not params.tls: - now = time() - since = (now-params.sts.created) - if since <= params.sts.duration: - params.port = params.sts.port - params.tls = True diff --git a/ircrobots/server.py b/ircrobots/server.py index 7e2fb86..09cb776 100644 --- a/ircrobots/server.py +++ b/ircrobots/server.py @@ -8,8 +8,8 @@ from ircstates.numerics import * from ircstates.server import ServerDisconnectedException from irctokens import build, Line, tokenise -from .ircv3 import (CAPContext, STSContext, CAP_ECHO, CAP_SASL, CAP_LABEL, - LABEL_TAG) +from .ircv3 import (CAPContext, sts_transmute, CAP_ECHO, CAP_SASL, + CAP_LABEL, LABEL_TAG) from .sasl import SASLContext, SASLResult from .join_info import WHOContext from .matching import ResponseOr, Responses, Response, ParamAny, ParamFolded @@ -84,7 +84,7 @@ class Server(IServer): async def connect(self, transport: ITCPTransport, params: ConnectionParams): - await STSContext(self).transmute(params) + await sts_transmute(params) reader, writer = await transport.connect( params.host,