Files
egutierrez 235c5ff827 feat: implementar comandos custom !echo y !dice para test-bot
- !echo <texto>: 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) <noreply@anthropic.com>
2026-04-09 20:25:41 +00:00

48 lines
1.1 KiB
Go

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 <texto>",
},
Handler: func(_ context.Context, msgCtx decision.MessageContext) string {
if len(msgCtx.Args) == 0 {
return "Uso: !echo <texto>"
}
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)
},
},
}
}