mirror of
https://github.com/ergochat/ergo.git
synced 2025-05-30 03:17:42 +02:00
parent
f5bb5afdd6
commit
7256d83ff0
@ -375,6 +375,11 @@ server:
|
|||||||
# if you don't want to publicize how popular the server is
|
# if you don't want to publicize how popular the server is
|
||||||
suppress-lusers: false
|
suppress-lusers: false
|
||||||
|
|
||||||
|
# optionally map command alias names to existing ergo commands. most deployments
|
||||||
|
# should ignore this.
|
||||||
|
#command-aliases:
|
||||||
|
#"UMGEBUNG": "AMBIANCE"
|
||||||
|
|
||||||
# account options
|
# account options
|
||||||
accounts:
|
accounts:
|
||||||
# is account authentication enabled, i.e., can users log into existing accounts?
|
# is account authentication enabled, i.e., can users log into existing accounts?
|
||||||
|
@ -750,13 +750,8 @@ func (client *Client) run(session *Session) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd, exists := Commands[msg.Command]
|
var cmd Command
|
||||||
if !exists {
|
msg.Command, cmd = client.server.resolveCommand(msg.Command, invalidUtf8)
|
||||||
cmd = unknownCommand
|
|
||||||
} else if invalidUtf8 {
|
|
||||||
cmd = invalidUtf8Command
|
|
||||||
}
|
|
||||||
|
|
||||||
isExiting := cmd.Run(client.server, client, session, msg)
|
isExiting := cmd.Run(client.server, client, session, msg)
|
||||||
if isExiting {
|
if isExiting {
|
||||||
break
|
break
|
||||||
|
@ -18,6 +18,24 @@ type Command struct {
|
|||||||
capabs []string
|
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.
|
// Run runs this command with the given client/message.
|
||||||
func (cmd *Command) Run(server *Server, client *Client, session *Session, msg ircmsg.Message) (exiting bool) {
|
func (cmd *Command) Run(server *Server, client *Client, session *Session, msg ircmsg.Message) (exiting bool) {
|
||||||
rb := NewResponseBuffer(session)
|
rb := NewResponseBuffer(session)
|
||||||
|
@ -609,6 +609,7 @@ type Config struct {
|
|||||||
OverrideServicesHostname string `yaml:"override-services-hostname"`
|
OverrideServicesHostname string `yaml:"override-services-hostname"`
|
||||||
MaxLineLen int `yaml:"max-line-len"`
|
MaxLineLen int `yaml:"max-line-len"`
|
||||||
SuppressLusers bool `yaml:"suppress-lusers"`
|
SuppressLusers bool `yaml:"suppress-lusers"`
|
||||||
|
CommandAliases map[string]string `yaml:"command-aliases"`
|
||||||
}
|
}
|
||||||
|
|
||||||
API struct {
|
API struct {
|
||||||
@ -1660,6 +1661,11 @@ func LoadConfig(filename string) (config *Config, err error) {
|
|||||||
return nil, err
|
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:
|
// now that all postprocessing is complete, regenerate ISUPPORT:
|
||||||
err = config.generateISupport()
|
err = config.generateISupport()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1875,3 +1881,22 @@ func (config *Config) loadMOTD() error {
|
|||||||
}
|
}
|
||||||
return nil
|
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
|
# if you don't want to publicize how popular the server is
|
||||||
suppress-lusers: false
|
suppress-lusers: false
|
||||||
|
|
||||||
|
# optionally map command alias names to existing ergo commands. most deployments
|
||||||
|
# should ignore this.
|
||||||
|
#command-aliases:
|
||||||
|
#"UMGEBUNG": "AMBIANCE"
|
||||||
|
|
||||||
# account options
|
# account options
|
||||||
accounts:
|
accounts:
|
||||||
# is account authentication enabled, i.e., can users log into existing accounts?
|
# is account authentication enabled, i.e., can users log into existing accounts?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user