commit 68e1efc
delthas
·
2022-11-22 10:06:27 +0000 UTC
parent cb0ba06
Support irc URLs in the config addr Fixes: https://todo.sr.ht/~taiite/senpai/106
2 files changed,
+20,
-0
+16,
-0
1@@ -3,6 +3,8 @@ package senpai
2 import (
3 "errors"
4 "fmt"
5+ "net"
6+ "net/url"
7 "os"
8 "os/exec"
9 "path"
10@@ -140,6 +142,20 @@ func LoadConfigFile(filename string) (cfg Config, err error) {
11 if cfg.Real == "" {
12 cfg.Real = cfg.Nick
13 }
14+ var u *url.URL
15+ if u, err = url.Parse(cfg.Addr); err == nil && u.Scheme != "" {
16+ switch u.Scheme {
17+ case "ircs":
18+ cfg.TLS = true
19+ case "irc+insecure":
20+ cfg.TLS = false
21+ case "irc":
22+ // Could be TLS or plaintext, keep TLS as is.
23+ default:
24+ return cfg, fmt.Errorf("invalid IRC addr scheme: %v", cfg.Addr)
25+ }
26+ cfg.Addr = net.JoinHostPort(u.Hostname(), u.Port())
27+ }
28 return
29 }
30
+4,
-0
1@@ -18,6 +18,10 @@ Some settings are required, the others are optional.
2 by default unless you specify *tls* option to be *false*. TLS connections
3 default to port 6697, plain-text use port 6667.
4
5+ ircs:// & irc:// & irc+insecure:// URLs are supported, in which case only
6+ the hostname and port parts will be used. If the scheme is
7+ ircs/irc+insecure, tls will be overriden and set to true/false accordingly.
8+
9 *nickname* (required)
10 Your nickname, sent with a _NICK_ IRC message. It mustn't contain spaces or
11 colons (*:*).