mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-14 07:59:31 +01:00
commit
0db4b42ffe
@ -1015,16 +1015,17 @@ func extjwtHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HELP [<query>]
|
// HELP [<query>]
|
||||||
|
// HELPOP [<query>]
|
||||||
func helpHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
|
func helpHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
|
||||||
argument := strings.ToLower(strings.TrimSpace(strings.Join(msg.Params, " ")))
|
if len(msg.Params) == 0 {
|
||||||
|
|
||||||
if len(argument) < 1 {
|
|
||||||
client.sendHelp("HELPOP", client.t(`HELPOP <argument>
|
client.sendHelp("HELPOP", client.t(`HELPOP <argument>
|
||||||
|
|
||||||
Get an explanation of <argument>, or "index" for a list of help topics.`), rb)
|
Get an explanation of <argument>, or "index" for a list of help topics.`), rb)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
argument := strings.ToLower(strings.TrimSpace(msg.Params[0]))
|
||||||
|
|
||||||
// handle index
|
// handle index
|
||||||
if argument == "index" {
|
if argument == "index" {
|
||||||
client.sendHelp("HELP", server.helpIndexManager.GetIndex(client.Languages(), client.HasMode(modes.Operator)), rb)
|
client.sendHelp("HELP", server.helpIndexManager.GetIndex(client.Languages(), client.HasMode(modes.Operator)), rb)
|
||||||
@ -1035,14 +1036,12 @@ Get an explanation of <argument>, or "index" for a list of help topics.`), rb)
|
|||||||
|
|
||||||
if exists && (!helpHandler.oper || (helpHandler.oper && client.HasMode(modes.Operator))) {
|
if exists && (!helpHandler.oper || (helpHandler.oper && client.HasMode(modes.Operator))) {
|
||||||
if helpHandler.textGenerator != nil {
|
if helpHandler.textGenerator != nil {
|
||||||
client.sendHelp(strings.ToUpper(argument), helpHandler.textGenerator(client), rb)
|
client.sendHelp(argument, helpHandler.textGenerator(client), rb)
|
||||||
} else {
|
} else {
|
||||||
client.sendHelp(strings.ToUpper(argument), client.t(helpHandler.text), rb)
|
client.sendHelp(argument, client.t(helpHandler.text), rb)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
args := msg.Params
|
rb.Add(nil, server.name, ERR_HELPNOTFOUND, client.Nick(), strings.ToUpper(utils.SafeErrorParam(argument)), client.t("Help not found"))
|
||||||
args = append(args, client.t("Help not found"))
|
|
||||||
rb.Add(nil, server.name, ERR_HELPNOTFOUND, args...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -1865,7 +1864,7 @@ func monitorListHandler(server *Server, client *Client, msg ircmsg.IrcMessage, r
|
|||||||
nickList = append(nickList, replynick)
|
nickList = append(nickList, replynick)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, line := range utils.ArgsToStrings(maxLastArgLength, nickList, ",") {
|
for _, line := range utils.BuildTokenLines(maxLastArgLength, nickList, ",") {
|
||||||
rb.Add(nil, server.name, RPL_MONLIST, nick, line)
|
rb.Add(nil, server.name, RPL_MONLIST, nick, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1891,12 +1890,12 @@ func monitorStatusHandler(server *Server, client *Client, msg ircmsg.IrcMessage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(online) > 0 {
|
if len(online) > 0 {
|
||||||
for _, line := range utils.ArgsToStrings(maxLastArgLength, online, ",") {
|
for _, line := range utils.BuildTokenLines(maxLastArgLength, online, ",") {
|
||||||
rb.Add(nil, server.name, RPL_MONONLINE, client.Nick(), line)
|
rb.Add(nil, server.name, RPL_MONONLINE, client.Nick(), line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(offline) > 0 {
|
if len(offline) > 0 {
|
||||||
for _, line := range utils.ArgsToStrings(maxLastArgLength, offline, ",") {
|
for _, line := range utils.BuildTokenLines(maxLastArgLength, offline, ",") {
|
||||||
rb.Add(nil, server.name, RPL_MONOFFLINE, client.Nick(), line)
|
rb.Add(nil, server.name, RPL_MONOFFLINE, client.Nick(), line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
irc/help.go
15
irc/help.go
@ -752,22 +752,19 @@ func (hm *HelpIndexManager) GenerateIndices(lm *languages.Manager) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sendHelp sends the client help of the given string.
|
// sendHelp sends the client help of the given string.
|
||||||
func (client *Client) sendHelp(name string, text string, rb *ResponseBuffer) {
|
func (client *Client) sendHelp(helpEntry string, text string, rb *ResponseBuffer) {
|
||||||
splitName := strings.Split(name, " ")
|
helpEntry = strings.ToUpper(helpEntry)
|
||||||
|
nick := client.Nick()
|
||||||
textLines := strings.Split(text, "\n")
|
textLines := strings.Split(text, "\n")
|
||||||
|
|
||||||
for i, line := range textLines {
|
for i, line := range textLines {
|
||||||
args := splitName
|
|
||||||
args = append(args, line)
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
rb.Add(nil, client.server.name, RPL_HELPSTART, args...)
|
rb.Add(nil, client.server.name, RPL_HELPSTART, nick, helpEntry, line)
|
||||||
} else {
|
} else {
|
||||||
rb.Add(nil, client.server.name, RPL_HELPTXT, args...)
|
rb.Add(nil, client.server.name, RPL_HELPTXT, nick, helpEntry, line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
args := splitName
|
rb.Add(nil, client.server.name, RPL_ENDOFHELP, nick, helpEntry, client.t("End of /HELPOP"))
|
||||||
args = append(args, client.t("End of /HELPOP"))
|
|
||||||
rb.Add(nil, client.server.name, RPL_ENDOFHELP, args...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHelpIndex returns the help index for the given language.
|
// GetHelpIndex returns the help index for the given language.
|
||||||
|
@ -18,37 +18,6 @@ var (
|
|||||||
ErrInvalidParams = errors.New("Invalid parameters")
|
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 {
|
|
||||||
var messages []string
|
|
||||||
|
|
||||||
var buffer string
|
|
||||||
for {
|
|
||||||
if len(arguments) < 1 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(buffer) > 0 && maxLength < len(buffer)+len(delim)+len(arguments[0]) {
|
|
||||||
messages = append(messages, buffer)
|
|
||||||
buffer = ""
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(buffer) > 0 {
|
|
||||||
buffer += delim
|
|
||||||
}
|
|
||||||
buffer += arguments[0]
|
|
||||||
arguments = arguments[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(buffer) > 0 {
|
|
||||||
messages = append(messages, buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
return messages
|
|
||||||
}
|
|
||||||
|
|
||||||
func StringToBool(str string) (result bool, err error) {
|
func StringToBool(str string) (result bool, err error) {
|
||||||
switch strings.ToLower(str) {
|
switch strings.ToLower(str) {
|
||||||
case "on", "true", "t", "yes", "y", "enabled":
|
case "on", "true", "t", "yes", "y", "enabled":
|
||||||
|
@ -5,14 +5,6 @@ package utils
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestArgsToStrings(t *testing.T) {
|
|
||||||
val := ArgsToStrings(512, []string{"a", "b", "c"}, ",")
|
|
||||||
assertEqual(val, []string{"a,b,c"}, t)
|
|
||||||
|
|
||||||
val = ArgsToStrings(10, []string{"abcd", "efgh", "ijkl"}, ",")
|
|
||||||
assertEqual(val, []string{"abcd,efgh", "ijkl"}, t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStringToBool(t *testing.T) {
|
func TestStringToBool(t *testing.T) {
|
||||||
val, err := StringToBool("on")
|
val, err := StringToBool("on")
|
||||||
assertEqual(val, true, t)
|
assertEqual(val, true, t)
|
||||||
|
@ -132,3 +132,14 @@ func (t *TokenLineBuilder) Lines() (result []string) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildTokenLines is a convenience to apply TokenLineBuilder to a predetermined
|
||||||
|
// slice of tokens.
|
||||||
|
func BuildTokenLines(lineLen int, tokens []string, delim string) []string {
|
||||||
|
var tl TokenLineBuilder
|
||||||
|
tl.Initialize(lineLen, delim)
|
||||||
|
for _, arg := range tokens {
|
||||||
|
tl.Add(arg)
|
||||||
|
}
|
||||||
|
return tl.Lines()
|
||||||
|
}
|
||||||
|
@ -35,3 +35,11 @@ func TestTokenLineBuilder(t *testing.T) {
|
|||||||
t.Errorf("text incorrectly split into lines: %s instead of %s", joined, monteCristo)
|
t.Errorf("text incorrectly split into lines: %s instead of %s", joined, monteCristo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildTokenLines(t *testing.T) {
|
||||||
|
val := BuildTokenLines(512, []string{"a", "b", "c"}, ",")
|
||||||
|
assertEqual(val, []string{"a,b,c"}, t)
|
||||||
|
|
||||||
|
val = BuildTokenLines(10, []string{"abcd", "efgh", "ijkl"}, ",")
|
||||||
|
assertEqual(val, []string{"abcd,efgh", "ijkl"}, t)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user