mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-29 07:29:31 +01:00
add support for service command aliases
This commit is contained in:
parent
3c12fb6254
commit
578ca2fdf6
@ -63,6 +63,9 @@ invoking the command without a code will display the necessary code.`,
|
|||||||
helpShort: `$bUNREGISTER$b deletes a channel registration.`,
|
helpShort: `$bUNREGISTER$b deletes a channel registration.`,
|
||||||
enabled: chanregEnabled,
|
enabled: chanregEnabled,
|
||||||
},
|
},
|
||||||
|
"drop": {
|
||||||
|
aliasOf: "unregister",
|
||||||
|
},
|
||||||
"amode": {
|
"amode": {
|
||||||
handler: csAmodeHandler,
|
handler: csAmodeHandler,
|
||||||
help: `Syntax: $bAMODE #channel [mode change] [account]$b
|
help: `Syntax: $bAMODE #channel [mode change] [account]$b
|
||||||
|
@ -145,22 +145,6 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// confirm help entries for ChanServ exist.
|
|
||||||
// this forces people to write help entries for every single CS command.
|
|
||||||
for commandName, commandInfo := range chanservCommands {
|
|
||||||
if commandInfo.help == "" || commandInfo.helpShort == "" {
|
|
||||||
return nil, fmt.Errorf("Help entry does not exist for ChanServ command %s", commandName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// confirm help entries for NickServ exist.
|
|
||||||
// this forces people to write help entries for every single NS command.
|
|
||||||
for commandName, commandInfo := range nickservCommands {
|
|
||||||
if commandInfo.help == "" || commandInfo.helpShort == "" {
|
|
||||||
return nil, fmt.Errorf("Help entry does not exist for NickServ command %s", commandName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to clean up when receiving these signals.
|
// Attempt to clean up when receiving these signals.
|
||||||
signal.Notify(server.signals, ServerExitSignals...)
|
signal.Notify(server.signals, ServerExitSignals...)
|
||||||
signal.Notify(server.rehashSignal, syscall.SIGHUP)
|
signal.Notify(server.rehashSignal, syscall.SIGHUP)
|
||||||
|
@ -5,6 +5,7 @@ package irc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ type ircService struct {
|
|||||||
|
|
||||||
// defines a command associated with a service, e.g., NICKSERV IDENTIFY
|
// defines a command associated with a service, e.g., NICKSERV IDENTIFY
|
||||||
type serviceCommand struct {
|
type serviceCommand struct {
|
||||||
|
aliasOf string // marks this command as an alias of another
|
||||||
capabs []string // oper capabs the given user has to have to access this command
|
capabs []string // oper capabs the given user has to have to access this command
|
||||||
handler func(server *Server, client *Client, command, params string, rb *ResponseBuffer)
|
handler func(server *Server, client *Client, command, params string, rb *ResponseBuffer)
|
||||||
help string
|
help string
|
||||||
@ -33,6 +35,24 @@ type serviceCommand struct {
|
|||||||
enabled func(*Server) bool // is this command enabled in the server config?
|
enabled func(*Server) bool // is this command enabled in the server config?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// looks up a command in the table of command definitions for a service, resolving aliases
|
||||||
|
func lookupServiceCommand(commands map[string]*serviceCommand, command string) *serviceCommand {
|
||||||
|
maxDepth := 1
|
||||||
|
depth := 0
|
||||||
|
for depth <= maxDepth {
|
||||||
|
result, ok := commands[command]
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
} else if result.aliasOf == "" {
|
||||||
|
return result
|
||||||
|
} else {
|
||||||
|
command = result.aliasOf
|
||||||
|
depth += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// all services, by lowercase name
|
// all services, by lowercase name
|
||||||
var OragonoServices = map[string]*ircService{
|
var OragonoServices = map[string]*ircService{
|
||||||
"nickserv": {
|
"nickserv": {
|
||||||
@ -93,7 +113,7 @@ func servicePrivmsgHandler(service *ircService, server *Server, client *Client,
|
|||||||
rb.Add(nil, service.Name, "NOTICE", nick, notice)
|
rb.Add(nil, service.Name, "NOTICE", nick, notice)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := service.Commands[commandName]
|
cmd := lookupServiceCommand(service.Commands, commandName)
|
||||||
if cmd == nil {
|
if cmd == nil {
|
||||||
sendNotice(fmt.Sprintf("%s /%s HELP", client.t("Unknown command. To see available commands, run"), service.ShortName))
|
sendNotice(fmt.Sprintf("%s /%s HELP", client.t("Unknown command. To see available commands, run"), service.ShortName))
|
||||||
return
|
return
|
||||||
@ -140,6 +160,9 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
|
|||||||
if 0 < len(commandInfo.capabs) && !client.HasRoleCapabs(commandInfo.capabs...) {
|
if 0 < len(commandInfo.capabs) && !client.HasRoleCapabs(commandInfo.capabs...) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if commandInfo.aliasOf != "" {
|
||||||
|
continue // don't show help lines for aliases
|
||||||
|
}
|
||||||
if commandInfo.enabled != nil && !commandInfo.enabled(server) {
|
if commandInfo.enabled != nil && !commandInfo.enabled(server) {
|
||||||
disabledCommands = true
|
disabledCommands = true
|
||||||
continue
|
continue
|
||||||
@ -164,7 +187,8 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
|
|||||||
sendNotice(line)
|
sendNotice(line)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
commandInfo := service.Commands[strings.ToLower(strings.TrimSpace(params))]
|
commandName := strings.ToLower(strings.TrimSpace(params))
|
||||||
|
commandInfo := lookupServiceCommand(service.Commands, commandName)
|
||||||
if commandInfo == nil {
|
if commandInfo == nil {
|
||||||
sendNotice(client.t(fmt.Sprintf("Unknown command. To see available commands, run /%s HELP", service.ShortName)))
|
sendNotice(client.t(fmt.Sprintf("Unknown command. To see available commands, run /%s HELP", service.ShortName)))
|
||||||
} else {
|
} else {
|
||||||
@ -196,5 +220,12 @@ func initializeServices() {
|
|||||||
Commands[ircCmd] = ircCmdDef
|
Commands[ircCmd] = ircCmdDef
|
||||||
oragonoServicesByCommandAlias[ircCmd] = service
|
oragonoServicesByCommandAlias[ircCmd] = service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// force devs to write a help entry for every command
|
||||||
|
for commandName, commandInfo := range service.Commands {
|
||||||
|
if commandInfo.aliasOf == "" && (commandInfo.help == "" || commandInfo.helpShort == "") {
|
||||||
|
log.Fatal(fmt.Sprintf("help entry missing for %s command %s", serviceName, commandName))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user