package main
import (
"encoding/json"
"log"
"os"
)
type Config struct {
IRC IRCConfig `json:"kwargs"`
Channels []string `json:"channels"`
Channel string `json:"channel"`
HandlebotCfg `json:"handlebot"`
}
type IRCConfig struct {
Server string `json:"host"`
TLS bool `json:"tls"`
Port int `json:"port"`
User string `json:"user"`
Name string `json:"realname"`
Nick string `json:"nick"`
Password string `json:"password"`
}
type HandlebotCfg struct {
CommandPrefix string `json:"command_prefix"`
Database string `json:"database"`
APIKeys APIKeys `json:"keys"`
}
type APIKeys struct {
YouTube string `json:"youtube"`
WolframAlpha string `json:"wolframalpha"`
MapQuest string `json:"mapquest"`
OpenWeatherMap string `json:"openweathermap"`
}
func parseConfig(path string) *Config {
var cfg *Config
file, err := os.Open(path)
if err != nil {
log.Fatal("couldn't open the config file: ", err)
}
defer file.Close()
if err := json.NewDecoder(file).Decode(&cfg); err != nil {
log.Fatal("couldn't parse the config file: ", err)
}
if cfg.CommandPrefix == "" {
cfg.CommandPrefix = "."
}
return cfg
}