Skip to content

Commit

Permalink
fix mention parse function
Browse files Browse the repository at this point in the history
  • Loading branch information
sho0126hiro committed Oct 26, 2022
1 parent b66709a commit 525674c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/internal/domain/service/slack_mentioned.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ func (s *slackMentionedService) Parse(message string) *model.MentionParseResult
Message: message,
}
}
if strings.HasPrefix(tmp[1], ":") && strings.HasSuffix(tmp[1], ":") {
reaction := tmp[1]
if strings.HasPrefix(reaction, ":") && strings.HasSuffix(reaction, ":") {
return &model.MentionParseResult{
Message: message,
Reaction: strings.ReplaceAll(tmp[1], ":", ""),
Reaction: strings.ReplaceAll(s.removeSkinTone(reaction), ":", ""),
}
}
// invalid argument (not emoji)
Expand All @@ -57,3 +58,10 @@ func (s *slackMentionedService) Parse(message string) *model.MentionParseResult
Command: CommandHelp,
}
}

func (s *slackMentionedService) removeSkinTone(reaction string) string {
for _, st := range model.ReactionSkinTones {
reaction = strings.ReplaceAll(reaction, st, "")
}
return reaction
}
8 changes: 8 additions & 0 deletions app/internal/domain/service/slack_mentioned_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func Test_slackMentionedService_Parse(t *testing.T) {
Command: CommandHelp,
},
},
{
name: "OK: when a reaction with skin-tone is specified",
args: args{message: "@auriga :+1::skin-tone-2:"},
want: &model.MentionParseResult{
Message: "@auriga :+1::skin-tone-2:",
Reaction: "+1",
},
},
{
name: "NG: reaction is formatted incorrectly.",
args: args{message: "@auriga :tmp"},
Expand Down

0 comments on commit 525674c

Please sign in to comment.