Browse Source

Add "!github help" and fix command selection bug

The last command would always be chosen due to pointer fail.
pull/142/head
Kegan Dougal 8 years ago
parent
commit
96109afd41
  1. 4
      src/github.com/matrix-org/go-neb/clients/clients.go
  2. 9
      src/github.com/matrix-org/go-neb/services/github/github.go

4
src/github.com/matrix-org/go-neb/clients/clients.go

@ -215,11 +215,11 @@ func (c *Clients) onMessageEvent(client *gomatrix.Client, event *gomatrix.Event)
// response is appropriate. // response is appropriate.
func runCommandForService(cmds []types.Command, event *gomatrix.Event, arguments []string) interface{} { func runCommandForService(cmds []types.Command, event *gomatrix.Event, arguments []string) interface{} {
var bestMatch *types.Command var bestMatch *types.Command
for _, command := range cmds {
for i, command := range cmds {
matches := command.Matches(arguments) matches := command.Matches(arguments)
betterMatch := bestMatch == nil || len(bestMatch.Path) < len(command.Path) betterMatch := bestMatch == nil || len(bestMatch.Path) < len(command.Path)
if matches && betterMatch { if matches && betterMatch {
bestMatch = &command
bestMatch = &cmds[i]
} }
} }

9
src/github.com/matrix-org/go-neb/services/github/github.go

@ -163,6 +163,15 @@ func (s *Service) Commands(cli *gomatrix.Client) []types.Command {
return s.cmdGithubCreate(roomID, userID, args) return s.cmdGithubCreate(roomID, userID, args)
}, },
}, },
types.Command{
Path: []string{"github", "help"},
Command: func(roomID, userID string, args []string) (interface{}, error) {
return &gomatrix.TextMessage{
"m.notice",
fmt.Sprintf(`!github create owner/repo "title text" "description text"`),
}, nil
},
},
} }
} }

Loading…
Cancel
Save