3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-29 23:49:25 +01:00
ergo/irc/commands.go

292 lines
5.6 KiB
Go
Raw Normal View History

// Copyright (c) 2012-2014 Jeremy Latt
// Copyright (c) 2014-2015 Edmund Huber
2017-03-27 14:15:02 +02:00
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
// released under the MIT license
package irc
2017-06-15 18:14:19 +02:00
import "github.com/goshuirc/irc-go/ircmsg"
2012-12-09 21:51:50 +01:00
2016-06-19 04:53:52 +02:00
// Command represents a command accepted from a client.
type Command struct {
2016-06-19 13:59:18 +02:00
handler func(server *Server, client *Client, msg ircmsg.IrcMessage) bool
2016-06-20 02:04:53 +02:00
oper bool
2016-06-19 13:59:18 +02:00
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
2016-10-23 03:13:08 +02:00
capabs []string
}
2016-06-19 04:53:52 +02:00
// 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
2012-12-09 21:51:50 +01:00
}
if cmd.oper && !client.flags[Operator] {
client.Send(nil, server.name, ERR_NOPRIVILEGES, client.nick, "Permission Denied - You're not an IRC operator")
2016-06-20 02:04:53 +02:00
return false
}
if len(cmd.capabs) > 0 && !client.HasRoleCapabs(cmd.capabs...) {
2016-10-23 03:13:08 +02:00
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
}
2016-06-19 13:59:18 +02:00
if !cmd.leaveClientActive {
client.Active()
}
2017-05-09 12:36:45 +02:00
// only touch client if they're registered so that unregistered clients timeout appropriately
if client.registered && !cmd.leaveClientIdle {
2016-06-19 13:59:18 +02:00
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{
2017-03-08 12:36:13 +01:00
"ACC": {
handler: accHandler,
minParams: 3,
},
2016-11-01 14:56:21 +01:00
"AMBIANCE": {
handler: sceneHandler,
minParams: 2,
},
"AUTHENTICATE": {
handler: authenticateHandler,
usablePreReg: true,
minParams: 1,
},
2016-06-30 07:43:27 +02:00
"AWAY": {
handler: awayHandler,
minParams: 0,
},
2016-06-30 07:43:27 +02:00
"CAP": {
handler: capHandler,
usablePreReg: true,
minParams: 1,
},
"CHANSERV": {
handler: csHandler,
minParams: 1,
},
"CS": {
handler: csHandler,
minParams: 1,
},
2016-06-30 07:43:27 +02:00
"DEBUG": {
handler: debugHandler,
minParams: 1,
},
2016-11-04 03:42:58 +01:00
"DLINE": {
handler: dlineHandler,
minParams: 1,
oper: true,
},
2016-10-14 12:56:44 +02:00
"HELP": {
handler: helpHandler,
minParams: 0,
},
2017-04-30 05:53:49 +02:00
"HELPOP": {
handler: helpHandler,
minParams: 0,
},
2016-06-30 07:43:27 +02:00
"INVITE": {
handler: inviteHandler,
minParams: 2,
},
2016-06-30 07:43:27 +02:00
"ISON": {
handler: isonHandler,
minParams: 1,
},
2016-06-30 07:43:27 +02:00
"JOIN": {
handler: joinHandler,
minParams: 1,
},
2016-06-30 07:43:27 +02:00
"KICK": {
handler: kickHandler,
minParams: 2,
},
2016-06-30 07:43:27 +02:00
"KILL": {
handler: killHandler,
minParams: 1,
2016-06-20 02:04:53 +02:00
oper: true,
2016-10-23 03:13:08 +02:00
capabs: []string{"oper:local_kill"}, //TODO(dan): when we have S2S, this will be checked in the command handler itself
},
2017-01-11 13:38:16 +01:00
"KLINE": {
handler: klineHandler,
minParams: 1,
oper: true,
},
2016-06-30 07:43:27 +02:00
"LIST": {
handler: listHandler,
minParams: 0,
},
2017-01-15 01:48:47 +01:00
"LUSERS": {
handler: lusersHandler,
minParams: 0,
},
2016-06-30 07:43:27 +02:00
"MODE": {
handler: modeHandler,
minParams: 1,
},
2016-10-16 12:14:56 +02:00
"MONITOR": {
handler: monitorHandler,
minParams: 1,
},
2016-06-30 07:43:27 +02:00
"MOTD": {
handler: motdHandler,
minParams: 0,
},
2016-06-30 07:43:27 +02:00
"NAMES": {
handler: namesHandler,
minParams: 0,
},
2016-06-30 07:43:27 +02:00
"NICK": {
handler: nickHandler,
usablePreReg: true,
minParams: 1,
},
"NICKSERV": {
handler: nsHandler,
minParams: 1,
},
2016-06-30 07:43:27 +02:00
"NOTICE": {
handler: noticeHandler,
minParams: 2,
},
2016-11-01 14:56:21 +01:00
"NPC": {
handler: npcHandler,
minParams: 3,
},
"NPCA": {
handler: npcaHandler,
minParams: 3,
},
"NS": {
handler: nsHandler,
minParams: 1,
},
2016-06-30 07:43:27 +02:00
"OPER": {
handler: operHandler,
minParams: 2,
},
2016-06-30 07:43:27 +02:00
"PART": {
handler: partHandler,
minParams: 1,
},
2016-06-30 07:43:27 +02:00
"PASS": {
handler: passHandler,
usablePreReg: true,
minParams: 1,
},
2016-06-30 07:43:27 +02:00
"PING": {
2016-06-19 13:59:18 +02:00
handler: pingHandler,
usablePreReg: true,
minParams: 1,
leaveClientActive: true,
},
2016-06-30 07:43:27 +02:00
"PONG": {
2016-06-19 13:59:18 +02:00
handler: pongHandler,
usablePreReg: true,
minParams: 1,
leaveClientActive: true,
},
2016-06-30 07:43:27 +02:00
"PRIVMSG": {
handler: privmsgHandler,
minParams: 2,
},
"PROXY": {
handler: proxyHandler,
usablePreReg: true,
minParams: 5,
},
2017-06-05 04:01:37 +02:00
"RENAME": {
handler: renameHandler,
minParams: 2,
},
2016-06-30 07:43:27 +02:00
"SANICK": {
2016-06-20 02:04:53 +02:00
handler: sanickHandler,
minParams: 2,
oper: true,
},
"SAMODE": {
handler: modeHandler,
minParams: 1,
capabs: []string{"samode"},
},
2016-11-01 14:56:21 +01:00
"SCENE": {
handler: sceneHandler,
minParams: 2,
},
2017-01-14 06:52:32 +01:00
"TAGMSG": {
handler: tagmsgHandler,
minParams: 1,
},
2016-06-30 07:43:27 +02:00
"QUIT": {
handler: quitHandler,
usablePreReg: true,
minParams: 0,
},
2016-10-19 13:38:31 +02:00
"REHASH": {
handler: rehashHandler,
minParams: 0,
oper: true,
2016-10-23 03:13:08 +02:00
capabs: []string{"oper:rehash"},
2016-10-19 13:38:31 +02:00
},
2016-06-30 07:43:27 +02:00
"TIME": {
handler: timeHandler,
minParams: 0,
},
2016-06-30 07:43:27 +02:00
"TOPIC": {
handler: topicHandler,
minParams: 1,
},
2016-11-04 03:42:58 +01:00
"UNDLINE": {
2016-11-04 12:14:52 +01:00
handler: unDLineHandler,
2016-11-04 03:42:58 +01:00
minParams: 1,
oper: true,
},
2017-01-11 13:38:16 +01:00
"UNKLINE": {
handler: unKLineHandler,
minParams: 1,
oper: true,
},
2016-06-30 07:43:27 +02:00
"USER": {
handler: userHandler,
usablePreReg: true,
minParams: 4,
},
2017-01-23 17:44:35 +01:00
"USERHOST": {
handler: userhostHandler,
minParams: 1,
},
2016-06-30 07:43:27 +02:00
"VERSION": {
handler: versionHandler,
minParams: 0,
},
2016-06-30 07:43:27 +02:00
"WHO": {
handler: whoHandler,
minParams: 0,
},
2016-06-30 07:43:27 +02:00
"WHOIS": {
handler: whoisHandler,
minParams: 1,
},
2016-06-30 07:43:27 +02:00
"WHOWAS": {
handler: whowasHandler,
minParams: 1,
},
}