MCPcopy Create free account
hub / github.com/daodst/chat / ruleMatches

Function ruleMatches

internal/pushrules/evaluate.go:86–118  ·  view source on GitHub ↗
(rule *Rule, kind Kind, event *gomatrixserverlib.Event, ec EvaluationContext)

Source from the content-addressed store, hash-verified

84}
85
86func ruleMatches(rule *Rule, kind Kind, event *gomatrixserverlib.Event, ec EvaluationContext) (bool, error) {
87 if !rule.Enabled {
88 return false, nil
89 }
90
91 switch kind {
92 case OverrideKind, UnderrideKind:
93 for _, cond := range rule.Conditions {
94 ok, err := conditionMatches(cond, event, ec)
95 if err != nil {
96 return false, err
97 }
98 if !ok {
99 return false, nil
100 }
101 }
102 return true, nil
103
104 case ContentKind:
105 // TODO: "These configure behaviour for (unencrypted) messages
106 // that match certain patterns." - Does that mean "content.body"?
107 return patternMatches("content.body", rule.Pattern, event)
108
109 case RoomKind:
110 return rule.RuleID == event.RoomID(), nil
111
112 case SenderKind:
113 return rule.RuleID == event.Sender(), nil
114
115 default:
116 return false, nil
117 }
118}
119
120func conditionMatches(cond *Condition, event *gomatrixserverlib.Event, ec EvaluationContext) (bool, error) {
121 switch cond.Kind {

Callers 2

TestRuleMatchesFunction · 0.85
MatchEventMethod · 0.85

Calls 2

conditionMatchesFunction · 0.85
patternMatchesFunction · 0.85

Tested by 1

TestRuleMatchesFunction · 0.68