Browse Source

update react cmd to use a string map for aliases

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/197/head
Michael Telatynski 7 years ago
parent
commit
c774bb893b
No known key found for this signature in database GPG Key ID: 3F879DA5AD802A5E
  1. 15
      src/github.com/matrix-org/go-neb/services/github/github.go

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

@ -199,6 +199,15 @@ func (s *Service) cmdGithubCreate(roomID, userID string, args []string) (interfa
return gomatrix.TextMessage{"m.notice", fmt.Sprintf("Created issue: %s", *issue.HTMLURL)}, nil return gomatrix.TextMessage{"m.notice", fmt.Sprintf("Created issue: %s", *issue.HTMLURL)}, nil
} }
var cmdGithubReactAliases = map[string]string{
"+1": "+1",
"-1": "-1",
"laugh": "laugh",
"confused": "confused",
"heart": "heart",
"hooray": "hooray",
}
const cmdGithubReactUsage = `!github react [owner/repo]#issue (+1|-1|laugh|confused|heart|hooray)` const cmdGithubReactUsage = `!github react [owner/repo]#issue (+1|-1|laugh|confused|heart|hooray)`
func (s *Service) cmdGithubReact(roomID, userID string, args []string) (interface{}, error) { func (s *Service) cmdGithubReact(roomID, userID string, args []string) (interface{}, error) {
@ -209,7 +218,9 @@ func (s *Service) cmdGithubReact(roomID, userID string, args []string) (interfac
if len(args) < 2 { if len(args) < 2 {
return &gomatrix.TextMessage{"m.notice", "Usage: " + cmdGithubReactUsage}, nil return &gomatrix.TextMessage{"m.notice", "Usage: " + cmdGithubReactUsage}, nil
} }
if args[1] != "+1" && args[1] != "-1" && args[1] != "laugh" && args[1] != "confused" && args[1] != "heart" && args[1] != "hooray" {
reaction, ok := cmdGithubReactAliases[args[1]]
if !ok {
return &gomatrix.TextMessage{"m.notice", "Invalid reaction. Usage: " + cmdGithubReactUsage}, nil return &gomatrix.TextMessage{"m.notice", "Invalid reaction. Usage: " + cmdGithubReactUsage}, nil
} }
@ -219,7 +230,7 @@ func (s *Service) cmdGithubReact(roomID, userID string, args []string) (interfac
return resp, nil return resp, nil
} }
_, res, err := cli.Reactions.CreateIssueReaction(owner, repo, issueNum, args[1])
_, res, err := cli.Reactions.CreateIssueReaction(owner, repo, issueNum, reaction)
if err != nil { if err != nil {
log.WithField("err", err).Print("Failed to react to issue") log.WithField("err", err).Print("Failed to react to issue")

Loading…
Cancel
Save