|
@@ -4,6 +4,7 @@
|
4
|
4
|
package irc
|
5
|
5
|
|
6
|
6
|
import (
|
|
7
|
+ "bytes"
|
7
|
8
|
"fmt"
|
8
|
9
|
"log"
|
9
|
10
|
"sort"
|
|
@@ -190,6 +191,14 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
|
190
|
191
|
sendNotice(ircfmt.Unescape(fmt.Sprintf("*** $b%s HELP$b ***", service.Name)))
|
191
|
192
|
|
192
|
193
|
if len(params) == 0 {
|
|
194
|
+ helpBannerLines := strings.Split(client.t(service.HelpBanner), "\n")
|
|
195
|
+ helpBannerLines = append(helpBannerLines, []string{
|
|
196
|
+ "",
|
|
197
|
+ client.t("To see in-depth help for a specific command, try:"),
|
|
198
|
+ ircfmt.Unescape(fmt.Sprintf(client.t(" $b/msg %s HELP <command>$b"), service.Name)),
|
|
199
|
+ "",
|
|
200
|
+ client.t("Here are the commands you can use:"),
|
|
201
|
+ }...)
|
193
|
202
|
// show general help
|
194
|
203
|
var shownHelpLines sort.StringSlice
|
195
|
204
|
var disabledCommands bool
|
|
@@ -206,7 +215,7 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
|
206
|
215
|
continue
|
207
|
216
|
}
|
208
|
217
|
|
209
|
|
- shownHelpLines = append(shownHelpLines, " "+client.t(commandInfo.helpShort))
|
|
218
|
+ shownHelpLines = append(shownHelpLines, ircfmt.Unescape(" "+client.t(commandInfo.helpShort)))
|
210
|
219
|
}
|
211
|
220
|
|
212
|
221
|
if disabledCommands {
|
|
@@ -216,12 +225,11 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
|
216
|
225
|
// sort help lines
|
217
|
226
|
sort.Sort(shownHelpLines)
|
218
|
227
|
|
219
|
|
- // assemble help text
|
220
|
|
- assembledHelpLines := strings.Join(shownHelpLines, "\n")
|
221
|
|
- fullHelp := ircfmt.Unescape(fmt.Sprintf(client.t(service.HelpBanner), assembledHelpLines))
|
222
|
|
-
|
223
|
228
|
// push out help text
|
224
|
|
- for _, line := range strings.Split(fullHelp, "\n") {
|
|
229
|
+ for _, line := range helpBannerLines {
|
|
230
|
+ sendNotice(line)
|
|
231
|
+ }
|
|
232
|
+ for _, line := range shownHelpLines {
|
225
|
233
|
sendNotice(line)
|
226
|
234
|
}
|
227
|
235
|
} else {
|
|
@@ -249,6 +257,18 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
|
249
|
257
|
sendNotice(ircfmt.Unescape(fmt.Sprintf(client.t("*** $bEnd of %s HELP$b ***"), service.Name)))
|
250
|
258
|
}
|
251
|
259
|
|
|
260
|
+func makeServiceHelpTextGenerator(cmd string, banner string) func(*Client) string {
|
|
261
|
+ return func(client *Client) string {
|
|
262
|
+ var buf bytes.Buffer
|
|
263
|
+ fmt.Fprintf(&buf, client.t("%s <subcommand> [params]"), cmd)
|
|
264
|
+ buf.WriteRune('\n')
|
|
265
|
+ buf.WriteString(client.t(banner)) // may contain newlines, that's fine
|
|
266
|
+ buf.WriteRune('\n')
|
|
267
|
+ fmt.Fprintf(&buf, client.t("For more details, try /%s HELP"), cmd)
|
|
268
|
+ return buf.String()
|
|
269
|
+ }
|
|
270
|
+}
|
|
271
|
+
|
252
|
272
|
func initializeServices() {
|
253
|
273
|
// this modifies the global Commands map,
|
254
|
274
|
// so it must be called from irc/commands.go's init()
|
|
@@ -263,12 +283,16 @@ func initializeServices() {
|
263
|
283
|
// reserve the nickname
|
264
|
284
|
restrictedNicknames = append(restrictedNicknames, service.Name)
|
265
|
285
|
|
266
|
|
- // register the protocol-level commands (NICKSERV, NS) that talk to the service
|
|
286
|
+ // register the protocol-level commands (NICKSERV, NS) that talk to the service,
|
|
287
|
+ // and their associated help entries
|
267
|
288
|
var ircCmdDef Command
|
268
|
289
|
ircCmdDef.handler = serviceCmdHandler
|
269
|
290
|
for _, ircCmd := range service.CommandAliases {
|
270
|
291
|
Commands[ircCmd] = ircCmdDef
|
271
|
292
|
oragonoServicesByCommandAlias[ircCmd] = service
|
|
293
|
+ Help[strings.ToLower(ircCmd)] = HelpEntry{
|
|
294
|
+ textGenerator: makeServiceHelpTextGenerator(ircCmd, service.HelpBanner),
|
|
295
|
+ }
|
272
|
296
|
}
|
273
|
297
|
|
274
|
298
|
// force devs to write a help entry for every command
|