Fix list with big numbers.
This commit is contained in:
parent
ef87f6b627
commit
88aca60408
22
client.go
22
client.go
|
@ -12,11 +12,14 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// MsgBuffer is the length of the message buffer
|
// MsgBuffer is the length of the message buffer
|
||||||
MsgBuffer int = 50
|
MsgBuffer int = 20
|
||||||
|
|
||||||
// MaxMsgLength is the maximum length of a message
|
// MaxMsgLength is the maximum length of a message
|
||||||
MaxMsgLength int = 1024
|
MaxMsgLength int = 1024
|
||||||
|
|
||||||
|
// MaxNamesList is the max number of items to return in a /names command
|
||||||
|
MaxNamesList int = 3
|
||||||
|
|
||||||
// HelpText is the text returned by /help
|
// HelpText is the text returned by /help
|
||||||
HelpText string = `Available commands:
|
HelpText string = `Available commands:
|
||||||
/about - About this chat.
|
/about - About this chat.
|
||||||
|
@ -277,15 +280,18 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
||||||
c.SysMsg("Missing $NAME from: /whois $NAME")
|
c.SysMsg("Missing $NAME from: /whois $NAME")
|
||||||
}
|
}
|
||||||
case "/names", "/list":
|
case "/names", "/list":
|
||||||
names := ""
|
coloredNames := []string{}
|
||||||
nameList := c.Server.List(nil)
|
for _, name := range c.Server.List(nil) {
|
||||||
for _, name := range nameList {
|
coloredNames = append(coloredNames, c.Server.Who(name).ColoredName())
|
||||||
names += c.Server.Who(name).ColoredName() + systemMessageFormat + ", "
|
|
||||||
}
|
}
|
||||||
if len(names) > 2 {
|
num := len(coloredNames)
|
||||||
names = names[:len(names)-2]
|
if len(coloredNames) > MaxNamesList {
|
||||||
|
others := fmt.Sprintf("and %d others.", len(coloredNames)-MaxNamesList)
|
||||||
|
coloredNames = coloredNames[:MaxNamesList]
|
||||||
|
coloredNames = append(coloredNames, others)
|
||||||
}
|
}
|
||||||
c.SysMsg("%d connected: %s", len(nameList), names)
|
|
||||||
|
c.SysMsg("%d connected: %s", num, strings.Join(coloredNames, systemMessageFormat+", "))
|
||||||
case "/ban":
|
case "/ban":
|
||||||
if !c.Server.IsOp(c) {
|
if !c.Server.IsOp(c) {
|
||||||
c.SysMsg("You're not an admin.")
|
c.SysMsg("You're not an admin.")
|
||||||
|
|
Loading…
Reference in New Issue