commit 43fbc13

Hubert Hirtz  ·  2020-11-30 09:06:51 +0000 UTC
parent c791106
Move configuration defaults to config.go
2 files changed,  +13, -10
+13, -0
 1@@ -1,6 +1,7 @@
 2 package senpai
 3 
 4 import (
 5+	"errors"
 6 	"io/ioutil"
 7 
 8 	"gopkg.in/yaml.v2"
 9@@ -23,6 +24,18 @@ type Config struct {
10 
11 func ParseConfig(buf []byte) (cfg Config, err error) {
12 	err = yaml.Unmarshal(buf, &cfg)
13+	if cfg.Addr == "" {
14+		return cfg, errors.New("addr is required")
15+	}
16+	if cfg.Nick == "" {
17+		return cfg, errors.New("nick is required")
18+	}
19+	if cfg.User == "" {
20+		cfg.User = cfg.Nick
21+	}
22+	if cfg.Real == "" {
23+		cfg.Real = cfg.Nick
24+	}
25 	if cfg.NickColWidth <= 0 {
26 		cfg.NickColWidth = 16
27 	}
+0, -10
 1@@ -202,16 +202,6 @@ func NewSession(conn io.ReadWriteCloser, params SessionParams) (*Session, error)
 2 		chBatches:     map[string]HistoryEvent{},
 3 	}
 4 
 5-	if s.nick == "" {
 6-		return nil, errors.New("no nickname specified")
 7-	}
 8-	if s.user == "" {
 9-		s.user = s.nick
10-	}
11-	if s.real == "" {
12-		s.real = s.nick
13-	}
14-
15 	s.running.Store(true)
16 
17 	err := s.send("CAP LS 302\r\nNICK %s\r\nUSER %s 0 * :%s\r\n", s.nick, s.user, s.real)