catbase/config/config.go

100 lines
1.9 KiB
Go
Raw Normal View History

2016-01-17 18:00:44 +00:00
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
package config
import "encoding/json"
import "fmt"
import "io/ioutil"
// Config stores any system-wide startup information that cannot be easily configured via
// the database
type Config struct {
2016-03-10 18:37:07 +00:00
DB struct {
File string
Name string
Server string
}
Channels []string
MainChannel string
Plugins []string
Type string
Irc struct {
Server, Pass string
}
2016-03-11 02:11:52 +00:00
Slack struct {
Token string
}
2016-03-11 17:48:41 +00:00
Nick string
FullName string
Version string
CommandChar string
RatePerSec float64
LogLength int
Admins []string
HttpAddr string
Untappd struct {
Token string
Freq int
Channels []string
}
2016-08-30 19:40:55 +00:00
Twitch struct {
Freq int
Users map[string][]string //channel -> usernames
2016-08-09 00:44:28 +00:00
}
EnforceNicks bool
2013-02-21 03:24:51 +00:00
WelcomeMsgs []string
TwitterConsumerKey string
TwitterConsumerSecret string
TwitterUserKey string
TwitterUserSecret string
BadMsgs []string
2013-04-21 16:37:04 +00:00
Bad struct {
Msgs []string
Nicks []string
Hosts []string
}
2016-03-24 17:49:44 +00:00
Your struct {
YourChance float64
FuckingChance float64
2016-08-30 19:40:55 +00:00
DuckingChance float64
2016-03-24 17:49:44 +00:00
MaxLength int
}
2016-04-01 14:37:44 +00:00
LeftPad struct {
MaxLen int
Who string
}
2016-04-01 14:45:45 +00:00
Factoid struct {
MinLen int
QuoteChance float64
QuoteTime int
StartupFact string
}
Babbler struct {
DefaultUsers []string
}
}
// Readconfig loads the config data out of a JSON file located in cfile
func Readconfig(version, cfile string) *Config {
fmt.Printf("Using %s as config file.\n", cfile)
file, e := ioutil.ReadFile(cfile)
if e != nil {
panic("Couldn't read config file!")
}
var c Config
err := json.Unmarshal(file, &c)
if err != nil {
panic(err)
}
c.Version = version
2012-08-25 04:49:48 +00:00
2016-03-10 18:37:07 +00:00
if c.Type == "" {
c.Type = "irc"
}
fmt.Printf("godeepintir version %s running.\n", c.Version)
2012-08-25 04:49:48 +00:00
return &c
}