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

View File

@ -12,6 +12,7 @@ import (
"github.com/goshuirc/irc-go/ircfmt" "github.com/goshuirc/irc-go/ircfmt"
"github.com/oragono/oragono/irc/modes" "github.com/oragono/oragono/irc/modes"
"github.com/oragono/oragono/irc/utils"
) )
// "enabled" callbacks for specific nickserv commands // "enabled" callbacks for specific nickserv commands
@ -209,46 +210,51 @@ information on the settings and their possible values, see HELP SET.`,
capabs: []string{"accreg"}, capabs: []string{"accreg"},
}, },
"set": { "set": {
handler: nsSetHandler, 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 'enforce' lets you specify a custom enforcement mechanism for your registered
nicknames. Your options are: nicknames. Your options are:
1. 'none' [no enforcement, overriding the server default] 1. 'none' [no enforcement, overriding the server default]
2. 'timeout' [anyone using the nick must authenticate before a deadline, 2. 'timeout' [anyone using the nick must authenticate before a deadline,
or else they will be renamed] or else they will be renamed]
3. 'strict' [you must already be authenticated to use the nick] 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 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 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 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), 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 '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 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 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 'autoreplay-joins' controls whether autoreplayed channel history will include
lines for join and part. This provides more information about the context of lines for join and part. This provides more information about the context of
messages, but may be spammy. Your options are 'on' and 'off'. messages, but may be spammy. Your options are 'on' and 'off'.`,
`, },
helpShort: `$bSET$b modifies your account settings`,
authRequired: true, authRequired: true,
enabled: servCmdRequiresAccreg, enabled: servCmdRequiresAccreg,
minParams: 2, minParams: 2,
}, },
"saset": { "saset": {
handler: nsSetHandler, 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`, helpShort: `$bSASET$b modifies another user's account settings`,
enabled: servCmdRequiresAccreg, enabled: servCmdRequiresAccreg,
minParams: 3, 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) { func nsSetHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
var account string var account string
if command == "saset" { if command == "saset" {
@ -395,7 +385,7 @@ func nsSetHandler(server *Server, client *Client, command string, params []strin
newValue = BouncerAllowedServerDefault newValue = BouncerAllowedServerDefault
} else { } else {
var enabled bool var enabled bool
enabled, err = stringToBool(params[1]) enabled, err = utils.StringToBool(params[1])
if enabled { if enabled {
newValue = BouncerAllowedByUser newValue = BouncerAllowedByUser
} else { } else {
@ -411,7 +401,7 @@ func nsSetHandler(server *Server, client *Client, command string, params []strin
} }
case "autoreplay-joins": case "autoreplay-joins":
var newValue bool var newValue bool
newValue, err = stringToBool(params[1]) newValue, err = utils.StringToBool(params[1])
if err == nil { if err == nil {
munger = func(in AccountSettings) (out AccountSettings, err error) { munger = func(in AccountSettings) (out AccountSettings, err error) {
out = in out = in
@ -787,7 +777,7 @@ func nsPasswdHandler(server *Server, client *Client, command string, params []st
} }
} }
default: default:
errorMessage = "Invalid parameters" errorMessage = `Invalid parameters`
} }
if errorMessage != "" { 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 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) handler func(server *Server, client *Client, command string, params []string, rb *ResponseBuffer)
help string help string
helpStrings []string
helpShort string helpShort string
authRequired bool authRequired bool
hidden bool hidden bool
@ -228,8 +229,18 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
if commandInfo == nil { if commandInfo == nil {
sendNotice(client.t(fmt.Sprintf("Unknown command. To see available commands, run /%s HELP", service.ShortName))) sendNotice(client.t(fmt.Sprintf("Unknown command. To see available commands, run /%s HELP", service.ShortName)))
} else { } else {
for _, line := range strings.Split(ircfmt.Unescape(client.t(commandInfo.help)), "\n") { helpStrings := commandInfo.helpStrings
sendNotice(line) 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)
}
} }
} }
} }
@ -261,8 +272,10 @@ func initializeServices() {
// force devs to write a help entry for every command // force devs to write a help entry for every command
for commandName, commandInfo := range service.Commands { for commandName, commandInfo := range service.Commands {
if commandInfo.aliasOf == "" && !commandInfo.hidden && (commandInfo.help == "" || commandInfo.helpShort == "") { if commandInfo.aliasOf == "" && !commandInfo.hidden {
log.Fatal(fmt.Sprintf("help entry missing for %s command %s", serviceName, commandName)) 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 package utils
import (
"errors"
"strings"
)
var (
ErrInvalidParams = errors.New("Invalid parameters")
)
// ArgsToStrings takes the arguments and splits them into a series of strings, // ArgsToStrings takes the arguments and splits them into a series of strings,
// each argument separated by delim and each string bounded by maxLength. // each argument separated by delim and each string bounded by maxLength.
func ArgsToStrings(maxLength int, arguments []string, delim string) []string { func ArgsToStrings(maxLength int, arguments []string, delim string) []string {
@ -33,3 +42,15 @@ func ArgsToStrings(maxLength int, arguments []string, delim string) []string {
return messages 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
}