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
|
|
|
|
LogLength int
|
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-17 20:38:15 +00:00
|
|
|
return &c
|
|
|
|
}
|