Add ChanServ and NickServ LIST commands.

These commands search the registered nicknames/channels for ones
matching the provided regex, or return the entire list.

Only operators with chanreg (for ChanServ) or accreg (for NickServ)
capabilities can use LIST.
This commit is contained in:
Alex Jaspersen 2020-05-04 00:51:39 +00:00
parent 11e1939c9b
commit 6019ed1e29
3 changed files with 90 additions and 0 deletions

View file

@ -5,6 +5,7 @@ package irc
import (
"fmt"
"regexp"
"strconv"
"strings"
"time"
@ -97,6 +98,17 @@ certfp (your client certificate) if a password is not given.`,
enabled: servCmdRequiresAuthEnabled,
minParams: 1,
},
"list": {
handler: nsListHandler,
help: `Syntax: $bLIST [regex]$b
LIST returns the list of registered nicknames, which match the given regex.
If no regex is provided, all registered nicknames are returned.`,
helpShort: `$bLIST$b searches the list of registered nicknames.`,
enabled: servCmdRequiresAuthEnabled,
capabs: []string{"accreg"},
minParams: 0,
},
"info": {
handler: nsInfoHandler,
help: `Syntax: $bINFO [username]$b
@ -681,6 +693,34 @@ func nsIdentifyHandler(server *Server, client *Client, command string, params []
}
}
func nsListHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
if !client.HasRoleCapabs("accreg") {
nsNotice(rb, client.t("Insufficient privileges"))
return
}
var searchRegex *regexp.Regexp
if len(params) > 0 {
var err error
searchRegex, err = regexp.Compile(params[0])
if err != nil {
nsNotice(rb, client.t("Invalid regex"))
return
}
}
nsNotice(rb, ircfmt.Unescape(client.t("*** $bNickServ LIST$b ***")))
nicks := server.accounts.AllNicks()
for _, nick := range nicks {
if searchRegex == nil || searchRegex.MatchString(nick) {
nsNotice(rb, fmt.Sprintf(" %s", nick))
}
}
nsNotice(rb, ircfmt.Unescape(client.t("*** $bEnd of NickServ LIST$b ***")))
}
func nsInfoHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
if !server.Config().Accounts.AuthenticationEnabled && !client.HasRoleCapabs("accreg") {
nsNotice(rb, client.t("This command has been disabled by the server administrators"))