forked from shomali11/slacker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.go
More file actions
35 lines (29 loc) · 1.07 KB
/
Copy pathcommand.go
File metadata and controls
35 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package slacker
import (
"github.com/shomali11/commander"
"github.com/shomali11/proper"
)
// NewBotCommand creates a new bot command object
func NewBotCommand(usage string, description string, handler func(request Request, response ResponseWriter)) *BotCommand {
command := commander.NewCommand(usage)
return &BotCommand{usage: usage, description: description, handler: handler, command: command}
}
// BotCommand structure contains the bot's command, description and handler
type BotCommand struct {
usage string
description string
handler func(request Request, response ResponseWriter)
command *commander.Command
}
// Match determines whether the bot should respond based on the text received
func (c *BotCommand) Match(text string) (*proper.Properties, bool) {
return c.command.Match(text)
}
// Tokenize returns the command format's tokens
func (c *BotCommand) Tokenize() []*commander.Token {
return c.command.Tokenize()
}
// Execute executes the handler logic
func (c *BotCommand) Execute(request Request, response ResponseWriter) {
c.handler(request, response)
}