From 63542e733452e64d6d6c3063a6d74960ea900868 Mon Sep 17 00:00:00 2001 From: Steven Arnott Date: Fri, 25 Oct 2024 15:33:04 -0400 Subject: [PATCH] Added check to isValidHitChatRule where a rule needs one of Hear, Respond, ReactionsAdded, or ReactionsRremoved Update matcher_tests --- core/matcher.go | 7 +++++++ core/matcher_test.go | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/core/matcher.go b/core/matcher.go index 1b10ed7e..5d4ccbb6 100644 --- a/core/matcher.go +++ b/core/matcher.go @@ -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 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 { diff --git a/core/matcher_test.go b/core/matcher_test.go index 062c518c..a35769e6 100644 --- a/core/matcher_test.go +++ b/core/matcher_test.go @@ -645,12 +645,14 @@ 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) @@ -658,6 +660,7 @@ func Test_isValidHitChatRule(t *testing.T) { testMessageFail.Vars = failVars testRuleUserAllowed := models.Rule{} + testRuleUserAllowed.Hear = "stuff" testRuleUserAllowed.AllowUsers = []string{"fooUser"} testMessageUserAllowed := new(models.Message) userAllowedVars := make(map[string]string) @@ -665,6 +668,7 @@ func Test_isValidHitChatRule(t *testing.T) { testMessageUserAllowed.Vars = userAllowedVars testRuleNeedArg := models.Rule{} + testRuleNeedArg.Respond = "stuff" testRuleNeedArg.AllowUsers = []string{"fooUser"} testRuleNeedArg.Args = []string{"arg1", "arg2"} testMessageNeedArg := new(models.Message) @@ -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)