aboutsummaryrefslogtreecommitdiff
path: root/matrix/pushrules
diff options
context:
space:
mode:
Diffstat (limited to 'matrix/pushrules')
-rw-r--r--matrix/pushrules/condition.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/matrix/pushrules/condition.go b/matrix/pushrules/condition.go
index 12fd3f3..0b7776a 100644
--- a/matrix/pushrules/condition.go
+++ b/matrix/pushrules/condition.go
@@ -20,6 +20,7 @@ import (
"regexp"
"strconv"
"strings"
+ "unicode"
"maunium.net/go/mautrix"
@@ -116,7 +117,19 @@ func (cond *PushCondition) matchDisplayName(room Room, event *mautrix.Event) boo
if member == nil {
return false
}
- return strings.Contains(event.Content.Body, member.Displayname)
+
+ msg := event.Content.Body
+ isAcceptable := func(r uint8) bool {
+ return unicode.IsSpace(rune(r)) || unicode.IsPunct(rune(r))
+ }
+ length := len(member.Displayname)
+ for index := strings.Index(msg, member.Displayname); index != -1; index = strings.Index(msg, member.Displayname) {
+ if (index <= 0 || isAcceptable(msg[index-1])) && (index + length >= len(msg) || isAcceptable(msg[index+length])) {
+ return true
+ }
+ msg = msg[index+len(member.Displayname):]
+ }
+ return false
}
func (cond *PushCondition) matchMemberCount(room Room, event *mautrix.Event) bool {