marvin

A simple and modular IRC bot

git clone https://git.8pit.net/marvin.git

 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 Public
12// License along with this program. If not, see <http://www.gnu.org/licenses/>.
13
14package main
15
16import (
17	"encoding/json"
18	"io/ioutil"
19	"os"
20	"path/filepath"
21)
22
23type config struct {
24	// Nickname of the irc bot.
25	Nick string `json:"nickname"`
26
27	// Realname of the irc bot.
28	Name string `json:"realname"`
29
30	// Hostname of the irc server.
31	Host string `json:"hostname"`
32
33	// Port to connect to.
34	Port int `json:"port"`
35
36	// Path to directory containing module configs.
37	Conf string `json:"configs"`
38
39	// Path to SSL cert (if any).
40	Cert string `json:"cert"`
41
42	// Path to SSL client certificate (if any).
43	ClientCert string `json:"client_cert"`
44
45	// Path to SSL client key (if any).
46	ClientKey string `json:"client_key"`
47
48	// List of channels to connect to.
49	Chan []string `json:"channels"`
50}
51
52func 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}
61
62func readConfig(path string) (c config, err error) {
63	c = confDefaults()
64	data, err := ioutil.ReadFile(path)
65	if err != nil {
66		return
67	}
68
69	if err = json.Unmarshal(data, &c); err != nil {
70		return
71	}
72
73	return
74}