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"
"sort"
"strings"
"time"
@ -126,6 +127,16 @@ set using PURGE.`,
capabs: []string{"chanreg"},
minParams: 1,
},
"list": {
handler: csListHandler,
help: `Syntax: $bLIST [regex]$b
LIST returns the list of registered channels, which match the given regex.
If no regex is provided, all registered channels are returned.`,
helpShort: `$bLIST$b searches the list of registered channels.`,
capabs: []string{"chanreg"},
minParams: 0,
},
"info": {
handler: csInfoHandler,
help: `Syntax: $INFO #channel$b
@ -559,6 +570,34 @@ func csUnpurgeHandler(server *Server, client *Client, command string, params []s
}
}
func csListHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
if !client.HasRoleCapabs("chanreg") {
csNotice(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 {
csNotice(rb, client.t("Invalid regex"))
return
}
}
csNotice(rb, ircfmt.Unescape(client.t("*** $bChanServ LIST$b ***")))
channels := server.channelRegistry.AllChannels()
for _, channel := range channels {
if searchRegex == nil || searchRegex.MatchString(channel) {
csNotice(rb, fmt.Sprintf(" %s", channel))
}
}
csNotice(rb, ircfmt.Unescape(client.t("*** $bEnd of ChanServ LIST$b ***")))
}
func csInfoHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
chname, err := CasefoldChannel(params[0])
if err != nil {