review fixes

This commit is contained in:
Shivaram Lingamneni 2019-05-20 02:56:49 -04:00
parent f10ed05f86
commit 38b228af6a
4 changed files with 67 additions and 40 deletions

View File

@ -5,7 +5,10 @@
package irc
import "errors"
import (
"errors"
"github.com/oragono/oragono/irc/utils"
)
// Runtime Errors
var (
@ -40,7 +43,7 @@ var (
errInvalidUsername = errors.New("Invalid username")
errFeatureDisabled = errors.New(`That feature is disabled`)
errBanned = errors.New("IP or nickmask banned")
errInvalidParams = errors.New("Invalid parameters")
errInvalidParams = utils.ErrInvalidParams
)
// Socket Errors

View File

@ -12,6 +12,7 @@ import (
"github.com/goshuirc/irc-go/ircfmt"
"github.com/oragono/oragono/irc/modes"
"github.com/oragono/oragono/irc/utils"
)
// "enabled" callbacks for specific nickserv commands
@ -210,45 +211,50 @@ information on the settings and their possible values, see HELP SET.`,
},
"set": {
handler: nsSetHandler,
help: `Syntax $bSET <setting> <value>$b
helpShort: `$bSET$b modifies your account settings`,
// these are broken out as separate strings so they can be translated separately
helpStrings: []string{
`Syntax $bSET <setting> <value>$b
Set modifies your account settings. The following settings ara available:
Set modifies your account settings. The following settings are available:`,
$bENFORCE$b
`$bENFORCE$b
'enforce' lets you specify a custom enforcement mechanism for your registered
nicknames. Your options are:
1. 'none' [no enforcement, overriding the server default]
2. 'timeout' [anyone using the nick must authenticate before a deadline,
or else they will be renamed]
3. 'strict' [you must already be authenticated to use the nick]
4. 'default' [use the server default]
4. 'default' [use the server default]`,
$bBOUNCER$b
`$bBOUNCER$b
If 'bouncer' is enabled and you are already logged in and using a nick, a
second client of yours that authenticates with SASL and requests the same nick
is allowed to attach to the nick as well (this is comparable to the behavior
of IRC "bouncers" like ZNC). Your options are 'on' (allow this behavior),
'off' (disallow it), and 'default' (use the server default value).
'off' (disallow it), and 'default' (use the server default value).`,
$bAUTOREPLAY-LINES$b
`$bAUTOREPLAY-LINES$b
'autoreplay-lines' controls the number of lines of channel history that will
be replayed to you automatically when joining a channel. Your options are any
positive number, 0 to disable the feature, and 'default' to use the server
default.
default.`,
$bAUTOREPLAY-JOINS$b
`$bAUTOREPLAY-JOINS$b
'autoreplay-joins' controls whether autoreplayed channel history will include
lines for join and part. This provides more information about the context of
messages, but may be spammy. Your options are 'on' and 'off'.
`,
helpShort: `$bSET$b modifies your account settings`,
messages, but may be spammy. Your options are 'on' and 'off'.`,
},
authRequired: true,
enabled: servCmdRequiresAccreg,
minParams: 2,
},
"saset": {
handler: nsSetHandler,
help: `Syntax: $bSASET <account> <setting> <value>$b`,
help: `Syntax: $bSASET <account> <setting> <value>$b
SASET modifies the values of someone else's account settings. For more
information on the settings and their possible values, see HELP SET.`,
helpShort: `$bSASET$b modifies another user's account settings`,
enabled: servCmdRequiresAccreg,
minParams: 3,
@ -328,22 +334,6 @@ func displaySetting(settingName string, settings AccountSettings, client *Client
}
}
func stringToBool(str string) (result bool, err error) {
switch strings.ToLower(str) {
case "on":
result = true
case "off":
result = false
case "true":
result = true
case "false":
result = false
default:
err = errInvalidParams
}
return
}
func nsSetHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
var account string
if command == "saset" {
@ -395,7 +385,7 @@ func nsSetHandler(server *Server, client *Client, command string, params []strin
newValue = BouncerAllowedServerDefault
} else {
var enabled bool
enabled, err = stringToBool(params[1])
enabled, err = utils.StringToBool(params[1])
if enabled {
newValue = BouncerAllowedByUser
} else {
@ -411,7 +401,7 @@ func nsSetHandler(server *Server, client *Client, command string, params []strin
}
case "autoreplay-joins":
var newValue bool
newValue, err = stringToBool(params[1])
newValue, err = utils.StringToBool(params[1])
if err == nil {
munger = func(in AccountSettings) (out AccountSettings, err error) {
out = in
@ -787,7 +777,7 @@ func nsPasswdHandler(server *Server, client *Client, command string, params []st
}
}
default:
errorMessage = "Invalid parameters"
errorMessage = `Invalid parameters`
}
if errorMessage != "" {

View File

@ -30,6 +30,7 @@ type serviceCommand struct {
capabs []string // oper capabs the given user has to have to access this command
handler func(server *Server, client *Client, command string, params []string, rb *ResponseBuffer)
help string
helpStrings []string
helpShort string
authRequired bool
hidden bool
@ -228,11 +229,21 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
if commandInfo == nil {
sendNotice(client.t(fmt.Sprintf("Unknown command. To see available commands, run /%s HELP", service.ShortName)))
} else {
for _, line := range strings.Split(ircfmt.Unescape(client.t(commandInfo.help)), "\n") {
helpStrings := commandInfo.helpStrings
if helpStrings == nil {
hsArray := [1]string{commandInfo.help}
helpStrings = hsArray[:]
}
for i, helpString := range helpStrings {
if 0 < i {
sendNotice("")
}
for _, line := range strings.Split(ircfmt.Unescape(client.t(helpString)), "\n") {
sendNotice(line)
}
}
}
}
sendNotice(ircfmt.Unescape(fmt.Sprintf(client.t("*** $bEnd of %s HELP$b ***"), service.Name)))
}
@ -261,9 +272,11 @@ func initializeServices() {
// force devs to write a help entry for every command
for commandName, commandInfo := range service.Commands {
if commandInfo.aliasOf == "" && !commandInfo.hidden && (commandInfo.help == "" || commandInfo.helpShort == "") {
if commandInfo.aliasOf == "" && !commandInfo.hidden {
if (commandInfo.help == "" && commandInfo.helpStrings == nil) || commandInfo.helpShort == "" {
log.Fatal(fmt.Sprintf("help entry missing for %s command %s", serviceName, commandName))
}
}
}
}
}

View File

@ -3,6 +3,15 @@
package utils
import (
"errors"
"strings"
)
var (
ErrInvalidParams = errors.New("Invalid parameters")
)
// ArgsToStrings takes the arguments and splits them into a series of strings,
// each argument separated by delim and each string bounded by maxLength.
func ArgsToStrings(maxLength int, arguments []string, delim string) []string {
@ -33,3 +42,15 @@ func ArgsToStrings(maxLength int, arguments []string, delim string) []string {
return messages
}
func StringToBool(str string) (result bool, err error) {
switch strings.ToLower(str) {
case "on", "true", "t", "yes", "y":
result = true
case "off", "false", "f", "no", "n":
result = false
default:
err = ErrInvalidParams
}
return
}