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 {
|
2012-08-17 21:37:49 +00:00
|
|
|
DbName string
|
|
|
|
DbServer string
|
|
|
|
Channels []string
|
2012-08-17 22:09:29 +00:00
|
|
|
MainChannel string
|
2012-08-17 21:37:49 +00:00
|
|
|
Plugins []string
|
|
|
|
Nick, Server, Pass string
|
2012-08-17 22:56:44 +00:00
|
|
|
Version string
|
2012-08-18 01:39:26 +00:00
|
|
|
CommandChar string
|
2012-08-20 01:28:25 +00:00
|
|
|
QuoteChance float64
|
2012-08-23 20:28:45 +00:00
|
|
|
QuoteTime int
|
2012-08-20 01:28:25 +00:00
|
|
|
LogLength int
|
2012-08-26 23:23:51 +00:00
|
|
|
Admins []string
|
2012-12-01 23:01:03 +00:00
|
|
|
UntappdToken string
|
|
|
|
UntappdFreq int
|
2013-01-12 16:32:42 +00:00
|
|
|
WelcomeMsgs []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
|
|
|
|
}
|