-
Notifications
You must be signed in to change notification settings - Fork 0
/
botconfig.go
48 lines (41 loc) · 989 Bytes
/
botconfig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"errors"
"flag"
"fmt"
"os"
"strings"
)
type botConfig struct {
nick string
channels []string
serverPassword string
}
func parseArgs(args []string) (*botConfig, error) {
flagSet := &flag.FlagSet{}
nick := flagSet.String("nick", "", "bot's nick")
channels := StringArray{}
flagSet.Var(&channels, "channel", "channel to join (can be specified multiple times)")
err := flagSet.Parse(args)
if err != nil {
return nil, err
}
if *nick == "" || len(channels) == 0 {
flagSet.PrintDefaults()
return nil, errors.New("missing arguments")
}
for i := range channels {
if !strings.HasPrefix(channels[i], "#") {
channels[i] = fmt.Sprintf("#%s", channels[i])
}
}
serverPassword := os.Getenv("TWITCH_IRC_OAUTH")
if serverPassword == "" {
return nil, errors.New("set TWITCH_IRC_OAUTH environment variable")
}
return &botConfig{
nick: *nick,
channels: channels,
serverPassword: serverPassword,
}, nil
}