diff --git a/cmd/bot/main.go b/cmd/bot/main.go index 9010110..8da32a7 100644 --- a/cmd/bot/main.go +++ b/cmd/bot/main.go @@ -118,6 +118,10 @@ func main() { log.Fatalf("Failed to subscribe: %v", err) } + if err := client.RegisterSlashCommand("standup"); err != nil { + log.Printf("Warning: could not register /standup command (use !standup instead): %v", err) + } + log.Println("Bot is running. Press Ctrl+C to stop.") sig := make(chan os.Signal, 1) diff --git a/internal/commands/help.go b/internal/commands/help.go index 7a4f954..99b5c38 100644 --- a/internal/commands/help.go +++ b/internal/commands/help.go @@ -3,7 +3,7 @@ package commands import "fmt" func handleHelp(ctx *Context) error { - base := "Available commands:\n" + base := "Available commands (prefix with `/standup` or `!standup`):\n" cmds := "" if ctx.Username == ctx.Config.MainAdmin { @@ -40,7 +40,7 @@ func sendHelpForCommand(ctx *Context, cmd string) error { msg, ok := help[cmd] if !ok { - msg = fmt.Sprintf("No help available for `/standup %s`.", cmd) + msg = fmt.Sprintf("No help available for `%s %s`.", "command", cmd) } return send(ctx.Messenger, ctx.RoomID, msg) } diff --git a/internal/commands/registry.go b/internal/commands/registry.go index 0f59c5b..4b266eb 100644 --- a/internal/commands/registry.go +++ b/internal/commands/registry.go @@ -69,11 +69,12 @@ func (r *Registry) Register(name string, handler Handler, perm Permission) { } func (r *Registry) Dispatch(ctx *Context) (bool, error) { - if !strings.HasPrefix(ctx.RawText, "/standup") { + text := strings.TrimSpace(ctx.RawText) + if !strings.HasPrefix(text, "/standup") && !strings.HasPrefix(text, "!standup") { return false, nil } - parts := strings.Fields(ctx.RawText) + parts := strings.Fields(text) if len(parts) < 2 { ctx.CmdName = "help" ctx.Args = nil diff --git a/internal/rocket/client.go b/internal/rocket/client.go index 13e772d..f14e3e8 100644 --- a/internal/rocket/client.go +++ b/internal/rocket/client.go @@ -1,6 +1,7 @@ package rocket import ( + "bytes" "encoding/json" "fmt" "log" @@ -213,6 +214,22 @@ func (c *Client) IsDMRoom(roomID string) (bool, error) { return resp.Room.Type == "d", nil } +func (c *Client) RegisterSlashCommand(command string) error { + if c.rest == nil { + return fmt.Errorf("not connected") + } + body := fmt.Sprintf(`{"command": "%s", "clientOnly": true}`, command) + var resp rest.Status + if err := c.rest.Post("commands.register", bytes.NewBufferString(body), &resp); err != nil { + return fmt.Errorf("register slash command: %w", err) + } + if !resp.Success { + return fmt.Errorf("slash command registration failed: %s", resp.Error) + } + log.Printf("Registered /%s as a client-only slash command", command) + return nil +} + func (c *Client) UserInfo(username string) (*models.User, error) { if c.rest == nil { return nil, fmt.Errorf("not connected")