mirror of
https://github.com/ergochat/ergo.git
synced 2025-04-03 22:38:16 +02:00
parent
f5bb5afdd6
commit
7256d83ff0
@ -375,6 +375,11 @@ server:
|
||||
# if you don't want to publicize how popular the server is
|
||||
suppress-lusers: false
|
||||
|
||||
# optionally map command alias names to existing ergo commands. most deployments
|
||||
# should ignore this.
|
||||
#command-aliases:
|
||||
#"UMGEBUNG": "AMBIANCE"
|
||||
|
||||
# account options
|
||||
accounts:
|
||||
# is account authentication enabled, i.e., can users log into existing accounts?
|
||||
|
@ -750,13 +750,8 @@ func (client *Client) run(session *Session) {
|
||||
break
|
||||
}
|
||||
|
||||
cmd, exists := Commands[msg.Command]
|
||||
if !exists {
|
||||
cmd = unknownCommand
|
||||
} else if invalidUtf8 {
|
||||
cmd = invalidUtf8Command
|
||||
}
|
||||
|
||||
var cmd Command
|
||||
msg.Command, cmd = client.server.resolveCommand(msg.Command, invalidUtf8)
|
||||
isExiting := cmd.Run(client.server, client, session, msg)
|
||||
if isExiting {
|
||||
break
|
||||
|
@ -18,6 +18,24 @@ type Command struct {
|
||||
capabs []string
|
||||
}
|
||||
|
||||
// resolveCommand returns the command to execute in response to a user input line.
|
||||
// some invalid commands (unknown command verb, invalid UTF8) get a fake handler
|
||||
// to ensure that labeled-response still works as expected.
|
||||
func (server *Server) resolveCommand(command string, invalidUTF8 bool) (canonicalName string, result Command) {
|
||||
if invalidUTF8 {
|
||||
return command, invalidUtf8Command
|
||||
}
|
||||
if cmd, ok := Commands[command]; ok {
|
||||
return command, cmd
|
||||
}
|
||||
if target, ok := server.Config().Server.CommandAliases[command]; ok {
|
||||
if cmd, ok := Commands[target]; ok {
|
||||
return target, cmd
|
||||
}
|
||||
}
|
||||
return command, unknownCommand
|
||||
}
|
||||
|
||||
// Run runs this command with the given client/message.
|
||||
func (cmd *Command) Run(server *Server, client *Client, session *Session, msg ircmsg.Message) (exiting bool) {
|
||||
rb := NewResponseBuffer(session)
|
||||
|
@ -609,6 +609,7 @@ type Config struct {
|
||||
OverrideServicesHostname string `yaml:"override-services-hostname"`
|
||||
MaxLineLen int `yaml:"max-line-len"`
|
||||
SuppressLusers bool `yaml:"suppress-lusers"`
|
||||
CommandAliases map[string]string `yaml:"command-aliases"`
|
||||
}
|
||||
|
||||
API struct {
|
||||
@ -1660,6 +1661,11 @@ func LoadConfig(filename string) (config *Config, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config.Server.CommandAliases, err = normalizeCommandAliases(config.Server.CommandAliases)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// now that all postprocessing is complete, regenerate ISUPPORT:
|
||||
err = config.generateISupport()
|
||||
if err != nil {
|
||||
@ -1875,3 +1881,22 @@ func (config *Config) loadMOTD() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func normalizeCommandAliases(aliases map[string]string) (normalizedAliases map[string]string, err error) {
|
||||
if len(aliases) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
normalizedAliases = make(map[string]string, len(aliases))
|
||||
for alias, command := range aliases {
|
||||
alias = strings.ToUpper(alias)
|
||||
command = strings.ToUpper(command)
|
||||
if _, found := Commands[alias]; found {
|
||||
return nil, fmt.Errorf("Command alias `%s` collides with a real Ergo command", alias)
|
||||
}
|
||||
if _, found := Commands[command]; !found {
|
||||
return nil, fmt.Errorf("Command alias `%s` mapped to non-existent Ergo command `%s`", alias, command)
|
||||
}
|
||||
normalizedAliases[alias] = command
|
||||
}
|
||||
return normalizedAliases, nil
|
||||
}
|
||||
|
@ -347,6 +347,11 @@ server:
|
||||
# if you don't want to publicize how popular the server is
|
||||
suppress-lusers: false
|
||||
|
||||
# optionally map command alias names to existing ergo commands. most deployments
|
||||
# should ignore this.
|
||||
#command-aliases:
|
||||
#"UMGEBUNG": "AMBIANCE"
|
||||
|
||||
# account options
|
||||
accounts:
|
||||
# is account authentication enabled, i.e., can users log into existing accounts?
|
||||
|
Loading…
x
Reference in New Issue
Block a user