2019-01-21 19:24:03 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"strings"
|
2019-01-22 01:07:03 +00:00
|
|
|
"text/template"
|
2019-03-07 16:35:42 +00:00
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
2019-01-21 19:24:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var q = `
|
|
|
|
INSERT INTO config VALUES('nick','{{.Nick}}');
|
|
|
|
INSERT INTO config VALUES('channels','{{.Channel}}');
|
|
|
|
INSERT INTO config VALUES('untappd.channels','{{.Channel}}');
|
|
|
|
INSERT INTO config VALUES('twitch.channels','{{.Channel}}');
|
|
|
|
INSERT INTO config VALUES('init',1);
|
|
|
|
`
|
|
|
|
|
|
|
|
func (c *Config) SetDefaults(mainChannel, nick string) {
|
|
|
|
if nick == mainChannel && nick == "" {
|
2019-03-07 16:35:42 +00:00
|
|
|
log.Fatal().Msgf("You must provide a nick and a mainChannel")
|
2019-01-21 19:24:03 +00:00
|
|
|
}
|
|
|
|
t := template.Must(template.New("query").Parse(q))
|
|
|
|
vals := struct {
|
|
|
|
Nick string
|
|
|
|
Channel string
|
|
|
|
ChannelKey string
|
|
|
|
}{
|
|
|
|
nick,
|
|
|
|
mainChannel,
|
|
|
|
strings.ToLower(mainChannel),
|
|
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
|
|
t.Execute(&buf, vals)
|
2021-12-20 17:40:10 +00:00
|
|
|
c.db.MustExec(`delete from config;`)
|
|
|
|
c.db.MustExec(buf.String())
|
2019-03-07 16:35:42 +00:00
|
|
|
log.Info().Msgf("Configuration initialized.")
|
2019-01-21 19:24:03 +00:00
|
|
|
}
|