From a1936b5fa0578016e28aa86303ea1c17613ca313 Mon Sep 17 00:00:00 2001 From: Raed Shomali Date: Tue, 26 Jul 2022 08:46:45 -0400 Subject: [PATCH] Examples --- README.md | 10 +++++----- command.go | 2 +- examples/14/example14.go | 2 +- examples/2/example2.go | 2 +- examples/3/example3.go | 4 ++-- examples/4/example4.go | 2 +- slacker.go | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index dda8259..c6f653f 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ func main() { definition := &slacker.CommandDefinition{ Description: "Ping!", - Example: "ping", + Examples: []string{"ping"}, Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) { response.Reply("pong", slacker.WithThreadReply(true)) }, @@ -165,7 +165,7 @@ func main() { bot.Command("echo {word}", &slacker.CommandDefinition{ Description: "Echo a word!", - Example: "echo hello", + Examples: []string{"echo hello"}, Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) { word := request.Param("word") response.Reply(word) @@ -174,7 +174,7 @@ func main() { bot.Command("say ", &slacker.CommandDefinition{ Description: "Say a sentence!", - Example: "say hello there everyone!", + Examples: []string{"say hello there everyone!"}, Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) { sentence := request.Param("sentence") response.Reply(sentence) @@ -212,7 +212,7 @@ func main() { definition := &slacker.CommandDefinition{ Description: "Repeat a word a number of times!", - Example: "repeat hello 10", + Examples: []string{"repeat hello 10"}, Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) { word := request.StringParam("word", "Hello!") number := request.IntegerParam("number", 1) @@ -755,7 +755,7 @@ func main() { bot.Command("echo {word}", &slacker.CommandDefinition{ Description: "Echo a word!", - Example: "echo hello", + Examples: []string{"echo hello"}, Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) { word := request.Param("word") response.Reply(word) diff --git a/command.go b/command.go index a6c38f1..b56f5a8 100644 --- a/command.go +++ b/command.go @@ -10,7 +10,7 @@ import ( // CommandDefinition structure contains definition of the bot command type CommandDefinition struct { Description string - Example string + Examples []string BlockID string AuthorizationFunc func(botCtx BotContext, request Request) bool Handler func(botCtx BotContext, request Request, response ResponseWriter) diff --git a/examples/14/example14.go b/examples/14/example14.go index 68d410f..052556d 100644 --- a/examples/14/example14.go +++ b/examples/14/example14.go @@ -34,7 +34,7 @@ func main() { bot.Command("echo {word}", &slacker.CommandDefinition{ Description: "Echo a word!", - Example: "echo hello", + Examples: []string{"echo hello"}, Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) { word := request.Param("word") response.Reply(word) diff --git a/examples/2/example2.go b/examples/2/example2.go index d4b399e..b1d51be 100644 --- a/examples/2/example2.go +++ b/examples/2/example2.go @@ -13,7 +13,7 @@ func main() { definition := &slacker.CommandDefinition{ Description: "Ping!", - Example: "ping", + Examples: []string{"ping"}, Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) { response.Reply("pong", slacker.WithThreadReply(true)) }, diff --git a/examples/3/example3.go b/examples/3/example3.go index 607b3a4..0a00cc5 100644 --- a/examples/3/example3.go +++ b/examples/3/example3.go @@ -13,7 +13,7 @@ func main() { bot.Command("echo {word}", &slacker.CommandDefinition{ Description: "Echo a word!", - Example: "echo hello", + Examples: []string{"echo hello"}, Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) { word := request.Param("word") response.Reply(word) @@ -22,7 +22,7 @@ func main() { bot.Command("say ", &slacker.CommandDefinition{ Description: "Say a sentence!", - Example: "say hello there everyone!", + Examples: []string{"say hello there everyone!"}, Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) { sentence := request.Param("sentence") response.Reply(sentence) diff --git a/examples/4/example4.go b/examples/4/example4.go index 9104ab2..e8eb51e 100644 --- a/examples/4/example4.go +++ b/examples/4/example4.go @@ -13,7 +13,7 @@ func main() { definition := &slacker.CommandDefinition{ Description: "Repeat a word a number of times!", - Example: "repeat hello 10", + Examples: []string{"repeat hello 10"}, Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) { word := request.StringParam("word", "Hello!") number := request.IntegerParam("number", 1) diff --git a/slacker.go b/slacker.go index 5dcc607..aa52f78 100644 --- a/slacker.go +++ b/slacker.go @@ -285,8 +285,8 @@ func (s *Slacker) defaultHelp(botCtx BotContext, request Request, response Respo helpMessage += newLine - if len(command.Definition().Example) > 0 { - helpMessage += fmt.Sprintf(quoteMessageFormat, command.Definition().Example) + newLine + for _, example := range command.Definition().Examples { + helpMessage += fmt.Sprintf(quoteMessageFormat, example) + newLine } }