1// This program is free software: you can redistribute it and/or modify 2// it under the terms of the GNU Affero General Public License as 3// published by the Free Software Foundation, either version 3 of the 4// License, or (at your option) any later version. 5// 6// This program is distributed in the hope that it will be useful, but 7// WITHOUT ANY WARRANTY; without even the implied warranty of 8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 9// Affero General Public License for more details.10//11// You should have received a copy of the GNU Affero General Public12// License along with this program. If not, see <http://www.gnu.org/licenses/>.1314package main1516import (17 "encoding/json"18 "io/ioutil"19 "os"20 "path/filepath"21)2223type config struct {24 // Nickname of the irc bot.25 Nick string `json:"nickname"`2627 // Realname of the irc bot.28 Name string `json:"realname"`2930 // Hostname of the irc server.31 Host string `json:"hostname"`3233 // Port to connect to.34 Port int `json:"port"`3536 // Path to directory containing module configs.37 Conf string `json:"configs"`3839 // Path to SSL cert (if any).40 Cert string `json:"cert"`4142 // Path to SSL client certificate (if any).43 ClientCert string `json:"client_cert"`4445 // Path to SSL client key (if any).46 ClientKey string `json:"client_key"`4748 // List of channels to connect to.49 Chan []string `json:"channels"`50}5152func confDefaults() config {53 return config{54 Nick: "marvin",55 Name: "marvin IRC Bot",56 Host: "chat.freenode.net",57 Port: 6667,58 Conf: filepath.Join(os.Getenv("HOME"), appName),59 }60}6162func readConfig(path string) (c config, err error) {63 c = confDefaults()64 data, err := ioutil.ReadFile(path)65 if err != nil {66 return67 }6869 if err = json.Unmarshal(data, &c); err != nil {70 return71 }7273 return74}