From 6c91ebc7ecce4fadf434bc54663b5006b029f8b8 Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 29 Nov 2021 16:09:26 +0000 Subject: [PATCH] add ConnectionParams.from_hoststring("nick", "host:+port") --- ircrobots/params.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ircrobots/params.py b/ircrobots/params.py index fcbdbc2..27117e3 100644 --- a/ircrobots/params.py +++ b/ircrobots/params.py @@ -50,3 +50,20 @@ class ConnectionParams(object): alt_nicknames: List[str] = field(default_factory=list) autojoin: List[str] = field(default_factory=list) + + @staticmethod + def from_hoststring( + nickname: str, + hoststring: str + ) -> "ConnectionParams": + + host, _, port_s = hoststring.strip().partition(":") + + if port_s.startswith("+"): + tls = True + port_s = port_s.lstrip("+") or "6697" + elif not port_s: + tls = False + port_s = "6667" + + return ConnectionParams(nickname, host, int(port_s), tls)