/
admin.go
89 lines (74 loc) · 1.92 KB
/
admin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// This file is subject to a 1-clause BSD license.
// Its contents can be found in the enclosed LICENSE file.
package admin
import (
"github.com/chimeracoder/gopherbot/cmd"
"github.com/chimeracoder/gopherbot/irc"
"github.com/chimeracoder/gopherbot/plugin"
"github.com/chimeracoder/gopherbot/proto"
)
func init() { plugin.Register(New) }
type Plugin struct {
*plugin.Base
}
func New(profile string) plugin.Plugin {
p := new(Plugin)
p.Base = plugin.New(profile, "admin")
return p
}
func (p *Plugin) Load(c *proto.Client) (err error) {
err = p.Base.Load(c)
if err != nil {
return
}
comm := new(cmd.Command)
comm.Name = "quit"
comm.Description = "Unconditionally quit the bot program"
comm.Restricted = true
comm.Execute = func(cmd *cmd.Command, c *proto.Client, m *proto.Message) {
c.Quit("")
}
cmd.Register(comm)
comm = new(cmd.Command)
comm.Name = "join"
comm.Description = "Join the given channel"
comm.Restricted = true
comm.Params = []cmd.Param{
{Name: "channel", Optional: false, Pattern: cmd.RegChannel},
{Name: "key", Optional: true, Pattern: cmd.RegAny},
{Name: "chanservpass", Optional: true, Pattern: cmd.RegAny},
}
comm.Execute = func(cmd *cmd.Command, c *proto.Client, m *proto.Message) {
var ch irc.Channel
ch.Name = cmd.Params[0].Value
if len(cmd.Params) > 1 {
ch.Key = cmd.Params[1].Value
}
if len(cmd.Params) > 2 {
ch.ChanservPassword = cmd.Params[2].Value
}
c.Join(&ch)
}
cmd.Register(comm)
comm = new(cmd.Command)
comm.Name = "leave"
comm.Description = "Leave the given channel"
comm.Restricted = true
comm.Params = []cmd.Param{
{Name: "channel", Optional: true, Pattern: cmd.RegChannel},
}
comm.Execute = func(cmd *cmd.Command, c *proto.Client, m *proto.Message) {
var ch irc.Channel
if len(cmd.Params) > 0 {
ch.Name = cmd.Params[0].Value
} else {
if !m.FromChannel() {
return
}
ch.Name = m.Receiver
}
c.Part(&ch)
}
cmd.Register(comm)
return
}