From 235c5ff827fcd23565c7bf01fc0e8984947f7346 Mon Sep 17 00:00:00 2001 From: Enmanuel Date: Thu, 9 Apr 2026 20:25:41 +0000 Subject: [PATCH] feat: implementar comandos custom !echo y !dice para test-bot - !echo : repite el texto recibido (util para assertions exactas) - !dice / !dado: lanza un dado aleatorio (1-6) - Registro en cmd/launcher/main.go via testbot.Commands() Co-Authored-By: Claude Opus 4.6 (1M context) --- agents/test-bot/commands.go | 47 +++++++++++++++++++++++++++++++++++++ cmd/launcher/main.go | 9 ++++++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 agents/test-bot/commands.go diff --git a/agents/test-bot/commands.go b/agents/test-bot/commands.go new file mode 100644 index 0000000..51160aa --- /dev/null +++ b/agents/test-bot/commands.go @@ -0,0 +1,47 @@ +package test + +import ( + "context" + "fmt" + "math/rand" + "strings" + + "github.com/enmanuel/agents/pkg/command" + "github.com/enmanuel/agents/pkg/decision" +) + +// CommandEntry pairs a spec with its handler. +type CommandEntry struct { + Spec command.Spec + Handler func(ctx context.Context, msgCtx decision.MessageContext) string +} + +// Commands returns the custom command specs and handlers for test-bot. +func Commands() []CommandEntry { + return []CommandEntry{ + { + Spec: command.Spec{ + Name: "echo", + Description: "Repite el texto recibido", + Usage: "!echo ", + }, + Handler: func(_ context.Context, msgCtx decision.MessageContext) string { + if len(msgCtx.Args) == 0 { + return "Uso: !echo " + } + return strings.Join(msgCtx.Args, " ") + }, + }, + { + Spec: command.Spec{ + Name: "dice", + Aliases: []string{"dado"}, + Description: "Lanza un dado (1-6)", + Usage: "!dice", + }, + Handler: func(_ context.Context, _ decision.MessageContext) string { + return fmt.Sprintf("%d", rand.Intn(6)+1) + }, + }, + } +} diff --git a/cmd/launcher/main.go b/cmd/launcher/main.go index d7927dc..c2caf0d 100644 --- a/cmd/launcher/main.go +++ b/cmd/launcher/main.go @@ -33,7 +33,7 @@ import ( _ "github.com/enmanuel/agents/agents/assistant-bot" _ "github.com/enmanuel/agents/agents/asistente-2" _ "github.com/enmanuel/agents/agents/meteorologo" - _ "github.com/enmanuel/agents/agents/test-bot" + testbot "github.com/enmanuel/agents/agents/test-bot" ) func main() { @@ -181,6 +181,13 @@ func main() { agentCleanup() continue } + // Register agent-specific commands for robots + if cfg.Agent.ID == "test-bot" { + for _, cmd := range testbot.Commands() { + robot.RegisterCommand(cmd.Spec, cmd.Handler) + } + } + runner = robot agentLogger.Info("created robot", "id", cfg.Agent.ID) } else {