mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
Merge pull request #977 from ajaspers/list-regd-users+chans
Add ChanServ and NickServ LIST commands.
This commit is contained in:
commit
2ef87598c4
@ -7,6 +7,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -1047,6 +1048,41 @@ func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName s
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllNicks returns the uncasefolded nicknames for all accounts, including additional (grouped) nicks.
|
||||||
|
func (am *AccountManager) AllNicks() (result []string) {
|
||||||
|
accountNamePrefix := fmt.Sprintf(keyAccountName, "")
|
||||||
|
accountAdditionalNicksPrefix := fmt.Sprintf(keyAccountAdditionalNicks, "")
|
||||||
|
|
||||||
|
am.server.store.View(func(tx *buntdb.Tx) error {
|
||||||
|
// Account names
|
||||||
|
err := tx.AscendGreaterOrEqual("", accountNamePrefix, func(key, value string) bool {
|
||||||
|
if !strings.HasPrefix(key, accountNamePrefix) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
result = append(result, value)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Additional nicks
|
||||||
|
return tx.AscendGreaterOrEqual("", accountAdditionalNicksPrefix, func(key, value string) bool {
|
||||||
|
if !strings.HasPrefix(key, accountAdditionalNicksPrefix) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
additionalNicks := unmarshalReservedNicks(value)
|
||||||
|
for _, additionalNick := range additionalNicks {
|
||||||
|
result = append(result, additionalNick)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
sort.Strings(result)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (am *AccountManager) LoadAccount(accountName string) (result ClientAccount, err error) {
|
func (am *AccountManager) LoadAccount(accountName string) (result ClientAccount, err error) {
|
||||||
casefoldedAccount, err := CasefoldName(accountName)
|
casefoldedAccount, err := CasefoldName(accountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -5,6 +5,7 @@ package irc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -126,6 +127,16 @@ set using PURGE.`,
|
|||||||
capabs: []string{"chanreg"},
|
capabs: []string{"chanreg"},
|
||||||
minParams: 1,
|
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": {
|
"info": {
|
||||||
handler: csInfoHandler,
|
handler: csInfoHandler,
|
||||||
help: `Syntax: $INFO #channel$b
|
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) {
|
func csInfoHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
||||||
chname, err := CasefoldChannel(params[0])
|
chname, err := CasefoldChannel(params[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -5,6 +5,7 @@ package irc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -97,6 +98,17 @@ certfp (your client certificate) if a password is not given.`,
|
|||||||
enabled: servCmdRequiresAuthEnabled,
|
enabled: servCmdRequiresAuthEnabled,
|
||||||
minParams: 1,
|
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": {
|
"info": {
|
||||||
handler: nsInfoHandler,
|
handler: nsInfoHandler,
|
||||||
help: `Syntax: $bINFO [username]$b
|
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) {
|
func nsInfoHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
||||||
if !server.Config().Accounts.AuthenticationEnabled && !client.HasRoleCapabs("accreg") {
|
if !server.Config().Accounts.AuthenticationEnabled && !client.HasRoleCapabs("accreg") {
|
||||||
nsNotice(rb, client.t("This command has been disabled by the server administrators"))
|
nsNotice(rb, client.t("This command has been disabled by the server administrators"))
|
||||||
|
Loading…
Reference in New Issue
Block a user