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 nickserv
15
16import (
17	"github.com/nmeum/marvin/irc"
18	"github.com/nmeum/marvin/modules"
19	"strings"
20)
21
22type Module struct {
23	NickServ string `json:"nickserv"`
24	Password string `json:"password"`
25	Keyword  string `json:"keyword"`
26}
27
28func Init(moduleSet *modules.ModuleSet) {
29	moduleSet.Register(new(Module))
30}
31
32func (m *Module) Name() string {
33	return "nickserv"
34}
35
36func (m *Module) Help() string {
37	return "Enables authentication with NickServ."
38}
39
40func (m *Module) Defaults() {
41	m.NickServ = "NickServ"
42	m.Keyword = "identify"
43}
44
45func (m *Module) Load(client *irc.Client) error {
46	if len(m.Password) <= 0 {
47		return nil
48	}
49
50	client.CmdHook("notice", func(c *irc.Client, msg irc.Message) error {
51		if msg.Sender.Name != m.NickServ || !strings.Contains(msg.Data, m.Keyword) {
52			return nil
53		}
54
55		return c.Write("PRIVMSG %s :identify %s",
56			m.NickServ, m.Password)
57	})
58
59	return nil
60}