feat: permitir comandos de robots sin prefijo !

Cuando command_prefix es "" en el config, el parser trata el primer token
del mensaje como nombre de comando sin requerir el prefijo !. Si el token
empieza con !, se le quita igualmente para retrocompatibilidad.

Cambios:
- pkg/message/parse.go: modo sin prefijo en Parse() (puro, sin side effects)
- agents/robot.go: mensaje "comando desconocido" y !help adaptados al prefijo
- agents/handler.go: mensaje "comando desconocido" adaptado al prefijo
- internal/config/schema.go: documentar command_prefix: "" en FiltersCfg
- agents/_template_robot/config.yaml: ejemplo comentado de command_prefix: ""

El comportamiento con command_prefix: "!" no cambia (retrocompatible).
This commit is contained in:
2026-04-09 20:10:03 +00:00
parent 945710034c
commit 421ab5c773
5 changed files with 49 additions and 15 deletions
+26 -5
View File
@@ -38,12 +38,33 @@ func Parse(body, senderID, roomID string, powerLevel int, isDM bool, opts ParseO
}
}
// Parse command
if opts.CommandPrefix != "" && strings.HasPrefix(body, opts.CommandPrefix) {
parts := strings.Fields(strings.TrimPrefix(body, opts.CommandPrefix))
// Parse command.
// When CommandPrefix is non-empty (e.g. "!"), only messages starting with that
// prefix are treated as commands.
// When CommandPrefix is empty, every message is a potential command: the first
// token is the command name. If it starts with "!", the "!" is stripped for
// backward compatibility (so both "help" and "!help" work the same).
switch {
case opts.CommandPrefix != "":
// Standard mode: require prefix
if strings.HasPrefix(body, opts.CommandPrefix) {
parts := strings.Fields(strings.TrimPrefix(body, opts.CommandPrefix))
if len(parts) > 0 {
ctx.Command = strings.ToLower(parts[0])
ctx.Args = parts[1:]
}
}
case opts.CommandPrefix == "":
// No-prefix mode: treat first token as command
parts := strings.Fields(body)
if len(parts) > 0 {
ctx.Command = strings.ToLower(parts[0])
ctx.Args = parts[1:]
cmd := parts[0]
// Strip leading "!" for backward compatibility
cmd = strings.TrimPrefix(cmd, "!")
if cmd != "" {
ctx.Command = strings.ToLower(cmd)
ctx.Args = parts[1:]
}
}
}