Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/bot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
5 changes: 3 additions & 2 deletions internal/commands/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions internal/rocket/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rocket

import (
"bytes"
"encoding/json"
"fmt"
"log"
Expand Down Expand Up @@ -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")
Expand Down
Loading