Skip to content

Commit

Permalink
Added check to isValidHitChatRule where a rule needs one
Browse files Browse the repository at this point in the history
of Hear, Respond, ReactionsAdded, or ReactionsRremoved
Update matcher_tests
  • Loading branch information
Steven Arnott committed Oct 25, 2024
1 parent 422d826 commit 63542e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ func handleNoMatch(outputMsgs chan<- models.Message, message models.Message, hit
//
//nolint:gocyclo // refactor
func isValidHitChatRule(message *models.Message, rule models.Rule, processedInput string, bot *models.Bot) bool {

Check failure on line 243 in core/matcher.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

unnecessary leading newline (whitespace)

Check failure on line 243 in core/matcher.go

View workflow job for this annotation

GitHub Actions / build

unnecessary leading newline (whitespace)

Check failure on line 243 in core/matcher.go

View workflow job for this annotation

GitHub Actions / validate

unnecessary leading newline (whitespace)

// Check rule has one of Hear, Respond, ReactionsAdded or ReactionsRemoved
if !isValidChatRule(rule) {
message.Output = "Rule does not have one of Hear, Respond, ReactionsAdded or ReactionsRemoved defined "
return false
}

// Check to honor allow_users or allow_usergroups
canRunRule := utils.CanTrigger(message.Vars["_user.name"], message.Vars["_user.id"], rule, bot)
if !canRunRule {
Expand Down
5 changes: 5 additions & 0 deletions core/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,26 +645,30 @@ func Test_isValidHitChatRule(t *testing.T) {

testBot := new(models.Bot)
testRule := models.Rule{}
testRule.Hear = "stuff"
testMessage := new(models.Message)
happyVars := make(map[string]string)
happyVars["_user.name"] = "fooUser"
testMessage.Vars = happyVars

testRuleFail := models.Rule{}
testRuleFail.Hear = "stuff"
testRuleFail.AllowUsers = []string{"barUser"}
testMessageFail := new(models.Message)
failVars := make(map[string]string)
failVars["_user.name"] = "fooUser"
testMessageFail.Vars = failVars

testRuleUserAllowed := models.Rule{}
testRuleUserAllowed.Hear = "stuff"
testRuleUserAllowed.AllowUsers = []string{"fooUser"}
testMessageUserAllowed := new(models.Message)
userAllowedVars := make(map[string]string)
userAllowedVars["_user.name"] = "fooUser"
testMessageUserAllowed.Vars = userAllowedVars

testRuleNeedArg := models.Rule{}
testRuleNeedArg.Respond = "stuff"
testRuleNeedArg.AllowUsers = []string{"fooUser"}
testRuleNeedArg.Args = []string{"arg1", "arg2"}
testMessageNeedArg := new(models.Message)
Expand All @@ -673,6 +677,7 @@ func Test_isValidHitChatRule(t *testing.T) {
testMessageNeedArg.Vars = needArgVars

testRuleArgs := models.Rule{}
testRuleArgs.Respond = "stuff"
testRuleArgs.AllowUsers = []string{"fooUser"}
testRuleArgs.Args = []string{"arg1", "arg2"}
testMessageArgs := new(models.Message)
Expand Down

0 comments on commit 63542e7

Please sign in to comment.