From d5f2d952735202042b9f076eaf32dc98c8f2672c Mon Sep 17 00:00:00 2001 From: Joshua Blum Date: Tue, 28 Jul 2026 12:58:39 -0400 Subject: [PATCH 1/2] Fix command advertisements --- advertisement.go | 13 +++++++++---- bot_test.go | 11 +++++------ keybot/keybot.go | 19 +++++++++---------- keybot/winbot.go | 15 +++++++-------- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/advertisement.go b/advertisement.go index 75b5f45..6fb0023 100644 --- a/advertisement.go +++ b/advertisement.go @@ -18,18 +18,16 @@ func (b *Bot) AddAdvertisements(commands ...chat1.UserBotCommandInput) { func (b *Bot) AdvertisedCommands() []chat1.UserBotCommandInput { commands := []chat1.UserBotCommandInput{{ - Name: "help", + Name: b.advertisedCommandName("help"), Description: "Show available commands", - Usage: fmt.Sprintf("!%s help", b.name), ExtendedDescription: b.helpExtendedDescription(), }} for _, trigger := range b.triggers() { command := b.commands[trigger] commands = append(commands, chat1.UserBotCommandInput{ - Name: trigger, + Name: b.advertisedCommandName(trigger), Description: command.Description(), - Usage: fmt.Sprintf("!%s %s", b.name, trigger), }) } @@ -37,11 +35,18 @@ func (b *Bot) AdvertisedCommands() []chat1.UserBotCommandInput { slices.SortFunc(extras, func(a, b chat1.UserBotCommandInput) int { return strings.Compare(a.Name, b.Name) }) + for i := range extras { + extras[i].Name = b.advertisedCommandName(extras[i].Name) + } commands = append(commands, extras...) return commands } +func (b *Bot) advertisedCommandName(command string) string { + return fmt.Sprintf("%s %s", b.name, command) +} + func (b *Bot) advertiseCommands() error { advertiser, ok := b.backend.(commandAdvertiser) if !ok { diff --git a/bot_test.go b/bot_test.go index f2bcfaf..da3c3c2 100644 --- a/bot_test.go +++ b/bot_test.go @@ -119,30 +119,29 @@ func TestAdvertisedCommands(t *testing.T) { bot.AddAdvertisements(chat1.UserBotCommandInput{ Name: "build", Description: "Build things", - Usage: "!testbot build ", + Usage: "", }) commands := bot.AdvertisedCommands() if len(commands) != 3 { t.Fatalf("expected 3 advertised commands, got %d", len(commands)) } - if commands[0].Name != "help" { + if commands[0].Name != "testbot help" { t.Fatalf("expected help command first, got %q", commands[0].Name) } if commands[0].ExtendedDescription == nil || commands[0].ExtendedDescription.DesktopBody != "help body" { t.Fatalf("unexpected help extended description: %+v", commands[0].ExtendedDescription) } if commands[1] != (chat1.UserBotCommandInput{ - Name: "date", + Name: "testbot date", Description: "Show the current date", - Usage: "!testbot date", }) { t.Fatalf("unexpected builtin command: %+v", commands[1]) } if commands[2] != (chat1.UserBotCommandInput{ - Name: "build", + Name: "testbot build", Description: "Build things", - Usage: "!testbot build ", + Usage: "", }) { t.Fatalf("unexpected extra command: %+v", commands[2]) } diff --git a/keybot/keybot.go b/keybot/keybot.go index c3bc65d..aff9609 100644 --- a/keybot/keybot.go +++ b/keybot/keybot.go @@ -325,16 +325,15 @@ func (k *keybot) Help(bot *slackbot.Bot) string { } func (k *keybot) Advertisements(bot *slackbot.Bot) []chat1.UserBotCommandInput { - prefix := "!" + bot.Name() return []chat1.UserBotCommandInput{ - {Name: "build", Description: "Build darwin, mobile, android, or ios artifacts", Usage: prefix + " build [flags]"}, - {Name: "cancel", Description: "Cancel a launchd job by label", Usage: prefix + " cancel