Browse Source

refactor /HELP for services

1. DRY "banner" descriptions of each services
2. `/HELP NICKSERV` now refers the user to `/NICKSERV HELP`, etc.
3. Fix double translation of `textGenerator` output
tags/v1.2.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
1c583d775c
6 changed files with 35 additions and 61 deletions
  1. 1
    7
      irc/chanserv.go
  2. 1
    1
      irc/handlers.go
  3. 0
    32
      irc/help.go
  4. 1
    7
      irc/hostserv.go
  5. 1
    7
      irc/nickserv.go
  6. 31
    7
      irc/services.go

+ 1
- 7
irc/chanserv.go View File

@@ -17,13 +17,7 @@ import (
17 17
 	"github.com/oragono/oragono/irc/sno"
18 18
 )
19 19
 
20
-const chanservHelp = `ChanServ lets you register and manage channels.
21
-
22
-To see in-depth help for a specific ChanServ command, try:
23
-    $b/CS HELP <command>$b
24
-
25
-Here are the commands you can use:
26
-%s`
20
+const chanservHelp = `ChanServ lets you register and manage channels.`
27 21
 
28 22
 func chanregEnabled(config *Config) bool {
29 23
 	return config.Channels.Registration.Enabled

+ 1
- 1
irc/handlers.go View File

@@ -1091,7 +1091,7 @@ Get an explanation of <argument>, or "index" for a list of help topics.`), rb)
1091 1091
 
1092 1092
 	if exists && (!helpHandler.oper || (helpHandler.oper && client.HasMode(modes.Operator))) {
1093 1093
 		if helpHandler.textGenerator != nil {
1094
-			client.sendHelp(strings.ToUpper(argument), client.t(helpHandler.textGenerator(client)), rb)
1094
+			client.sendHelp(strings.ToUpper(argument), helpHandler.textGenerator(client), rb)
1095 1095
 		} else {
1096 1096
 			client.sendHelp(strings.ToUpper(argument), client.t(helpHandler.text), rb)
1097 1097
 		}

+ 0
- 32
irc/help.go View File

@@ -135,11 +135,6 @@ message (and as your quit message if you don't return in time).`,
135 135
 Used in capability negotiation. See the IRCv3 specs for more info:
136 136
 http://ircv3.net/specs/core/capability-negotiation-3.1.html
137 137
 http://ircv3.net/specs/core/capability-negotiation-3.2.html`,
138
-	},
139
-	"chanserv": {
140
-		text: `CHANSERV <subcommand> [params]
141
-
142
-ChanServ controls channel registrations.`,
143 138
 	},
144 139
 	"chathistory": {
145 140
 		text: `CHATHISTORY [params]
@@ -147,11 +142,6 @@ ChanServ controls channel registrations.`,
147 142
 CHATHISTORY is an experimental history replay command. See these documents:
148 143
 https://github.com/MuffinMedic/ircv3-specifications/blob/chathistory/extensions/chathistory.md
149 144
 https://gist.github.com/DanielOaks/c104ad6e8759c01eb5c826d627caf80d`,
150
-	},
151
-	"cs": {
152
-		text: `CS <subcommand> [params]
153
-
154
-ChanServ controls channel registrations.`,
155 145
 	},
156 146
 	"debug": {
157 147
 		oper: true,
@@ -212,18 +202,6 @@ Replay message history. <target> can be a channel name, "me" to replay direct
212 202
 message history, or a nickname to replay another client's direct message
213 203
 history (they must be logged into the same account as you). At most [limit]
214 204
 messages will be replayed.`,
215
-	},
216
-	"hostserv": {
217
-		text: `HOSTSERV <command> [params]
218
-
219
-HostServ lets you manage your vhost (a string displayed in place of your
220
-real hostname).`,
221
-	},
222
-	"hs": {
223
-		text: `HS <command> [params]
224
-
225
-HostServ lets you manage your vhost (a string displayed in place of your
226
-real hostname).`,
227 205
 	},
228 206
 	"info": {
229 207
 		text: `INFO
@@ -350,11 +328,6 @@ view the channel membership prefixes supported by this server, see the help for
350 328
 		text: `NICK <newnick>
351 329
 
352 330
 Sets your nickname to the new given one.`,
353
-	},
354
-	"nickserv": {
355
-		text: `NICKSERV <subcommand> [params]
356
-
357
-NickServ controls accounts and user registrations.`,
358 331
 	},
359 332
 	"notice": {
360 333
 		text: `NOTICE <target>{,<target>} <text to be sent>
@@ -374,11 +347,6 @@ Requires the roleplay mode (+E) to be set on the target.`,
374 347
 The NPC command is used to send an action to the target as the source.
375 348
 
376 349
 Requires the roleplay mode (+E) to be set on the target.`,
377
-	},
378
-	"ns": {
379
-		text: `NS <subcommand> [params]
380
-
381
-NickServ controls accounts and user registrations.`,
382 350
 	},
383 351
 	"oper": {
384 352
 		text: `OPER <name> <password>

+ 1
- 7
irc/hostserv.go View File

@@ -11,13 +11,7 @@ import (
11 11
 )
12 12
 
13 13
 const hostservHelp = `HostServ lets you manage your vhost (i.e., the string displayed
14
-in place of your client's hostname/IP).
15
-
16
-To see in-depth help for a specific HostServ command, try:
17
-    $b/HS HELP <command>$b
18
-
19
-Here are the commands you can use:
20
-%s`
14
+in place of your client's hostname/IP).`
21 15
 
22 16
 var (
23 17
 	errVHostBadCharacters = errors.New("Vhost contains prohibited characters")

+ 1
- 7
irc/nickserv.go View File

@@ -41,13 +41,7 @@ const (
41 41
 	nsTimeoutNotice = `This nickname is reserved. Please login within %v (using $b/msg NickServ IDENTIFY <password>$b or SASL), or switch to a different nickname.`
42 42
 )
43 43
 
44
-const nickservHelp = `NickServ lets you register and login to an account.
45
-
46
-To see in-depth help for a specific NickServ command, try:
47
-    $b/NS HELP <command>$b
48
-
49
-Here are the commands you can use:
50
-%s`
44
+const nickservHelp = `NickServ lets you register and log into an account.`
51 45
 
52 46
 var (
53 47
 	nickservCommands = map[string]*serviceCommand{

+ 31
- 7
irc/services.go View File

@@ -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

Loading…
Cancel
Save