Skip to content

Commit

Permalink
feat: add in ability to supply custom command matching interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcgovern-apixio committed Nov 15, 2024
1 parent bd3ee21 commit a3968d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions command_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func (g *CommandGroup) AddCommand(definition *CommandDefinition) {
g.commands = append(g.commands, newCommand(definition))
}

func (g *CommandGroup) AddCustomCommand(cmd Command) {
cmd.Definition().Command = strings.TrimSpace(fmt.Sprintf("%s %s", g.prefix, cmd.Definition().Command))
g.commands = append(g.commands, cmd)
}

// 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))
Expand Down
8 changes: 8 additions & 0 deletions slacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ func (s *Slacker) AddCommand(definition *CommandDefinition) {
s.commandGroups[0].AddCommand(definition)
}

func (s *Slacker) AddCustomCommand(cmd Command) {
if len(cmd.Definition().Command) == 0 {
s.logger.Error("missing `Command`")
return
}
s.commandGroups[0].AddCustomCommand(cmd)
}

// AddCommandMiddleware appends a new command middleware to the list of root level command middlewares
func (s *Slacker) AddCommandMiddleware(middleware CommandMiddlewareHandler) {
s.commandMiddlewares = append(s.commandMiddlewares, middleware)
Expand Down

0 comments on commit a3968d2

Please sign in to comment.