-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V2 Foundation: Groups, Middlewares, Simplified Interfaces, ... (#134)
feat: Slacker V2 - Simplified Interfaces - Added support for Groups, Middleware - Enhanced support for Interaction Callbacks - Enhanced support for Cron Jobs - Added support for more message actions - Improved examples and documentation
- Loading branch information
1 parent
c38812c
commit bc3ade5
Showing
59 changed files
with
2,070 additions
and
2,432 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,21 +1,21 @@ | ||
package slacker | ||
|
||
// BotInteractionMode instruct the bot on how to handle incoming events that | ||
// BotMode instruct the bot on how to handle incoming events that | ||
// originated from a bot. | ||
type BotInteractionMode int | ||
type BotMode int | ||
|
||
const ( | ||
// BotInteractionModeIgnoreAll instructs our bot to ignore any activity coming | ||
// BotModeIgnoreAll instructs our bot to ignore any activity coming | ||
// from other bots, including our self. | ||
BotInteractionModeIgnoreAll BotInteractionMode = iota | ||
BotModeIgnoreAll BotMode = iota | ||
|
||
// BotInteractionModeIgnoreApp will ignore any events that originate from a | ||
// BotModeIgnoreApp will ignore any events that originate from a | ||
// bot that is associated with the same App (ie. share the same App ID) as | ||
// this bot. OAuth scope `user:read` is required for this mode. | ||
BotInteractionModeIgnoreApp | ||
BotModeIgnoreApp | ||
|
||
// BotInteractionModeIgnoreNone will not ignore any bots, including our self. | ||
// BotModeIgnoreNone will not ignore any bots, including our self. | ||
// This can lead to bots "talking" to each other so care must be taken when | ||
// selecting this option. | ||
BotInteractionModeIgnoreNone | ||
BotModeIgnoreNone | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package slacker | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// newGroup creates a new CommandGroup with a prefix | ||
func newGroup(prefix string) *CommandGroup { | ||
return &CommandGroup{prefix: prefix} | ||
} | ||
|
||
// CommandGroup groups commands with a common prefix and middlewares | ||
type CommandGroup struct { | ||
prefix string | ||
middlewares []CommandMiddlewareHandler | ||
commands []Command | ||
} | ||
|
||
// AddMiddleware define a new middleware and append it to the list of group middlewares | ||
func (g *CommandGroup) AddMiddleware(middleware CommandMiddlewareHandler) { | ||
g.middlewares = append(g.middlewares, middleware) | ||
} | ||
|
||
// AddCommand define a new command and append it to the list of group bot commands | ||
func (g *CommandGroup) AddCommand(definition *CommandDefinition) { | ||
definition.Command = strings.TrimSpace(fmt.Sprintf("%s %s", g.prefix, definition.Command)) | ||
g.commands = append(g.commands, newCommand(definition)) | ||
} | ||
|
||
// PrependCommand define a new command and prepend it to the list of group bot commands | ||
func (g *CommandGroup) PrependCommand(definition *CommandDefinition) { | ||
definition.Command = strings.TrimSpace(fmt.Sprintf("%s %s", g.prefix, definition.Command)) | ||
g.commands = append([]Command{newCommand(definition)}, g.commands...) | ||
} | ||
|
||
// GetPrefix returns the group's prefix | ||
func (g *CommandGroup) GetPrefix() string { | ||
return g.prefix | ||
} | ||
|
||
// GetCommands returns Commands | ||
func (g *CommandGroup) GetCommands() []Command { | ||
return g.commands | ||
} | ||
|
||
// GetMiddlewares returns Middlewares | ||
func (g *CommandGroup) GetMiddlewares() []CommandMiddlewareHandler { | ||
return g.middlewares | ||
} |
Oops, something went wrong.