forked from shomali11/slacker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code clean up and performance improvements
- Loading branch information
1 parent
963ede0
commit 9d124ce
Showing
13 changed files
with
230 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
package slacker | ||
|
||
import "github.com/shomali11/slacker/expression" | ||
import ( | ||
"github.com/shomali11/commander" | ||
"github.com/shomali11/properties" | ||
) | ||
|
||
// NewCommand creates a new command structure | ||
func NewCommand(usage string, description string, handler func(request *Request, response *Response)) *Command { | ||
return &Command{usage: usage, description: description, handler: handler} | ||
// NewBotCommand creates a new bot command object | ||
func NewBotCommand(usage string, description string, handler func(request *Request, response *Response)) *BotCommand { | ||
command := commander.NewCommand(usage) | ||
return &BotCommand{usage: usage, description: description, handler: handler, command: command} | ||
} | ||
|
||
// Command structure contains the command, description and handler | ||
type Command struct { | ||
// BotCommand structure contains the bot's command, description and handler | ||
type BotCommand struct { | ||
usage string | ||
description string | ||
handler func(request *Request, response *Response) | ||
command *commander.Command | ||
} | ||
|
||
// Match determines whether the bot should respond based on the text received | ||
func (c *Command) Match(text string) (bool, map[string]string) { | ||
return expression.Match(c.usage, text) | ||
func (c *BotCommand) Match(text string) (*properties.Properties, bool) { | ||
return c.command.Match(text) | ||
} | ||
|
||
// Execute executes the handler logic | ||
func (c *Command) Execute(request *Request, response *Response) { | ||
func (c *BotCommand) Execute(request *Request, response *Response) { | ||
c.handler(request, response) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.