-
Notifications
You must be signed in to change notification settings - Fork 178
/
commands.go
279 lines (272 loc) · 5.33 KB
/
commands.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// Copyright (c) 2012-2014 Jeremy Latt
// Copyright (c) 2014-2015 Edmund Huber
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
// released under the MIT license
package irc
import (
"github.com/DanielOaks/girc-go/ircmsg"
)
// Command represents a command accepted from a client.
type Command struct {
handler func(server *Server, client *Client, msg ircmsg.IrcMessage) bool
oper bool
usablePreReg bool
leaveClientActive bool // if true, leaves the client active time alone. reversed because we can't default a struct element to True
leaveClientIdle bool
minParams int
capabs []string
}
// Run runs this command with the given client/message.
func (cmd *Command) Run(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
if !client.registered && !cmd.usablePreReg {
client.Send(nil, server.name, ERR_NOTREGISTERED, client.nick, "You need to register before you can use that command")
return false
}
if cmd.oper && !client.flags[Operator] {
client.Send(nil, server.name, ERR_NOPRIVILEGES, client.nick, "Permission Denied - You're not an IRC operator")
return false
}
if len(cmd.capabs) > 0 && !client.HasCapabs(cmd.capabs...) {
client.Send(nil, server.name, ERR_NOPRIVILEGES, client.nick, "Permission Denied")
return false
}
if len(msg.Params) < cmd.minParams {
client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.nick, msg.Command, "Not enough parameters")
return false
}
if !cmd.leaveClientActive {
client.Active()
}
if !cmd.leaveClientIdle {
client.Touch()
}
exiting := cmd.handler(server, client, msg)
// after each command, see if we can send registration to the client
if !client.registered {
server.tryRegister(client)
}
return exiting
}
// Commands holds all commands executable by a client connected to us.
var Commands = map[string]Command{
"AMBIANCE": {
handler: sceneHandler,
minParams: 2,
},
"AUTHENTICATE": {
handler: authenticateHandler,
usablePreReg: true,
minParams: 1,
},
"AWAY": {
handler: awayHandler,
minParams: 0,
},
"CAP": {
handler: capHandler,
usablePreReg: true,
minParams: 1,
},
"CHANSERV": {
handler: csHandler,
minParams: 1,
},
"CS": {
handler: csHandler,
minParams: 1,
},
"DEBUG": {
handler: debugHandler,
minParams: 1,
},
"DLINE": {
handler: dlineHandler,
minParams: 1,
oper: true,
},
"HELP": {
handler: helpHandler,
minParams: 0,
},
"INVITE": {
handler: inviteHandler,
minParams: 2,
},
"ISON": {
handler: isonHandler,
minParams: 1,
},
"JOIN": {
handler: joinHandler,
minParams: 1,
},
"KICK": {
handler: kickHandler,
minParams: 2,
},
"KILL": {
handler: killHandler,
minParams: 1,
oper: true,
capabs: []string{"oper:local_kill"}, //TODO(dan): when we have S2S, this will be checked in the command handler itself
},
"KLINE": {
handler: klineHandler,
minParams: 1,
oper: true,
},
"LIST": {
handler: listHandler,
minParams: 0,
},
"LUSERS": {
handler: lusersHandler,
minParams: 0,
},
"MODE": {
handler: modeHandler,
minParams: 1,
},
"MONITOR": {
handler: monitorHandler,
minParams: 1,
},
"MOTD": {
handler: motdHandler,
minParams: 0,
},
"NAMES": {
handler: namesHandler,
minParams: 0,
},
"NICK": {
handler: nickHandler,
usablePreReg: true,
minParams: 1,
},
"NICKSERV": {
handler: nsHandler,
minParams: 1,
},
"NOTICE": {
handler: noticeHandler,
minParams: 2,
},
"NPC": {
handler: npcHandler,
minParams: 3,
},
"NPCA": {
handler: npcaHandler,
minParams: 3,
},
"NS": {
handler: nsHandler,
minParams: 1,
},
"OPER": {
handler: operHandler,
minParams: 2,
},
"PART": {
handler: partHandler,
minParams: 1,
},
"PASS": {
handler: passHandler,
usablePreReg: true,
minParams: 1,
},
"PING": {
handler: pingHandler,
usablePreReg: true,
minParams: 1,
leaveClientActive: true,
},
"PONG": {
handler: pongHandler,
usablePreReg: true,
minParams: 1,
leaveClientActive: true,
},
"PRIVMSG": {
handler: privmsgHandler,
minParams: 2,
},
"SANICK": {
handler: sanickHandler,
minParams: 2,
oper: true,
},
"SAMODE": {
handler: modeHandler,
minParams: 1,
capabs: []string{"samode"},
},
"SCENE": {
handler: sceneHandler,
minParams: 2,
},
"TAGMSG": {
handler: tagmsgHandler,
minParams: 1,
},
"QUIT": {
handler: quitHandler,
usablePreReg: true,
minParams: 0,
},
"REG": {
handler: regHandler,
minParams: 3,
},
"REHASH": {
handler: rehashHandler,
minParams: 0,
oper: true,
capabs: []string{"oper:rehash"},
},
"TIME": {
handler: timeHandler,
minParams: 0,
},
"TOPIC": {
handler: topicHandler,
minParams: 1,
},
"UNDLINE": {
handler: unDLineHandler,
minParams: 1,
oper: true,
},
"UNKLINE": {
handler: unKLineHandler,
minParams: 1,
oper: true,
},
"USER": {
handler: userHandler,
usablePreReg: true,
minParams: 4,
},
"USERHOST": {
handler: userhostHandler,
minParams: 1,
},
"VERSION": {
handler: versionHandler,
minParams: 0,
},
"WHO": {
handler: whoHandler,
minParams: 0,
},
"WHOIS": {
handler: whoisHandler,
minParams: 1,
},
"WHOWAS": {
handler: whowasHandler,
minParams: 1,
},
}