From 34cc516aa924c3685c1a7745455bce39d89efbb4 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Tue, 31 May 2022 01:07:27 -0400 Subject: [PATCH] try another variation to find mentions --- fun.go | 2 +- honk.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fun.go b/fun.go index 3dafe4b..3a341e3 100644 --- a/fun.go +++ b/fun.go @@ -124,7 +124,7 @@ func reverbolate(userid int64, honks []*Honk) { h.Noise = demoji(h.Noise) h.Open = "open" for _, m := range h.Mentions { - if !strings.Contains(h.Noise, m.Nick()) { + if !m.IsPresent(h.Noise) { h.Noise = "(" + m.Who + ")" + h.Noise } } diff --git a/honk.go b/honk.go index be40d57..b7b6619 100644 --- a/honk.go +++ b/honk.go @@ -23,7 +23,6 @@ import ( "log/syslog" notrand "math/rand" "os" - "regexp" "strconv" "strings" "time" @@ -136,13 +135,14 @@ type Mention struct { Where string } -var re_firstname = regexp.MustCompile("@[[:alnum:]]+") - -func (mention *Mention) Nick() string { - if m := re_firstname.FindString(mention.Who); m != "" { - return m +func (mention *Mention) IsPresent(noise string) bool { + nick := strings.TrimLeft(mention.Who, "@") + idx := strings.IndexByte(nick, '@') + if idx != -1 { + nick = nick[:idx] } - return mention.Who + nick += "<" + return strings.Contains(noise, ">@"+nick) || strings.Contains(noise, "@"+nick) } type OldRevision struct {