|
@@ -11,6 +11,7 @@ import (
|
11
|
11
|
|
12
|
12
|
"github.com/goshuirc/irc-go/ircfmt"
|
13
|
13
|
"github.com/goshuirc/irc-go/ircmsg"
|
|
14
|
+ "github.com/oragono/oragono/irc/utils"
|
14
|
15
|
)
|
15
|
16
|
|
16
|
17
|
// defines an IRC service, e.g., NICKSERV
|
|
@@ -32,6 +33,7 @@ type serviceCommand struct {
|
32
|
33
|
authRequired bool
|
33
|
34
|
enabled func(*Config) bool // is this command enabled in the server config?
|
34
|
35
|
minParams int
|
|
36
|
+ maxParams int // split into at most n params, with last param containing remaining unsplit text
|
35
|
37
|
}
|
36
|
38
|
|
37
|
39
|
// looks up a command in the table of command definitions for a service, resolving aliases
|
|
@@ -97,29 +99,49 @@ func serviceCmdHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb
|
97
|
99
|
return false
|
98
|
100
|
}
|
99
|
101
|
|
100
|
|
- serviceRunCommand(service, server, client, msg.Params, rb)
|
|
102
|
+ if len(msg.Params) == 0 {
|
|
103
|
+ return false
|
|
104
|
+ }
|
|
105
|
+ commandName := strings.ToLower(msg.Params[0])
|
|
106
|
+ params := msg.Params[1:]
|
|
107
|
+ cmd := lookupServiceCommand(service.Commands, commandName)
|
|
108
|
+ // for a maxParams command, join all final parameters together if necessary
|
|
109
|
+ if cmd != nil && cmd.maxParams != 0 && cmd.maxParams < len(params) {
|
|
110
|
+ newParams := make([]string, cmd.maxParams)
|
|
111
|
+ copy(newParams, params[:cmd.maxParams-1])
|
|
112
|
+ newParams[cmd.maxParams-1] = strings.Join(params[cmd.maxParams-1:], " ")
|
|
113
|
+ params = newParams
|
|
114
|
+ }
|
|
115
|
+ serviceRunCommand(service, server, client, cmd, commandName, params, rb)
|
101
|
116
|
return false
|
102
|
117
|
}
|
103
|
118
|
|
104
|
119
|
// generic handler for service PRIVMSG, like `/msg NickServ INFO`
|
105
|
120
|
func servicePrivmsgHandler(service *ircService, server *Server, client *Client, message string, rb *ResponseBuffer) {
|
106
|
|
- serviceRunCommand(service, server, client, strings.Fields(message), rb)
|
107
|
|
-}
|
108
|
|
-
|
109
|
|
-// actually execute a service command
|
110
|
|
-func serviceRunCommand(service *ircService, server *Server, client *Client, params []string, rb *ResponseBuffer) {
|
|
121
|
+ params := strings.Fields(message)
|
111
|
122
|
if len(params) == 0 {
|
112
|
123
|
return
|
113
|
124
|
}
|
|
125
|
+
|
|
126
|
+ // look up the service command to see how to parse it
|
114
|
127
|
commandName := strings.ToLower(params[0])
|
115
|
|
- params = params[1:]
|
|
128
|
+ cmd := lookupServiceCommand(service.Commands, commandName)
|
|
129
|
+ // reparse if needed
|
|
130
|
+ if cmd != nil && cmd.maxParams != 0 {
|
|
131
|
+ params = utils.FieldsN(message, cmd.maxParams+1)[1:]
|
|
132
|
+ } else {
|
|
133
|
+ params = params[1:]
|
|
134
|
+ }
|
|
135
|
+ serviceRunCommand(service, server, client, cmd, commandName, params, rb)
|
|
136
|
+}
|
116
|
137
|
|
|
138
|
+// actually execute a service command
|
|
139
|
+func serviceRunCommand(service *ircService, server *Server, client *Client, cmd *serviceCommand, commandName string, params []string, rb *ResponseBuffer) {
|
117
|
140
|
nick := rb.target.Nick()
|
118
|
141
|
sendNotice := func(notice string) {
|
119
|
142
|
rb.Add(nil, service.Name, "NOTICE", nick, notice)
|
120
|
143
|
}
|
121
|
144
|
|
122
|
|
- cmd := lookupServiceCommand(service.Commands, commandName)
|
123
|
145
|
if cmd == nil {
|
124
|
146
|
sendNotice(fmt.Sprintf("%s /%s HELP", client.t("Unknown command. To see available commands, run"), service.ShortName))
|
125
|
147
|
return
|