2012-08-17 20:38:15 +00:00
|
|
|
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 {
|
2013-02-21 03:24:51 +00:00
|
|
|
DbName string
|
|
|
|
DbServer string
|
|
|
|
Channels []string
|
|
|
|
MainChannel string
|
|
|
|
Plugins []string
|
|
|
|
Nick, Server, Pass string
|
|
|
|
Version string
|
|
|
|
CommandChar string
|
|
|
|
QuoteChance float64
|
|
|
|
QuoteTime int
|
|
|
|
LogLength int
|
|
|
|
Admins []string
|
2013-06-01 17:29:12 +00:00
|
|
|
HttpAddr string
|
2013-02-21 03:24:51 +00:00
|
|
|
UntappdToken string
|
|
|
|
UntappdFreq int
|
|
|
|
WelcomeMsgs []string
|
|
|
|
TwitterConsumerKey string
|
|
|
|
TwitterConsumerSecret string
|
|
|
|
TwitterUserKey string
|
|
|
|
TwitterUserSecret string
|
2013-03-30 11:12:27 +00:00
|
|
|
BadMsgs []string
|
2013-04-21 16:37:04 +00:00
|
|
|
Bad struct {
|
|
|
|
Msgs []string
|
|
|
|
Nicks []string
|
|
|
|
Hosts []string
|
|
|
|
}
|
2012-08-17 21:37:49 +00:00
|
|
|
}
|
2012-08-17 20:38:15 +00:00
|
|
|
|
2012-08-17 21:37:49 +00:00
|
|
|
// Readconfig loads the config data out of a JSON file located in cfile
|
2012-08-17 22:56:44 +00:00
|
|
|
func Readconfig(version, cfile string) *Config {
|
2012-08-17 20:38:15 +00:00
|
|
|
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)
|
|
|
|
}
|
2012-08-17 22:56:44 +00:00
|
|
|
c.Version = version
|
2012-08-25 04:49:48 +00:00
|
|
|
|
2012-08-25 04:51:16 +00:00
|
|
|
fmt.Printf("godeepintir version %s running.\n", c.Version)
|
2012-08-25 04:49:48 +00:00
|
|
|
|
2012-08-17 20:38:15 +00:00
|
|
|
return &c
|
|
|
|
}
|