From 96109afd41c4ebfcb20686c6075fd21a20ebf911 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 23 Dec 2016 15:13:25 +0000 Subject: [PATCH] Add "!github help" and fix command selection bug The last command would always be chosen due to pointer fail. --- src/github.com/matrix-org/go-neb/clients/clients.go | 4 ++-- .../matrix-org/go-neb/services/github/github.go | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/clients/clients.go b/src/github.com/matrix-org/go-neb/clients/clients.go index 1927f64..bd850a4 100644 --- a/src/github.com/matrix-org/go-neb/clients/clients.go +++ b/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. func runCommandForService(cmds []types.Command, event *gomatrix.Event, arguments []string) interface{} { var bestMatch *types.Command - for _, command := range cmds { + for i, command := range cmds { matches := command.Matches(arguments) betterMatch := bestMatch == nil || len(bestMatch.Path) < len(command.Path) if matches && betterMatch { - bestMatch = &command + bestMatch = &cmds[i] } } diff --git a/src/github.com/matrix-org/go-neb/services/github/github.go b/src/github.com/matrix-org/go-neb/services/github/github.go index 5de367b..e9897a4 100644 --- a/src/github.com/matrix-org/go-neb/services/github/github.go +++ b/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) }, }, + 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 + }, + }, } }