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

Function conditionMatches

internal/pushrules/evaluate.go:120–145  ·  view source on GitHub ↗
(cond *Condition, event *gomatrixserverlib.Event, ec EvaluationContext)

Source from the content-addressed store, hash-verified

118}
119
120func conditionMatches(cond *Condition, event *gomatrixserverlib.Event, ec EvaluationContext) (bool, error) {
121 switch cond.Kind {
122 case EventMatchCondition:
123 return patternMatches(cond.Key, cond.Pattern, event)
124
125 case ContainsDisplayNameCondition:
126 return patternMatches("content.body", ec.UserDisplayName(), event)
127
128 case RoomMemberCountCondition:
129 cmp, err := parseRoomMemberCountCondition(cond.Is)
130 if err != nil {
131 return false, fmt.Errorf("parsing room_member_count condition: %w", err)
132 }
133 n, err := ec.RoomMemberCount()
134 if err != nil {
135 return false, fmt.Errorf("RoomMemberCount failed: %w", err)
136 }
137 return cmp(n), nil
138
139 case SenderNotificationPermissionCondition:
140 return ec.HasPowerLevel(event.Sender(), cond.Key)
141
142 default:
143 return false, nil
144 }
145}
146
147func patternMatches(key, pattern string, event *gomatrixserverlib.Event) (bool, error) {
148 re, err := globToRegexp(pattern)

Callers 2

TestConditionMatchesFunction · 0.85
ruleMatchesFunction · 0.85

Calls 5

patternMatchesFunction · 0.85
UserDisplayNameMethod · 0.65
RoomMemberCountMethod · 0.65
HasPowerLevelMethod · 0.65

Tested by 1

TestConditionMatchesFunction · 0.68