summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtz.pm>2020-11-30 10:06:51 +0100
committerHubert Hirtz <hubert@hirtz.pm>2020-11-30 10:06:51 +0100
commit43fbc13a28e03cc1821e3a9a8fd7c07734bded29 (patch)
treec2cc44625d528122fc5abaaf019ff4b7866c6771
parentMake cmd/test usable (diff)
Move configuration defaults to config.go
Diffstat (limited to '')
-rw-r--r--config.go13
-rw-r--r--irc/states.go10
2 files changed, 13 insertions, 10 deletions
diff --git a/config.go b/config.go
index 2515e57..bd65959 100644
--- a/config.go
+++ b/config.go
@@ -1,6 +1,7 @@
package senpai
import (
+ "errors"
"io/ioutil"
"gopkg.in/yaml.v2"
@@ -23,6 +24,18 @@ type Config struct {
func ParseConfig(buf []byte) (cfg Config, err error) {
err = yaml.Unmarshal(buf, &cfg)
+ if cfg.Addr == "" {
+ return cfg, errors.New("addr is required")
+ }
+ if cfg.Nick == "" {
+ return cfg, errors.New("nick is required")
+ }
+ if cfg.User == "" {
+ cfg.User = cfg.Nick
+ }
+ if cfg.Real == "" {
+ cfg.Real = cfg.Nick
+ }
if cfg.NickColWidth <= 0 {
cfg.NickColWidth = 16
}
diff --git a/irc/states.go b/irc/states.go
index 3f787b7..3707b44 100644
--- a/irc/states.go
+++ b/irc/states.go
@@ -202,16 +202,6 @@ func NewSession(conn io.ReadWriteCloser, params SessionParams) (*Session, error)
chBatches: map[string]HistoryEvent{},
}
- if s.nick == "" {
- return nil, errors.New("no nickname specified")
- }
- if s.user == "" {
- s.user = s.nick
- }
- if s.real == "" {
- s.real = s.nick
- }
-
s.running.Store(true)
err := s.send("CAP LS 302\r\nNICK %s\r\nUSER %s 0 * :%s\r\n", s.nick, s.user, s.real)