summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordelthas <delthas@dille.cc>2022-11-22 11:06:27 +0100
committerdelthas <delthas@dille.cc>2022-11-22 11:06:27 +0100
commit68e1efcf0612c635ea186676559883e791552d30 (patch)
tree7cd2fbb5daba6ff48c7568d6c4cc4cc6a7a67afc
parentEnable receiving away updates for private buffers (diff)
Support irc URLs in the config addr
Fixes: https://todo.sr.ht/~taiite/senpai/106
-rw-r--r--config.go16
-rw-r--r--doc/senpai.5.scd4
2 files changed, 20 insertions, 0 deletions
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 (*:*).