mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
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:
parent
11e1939c9b
commit
6019ed1e29
@ -1047,6 +1047,17 @@ func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName s
|
||||
return err
|
||||
}
|
||||
|
||||
func (am *AccountManager) AllNicks() []string {
|
||||
am.RLock()
|
||||
defer am.RUnlock()
|
||||
|
||||
nicks := make([]string, 0, len(am.nickToAccount))
|
||||
for nick := range am.nickToAccount {
|
||||
nicks = append(nicks, nick)
|
||||
}
|
||||
return nicks
|
||||
}
|
||||
|
||||
func (am *AccountManager) LoadAccount(accountName string) (result ClientAccount, err error) {
|
||||
casefoldedAccount, err := CasefoldName(accountName)
|
||||
if err != nil {
|
||||
|
@ -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 {
|
||||
|
@ -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"))
|
||||
|
Loading…
Reference in New Issue
Block a user