Skip to content
Merged
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
13 changes: 9 additions & 4 deletions advertisement.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,35 @@ 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),
})
}

extras := slices.Clone(b.advertisements)
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 {
Expand Down
11 changes: 5 additions & 6 deletions bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,29 @@ func TestAdvertisedCommands(t *testing.T) {
bot.AddAdvertisements(chat1.UserBotCommandInput{
Name: "build",
Description: "Build things",
Usage: "!testbot build <target>",
Usage: "<target>",
})

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 <target>",
Usage: "<target>",
}) {
t.Fatalf("unexpected extra command: %+v", commands[2])
}
Expand Down
21 changes: 10 additions & 11 deletions keybot/keybot.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,16 @@ func (k *keybot) Help(bot *slackbot.Bot) string {
return out
}

func (k *keybot) Advertisements(bot *slackbot.Bot) []chat1.UserBotCommandInput {
prefix := "!" + bot.Name()
func (k *keybot) Advertisements() []chat1.UserBotCommandInput {
return []chat1.UserBotCommandInput{
{Name: "build", Description: "Build darwin, mobile, android, or ios artifacts", Usage: prefix + " build <darwin|mobile|android|ios> [flags]"},
{Name: "cancel", Description: "Cancel a launchd job by label", Usage: prefix + " cancel <label>"},
{Name: "dumplog", Description: "Show the log file for a launchd job", Usage: prefix + " dumplog <label>"},
{Name: "gclean", Description: "Clean the go/go-ios/go-android repos", Usage: prefix + " gclean"},
{Name: "gdiff", Description: "Show the git diff for a repo under $GOPATH/src", Usage: prefix + " gdiff <repo>"},
{Name: "nodeModuleClean", Description: "Clean the ios/android node_modules", Usage: prefix + " nodeModuleClean"},
{Name: "release", Description: "Promote or mark releases as broken", Usage: prefix + " release <promote|broken> ..."},
{Name: "smoketest", Description: "Set smoketesting status for a build", Usage: prefix + " smoketest --build-a <id> --platform <name> --enable <bool> --max-testers <n>"},
{Name: "upgrade", Description: "Upgrade a package", Usage: prefix + " upgrade <name>"},
{Name: "build", Description: "Build darwin, mobile, android, or ios artifacts", Usage: "<darwin|mobile|android|ios> [flags]"},
{Name: "cancel", Description: "Cancel a launchd job by label", Usage: "<label>"},
{Name: "dumplog", Description: "Show the log file for a launchd job", Usage: "<label>"},
{Name: "gclean", Description: "Clean the go/go-ios/go-android repos"},
{Name: "gdiff", Description: "Show the git diff for a repo under $GOPATH/src", Usage: "<repo>"},
{Name: "nodeModuleClean", Description: "Clean the ios/android node_modules"},
{Name: "release", Description: "Promote or mark releases as broken", Usage: "<promote|broken> ..."},
{Name: "smoketest", Description: "Set smoketesting status for a build", Usage: "--build-a <id> --platform <name> --enable <bool> --max-testers <n>"},
{Name: "upgrade", Description: "Upgrade a package", Usage: "<name>"},
}
}
4 changes: 2 additions & 2 deletions keybot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func addBasicCommands(bot *slackbot.Bot) {
type extension interface {
Run(b *slackbot.Bot, channel string, args []string) (string, error)
Help(bot *slackbot.Bot) string
Advertisements(bot *slackbot.Bot) []chat1.UserBotCommandInput
Advertisements() []chat1.UserBotCommandInput
}

func main() {
Expand Down Expand Up @@ -99,7 +99,7 @@ func main() {
}
bot.SetDefault(slackbot.NewFuncCommand(runFn, "Extension", bot.Config()))
bot.SetHelp(bot.HelpMessage() + "\n\n" + ext.Help(bot))
bot.AddAdvertisements(ext.Advertisements(bot)...)
bot.AddAdvertisements(ext.Advertisements()...)

bot.SendMessage("I'm running.", channel)
if err := bot.Listen(); err != nil {
Expand Down
17 changes: 8 additions & 9 deletions keybot/winbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,15 @@ func (d *winbot) Help(bot *slackbot.Bot) string {
return out
}

func (d *winbot) Advertisements(bot *slackbot.Bot) []chat1.UserBotCommandInput {
prefix := "!" + bot.Name()
func (d *winbot) Advertisements() []chat1.UserBotCommandInput {
return []chat1.UserBotCommandInput{
{Name: "build", Description: "Start a windows build", Usage: prefix + " build [--test] [--client-commit <sha>] [--kbfs-commit <sha>] [--updater-commit <sha>] [--skip-ci] [--smoke] [--dev-cert]"},
{Name: "cancel", Description: "Cancel the current windows build", Usage: prefix + " cancel"},
{Name: "dumplog", Description: "Show the last windows build log file", Usage: prefix + " dumplog"},
{Name: "gclean", Description: "Clean a repo under $GOPATH/src", Usage: prefix + " gclean <repo>"},
{Name: "gdiff", Description: "Show the git diff for a repo under $GOPATH/src", Usage: prefix + " gdiff <repo>"},
{Name: "restart", Description: "Quit and let the calling script restart the bot", Usage: prefix + " restart"},
{Name: "startAutoTimer", Description: "Start or stop the automatic build timer", Usage: prefix + " startAutoTimer [--interval <hours>] [--startHour <hour>] [--delay <hours>]"},
{Name: "build", Description: "Start a windows build", Usage: "[--test] [--client-commit <sha>] [--kbfs-commit <sha>] [--updater-commit <sha>] [--skip-ci] [--smoke] [--dev-cert]"},
{Name: "cancel", Description: "Cancel the current windows build"},
{Name: "dumplog", Description: "Show the last windows build log file"},
{Name: "gclean", Description: "Clean a repo under $GOPATH/src", Usage: "<repo>"},
{Name: "gdiff", Description: "Show the git diff for a repo under $GOPATH/src", Usage: "<repo>"},
{Name: "restart", Description: "Quit and let the calling script restart the bot"},
{Name: "startAutoTimer", Description: "Start or stop the automatic build timer", Usage: "[--interval <hours>] [--startHour <hour>] [--delay <hours>]"},
}
}

Expand Down
Loading