Przeglądaj źródła

review fixes

tags/v1.1.0-rc1
Shivaram Lingamneni 5 lat temu
rodzic
commit
38b228af6a
4 zmienionych plików z 67 dodań i 40 usunięć
  1. 5
    2
      irc/errors.go
  2. 24
    34
      irc/nickserv.go
  3. 17
    4
      irc/services.go
  4. 21
    0
      irc/utils/args.go

+ 5
- 2
irc/errors.go Wyświetl plik

@@ -5,7 +5,10 @@
5 5
 
6 6
 package irc
7 7
 
8
-import "errors"
8
+import (
9
+	"errors"
10
+	"github.com/oragono/oragono/irc/utils"
11
+)
9 12
 
10 13
 // Runtime Errors
11 14
 var (
@@ -40,7 +43,7 @@ var (
40 43
 	errInvalidUsername                = errors.New("Invalid username")
41 44
 	errFeatureDisabled                = errors.New(`That feature is disabled`)
42 45
 	errBanned                         = errors.New("IP or nickmask banned")
43
-	errInvalidParams                  = errors.New("Invalid parameters")
46
+	errInvalidParams                  = utils.ErrInvalidParams
44 47
 )
45 48
 
46 49
 // Socket Errors

+ 24
- 34
irc/nickserv.go Wyświetl plik

@@ -12,6 +12,7 @@ import (
12 12
 	"github.com/goshuirc/irc-go/ircfmt"
13 13
 
14 14
 	"github.com/oragono/oragono/irc/modes"
15
+	"github.com/oragono/oragono/irc/utils"
15 16
 )
16 17
 
17 18
 // "enabled" callbacks for specific nickserv commands
@@ -209,46 +210,51 @@ information on the settings and their possible values, see HELP SET.`,
209 210
 			capabs:    []string{"accreg"},
210 211
 		},
211 212
 		"set": {
212
-			handler: nsSetHandler,
213
-			help: `Syntax $bSET <setting> <value>$b
213
+			handler:   nsSetHandler,
214
+			helpShort: `$bSET$b modifies your account settings`,
215
+			// these are broken out as separate strings so they can be translated separately
216
+			helpStrings: []string{
217
+				`Syntax $bSET <setting> <value>$b
214 218
 
215
-Set modifies your account settings. The following settings ara available:
219
+Set modifies your account settings. The following settings are available:`,
216 220
 
217
-$bENFORCE$b
221
+				`$bENFORCE$b
218 222
 'enforce' lets you specify a custom enforcement mechanism for your registered
219 223
 nicknames. Your options are:
220 224
 1. 'none'    [no enforcement, overriding the server default]
221 225
 2. 'timeout' [anyone using the nick must authenticate before a deadline,
222 226
               or else they will be renamed]
223 227
 3. 'strict'  [you must already be authenticated to use the nick]
224
-4. 'default' [use the server default]
228
+4. 'default' [use the server default]`,
225 229
 
226
-$bBOUNCER$b
230
+				`$bBOUNCER$b
227 231
 If 'bouncer' is enabled and you are already logged in and using a nick, a
228 232
 second client of yours that authenticates with SASL and requests the same nick
229 233
 is allowed to attach to the nick as well (this is comparable to the behavior
230 234
 of IRC "bouncers" like ZNC). Your options are 'on' (allow this behavior),
231
-'off' (disallow it), and 'default' (use the server default value).
235
+'off' (disallow it), and 'default' (use the server default value).`,
232 236
 
233
-$bAUTOREPLAY-LINES$b
237
+				`$bAUTOREPLAY-LINES$b
234 238
 'autoreplay-lines' controls the number of lines of channel history that will
235 239
 be replayed to you automatically when joining a channel. Your options are any
236 240
 positive number, 0 to disable the feature, and 'default' to use the server
237
-default.
241
+default.`,
238 242
 
239
-$bAUTOREPLAY-JOINS$b
243
+				`$bAUTOREPLAY-JOINS$b
240 244
 'autoreplay-joins' controls whether autoreplayed channel history will include
241 245
 lines for join and part. This provides more information about the context of
242
-messages, but may be spammy. Your options are 'on' and 'off'.
243
-`,
244
-			helpShort:    `$bSET$b modifies your account settings`,
246
+messages, but may be spammy. Your options are 'on' and 'off'.`,
247
+			},
245 248
 			authRequired: true,
246 249
 			enabled:      servCmdRequiresAccreg,
247 250
 			minParams:    2,
248 251
 		},
249 252
 		"saset": {
250
-			handler:   nsSetHandler,
251
-			help:      `Syntax: $bSASET <account> <setting> <value>$b`,
253
+			handler: nsSetHandler,
254
+			help: `Syntax: $bSASET <account> <setting> <value>$b
255
+
256
+SASET modifies the values of someone else's account settings. For more
257
+information on the settings and their possible values, see HELP SET.`,
252 258
 			helpShort: `$bSASET$b modifies another user's account settings`,
253 259
 			enabled:   servCmdRequiresAccreg,
254 260
 			minParams: 3,
@@ -328,22 +334,6 @@ func displaySetting(settingName string, settings AccountSettings, client *Client
328 334
 	}
329 335
 }
330 336
 
331
-func stringToBool(str string) (result bool, err error) {
332
-	switch strings.ToLower(str) {
333
-	case "on":
334
-		result = true
335
-	case "off":
336
-		result = false
337
-	case "true":
338
-		result = true
339
-	case "false":
340
-		result = false
341
-	default:
342
-		err = errInvalidParams
343
-	}
344
-	return
345
-}
346
-
347 337
 func nsSetHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
348 338
 	var account string
349 339
 	if command == "saset" {
@@ -395,7 +385,7 @@ func nsSetHandler(server *Server, client *Client, command string, params []strin
395 385
 			newValue = BouncerAllowedServerDefault
396 386
 		} else {
397 387
 			var enabled bool
398
-			enabled, err = stringToBool(params[1])
388
+			enabled, err = utils.StringToBool(params[1])
399 389
 			if enabled {
400 390
 				newValue = BouncerAllowedByUser
401 391
 			} else {
@@ -411,7 +401,7 @@ func nsSetHandler(server *Server, client *Client, command string, params []strin
411 401
 		}
412 402
 	case "autoreplay-joins":
413 403
 		var newValue bool
414
-		newValue, err = stringToBool(params[1])
404
+		newValue, err = utils.StringToBool(params[1])
415 405
 		if err == nil {
416 406
 			munger = func(in AccountSettings) (out AccountSettings, err error) {
417 407
 				out = in
@@ -787,7 +777,7 @@ func nsPasswdHandler(server *Server, client *Client, command string, params []st
787 777
 			}
788 778
 		}
789 779
 	default:
790
-		errorMessage = "Invalid parameters"
780
+		errorMessage = `Invalid parameters`
791 781
 	}
792 782
 
793 783
 	if errorMessage != "" {

+ 17
- 4
irc/services.go Wyświetl plik

@@ -30,6 +30,7 @@ type serviceCommand struct {
30 30
 	capabs       []string // oper capabs the given user has to have to access this command
31 31
 	handler      func(server *Server, client *Client, command string, params []string, rb *ResponseBuffer)
32 32
 	help         string
33
+	helpStrings  []string
33 34
 	helpShort    string
34 35
 	authRequired bool
35 36
 	hidden       bool
@@ -228,8 +229,18 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
228 229
 		if commandInfo == nil {
229 230
 			sendNotice(client.t(fmt.Sprintf("Unknown command. To see available commands, run /%s HELP", service.ShortName)))
230 231
 		} else {
231
-			for _, line := range strings.Split(ircfmt.Unescape(client.t(commandInfo.help)), "\n") {
232
-				sendNotice(line)
232
+			helpStrings := commandInfo.helpStrings
233
+			if helpStrings == nil {
234
+				hsArray := [1]string{commandInfo.help}
235
+				helpStrings = hsArray[:]
236
+			}
237
+			for i, helpString := range helpStrings {
238
+				if 0 < i {
239
+					sendNotice("")
240
+				}
241
+				for _, line := range strings.Split(ircfmt.Unescape(client.t(helpString)), "\n") {
242
+					sendNotice(line)
243
+				}
233 244
 			}
234 245
 		}
235 246
 	}
@@ -261,8 +272,10 @@ func initializeServices() {
261 272
 
262 273
 		// force devs to write a help entry for every command
263 274
 		for commandName, commandInfo := range service.Commands {
264
-			if commandInfo.aliasOf == "" && !commandInfo.hidden && (commandInfo.help == "" || commandInfo.helpShort == "") {
265
-				log.Fatal(fmt.Sprintf("help entry missing for %s command %s", serviceName, commandName))
275
+			if commandInfo.aliasOf == "" && !commandInfo.hidden {
276
+				if (commandInfo.help == "" && commandInfo.helpStrings == nil) || commandInfo.helpShort == "" {
277
+					log.Fatal(fmt.Sprintf("help entry missing for %s command %s", serviceName, commandName))
278
+				}
266 279
 			}
267 280
 		}
268 281
 	}

+ 21
- 0
irc/utils/args.go Wyświetl plik

@@ -3,6 +3,15 @@
3 3
 
4 4
 package utils
5 5
 
6
+import (
7
+	"errors"
8
+	"strings"
9
+)
10
+
11
+var (
12
+	ErrInvalidParams = errors.New("Invalid parameters")
13
+)
14
+
6 15
 // ArgsToStrings takes the arguments and splits them into a series of strings,
7 16
 // each argument separated by delim and each string bounded by maxLength.
8 17
 func ArgsToStrings(maxLength int, arguments []string, delim string) []string {
@@ -33,3 +42,15 @@ func ArgsToStrings(maxLength int, arguments []string, delim string) []string {
33 42
 
34 43
 	return messages
35 44
 }
45
+
46
+func StringToBool(str string) (result bool, err error) {
47
+	switch strings.ToLower(str) {
48
+	case "on", "true", "t", "yes", "y":
49
+		result = true
50
+	case "off", "false", "f", "no", "n":
51
+		result = false
52
+	default:
53
+		err = ErrInvalidParams
54
+	}
55
+	return
56
+}

Ładowanie…
Anuluj
Zapisz