From 68e1efcf0612c635ea186676559883e791552d30 Mon Sep 17 00:00:00 2001 From: delthas Date: Tue, 22 Nov 2022 11:06:27 +0100 Subject: Support irc URLs in the config addr Fixes: https://todo.sr.ht/~taiite/senpai/106 --- config.go | 16 ++++++++++++++++ doc/senpai.5.scd | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/config.go b/config.go index 9ee6d09..0aab25a 100644 --- a/config.go +++ b/config.go @@ -3,6 +3,8 @@ package senpai import ( "errors" "fmt" + "net" + "net/url" "os" "os/exec" "path" @@ -140,6 +142,20 @@ func LoadConfigFile(filename string) (cfg Config, err error) { if cfg.Real == "" { cfg.Real = cfg.Nick } + var u *url.URL + if u, err = url.Parse(cfg.Addr); err == nil && u.Scheme != "" { + switch u.Scheme { + case "ircs": + cfg.TLS = true + case "irc+insecure": + cfg.TLS = false + case "irc": + // Could be TLS or plaintext, keep TLS as is. + default: + return cfg, fmt.Errorf("invalid IRC addr scheme: %v", cfg.Addr) + } + cfg.Addr = net.JoinHostPort(u.Hostname(), u.Port()) + } return } diff --git a/doc/senpai.5.scd b/doc/senpai.5.scd index 114d60b..76cfb72 100644 --- a/doc/senpai.5.scd +++ b/doc/senpai.5.scd @@ -18,6 +18,10 @@ Some settings are required, the others are optional. by default unless you specify *tls* option to be *false*. TLS connections default to port 6697, plain-text use port 6667. + ircs:// & irc:// & irc+insecure:// URLs are supported, in which case only + the hostname and port parts will be used. If the scheme is + ircs/irc+insecure, tls will be overriden and set to true/false accordingly. + *nickname* (required) Your nickname, sent with a _NICK_ IRC message. It mustn't contain spaces or colons (*:*). -- cgit v1.2.3