some more bits of hfcs

This commit is contained in:
Ted Unangst 2019-10-04 21:57:53 -04:00
parent 9b28e2f159
commit 07b041fc26
2 changed files with 25 additions and 6 deletions

3
fun.go
View File

@ -35,7 +35,6 @@ import (
func reverbolate(userid int64, honks []*Honk) { func reverbolate(userid int64, honks []*Honk) {
filt := htfilter.New() filt := htfilter.New()
filt.Imager = replaceimg filt.Imager = replaceimg
zilences := getfilters(userid, filtCollapse)
for _, h := range honks { for _, h := range honks {
h.What += "ed" h.What += "ed"
if h.What == "tonked" { if h.What == "tonked" {
@ -76,7 +75,7 @@ func reverbolate(userid int64, honks []*Honk) {
h.Open = "" h.Open = ""
} }
} else { } else {
if badword := unsee(zilences, h); badword != "" { if badword := unsee(userid, h); badword != "" {
if h.Precis == "" { if h.Precis == "" {
h.Precis = badword h.Precis = badword
} }

28
hfcs.go
View File

@ -26,6 +26,7 @@ type Filter struct {
Actor string Actor string
IncludeAudience bool IncludeAudience bool
Text string Text string
re_text *regexp.Regexp
IsAnnounce bool IsAnnounce bool
Reject bool Reject bool
SkipMedia bool SkipMedia bool
@ -77,6 +78,13 @@ var filtcache = cacheNew(func(userid int64) (afiltermap, bool) {
log.Printf("error scanning filter: %s", err) log.Printf("error scanning filter: %s", err)
continue continue
} }
if filt.Text != "" {
filt.re_text, err = regexp.Compile("\\b(?i:" + filt.Text + ")\\b")
if err != nil {
log.Printf("error compiling filter text: %s", err)
continue
}
}
filt.ID = filterid filt.ID = filterid
if filt.Reject { if filt.Reject {
filtmap[filtReject] = append(filtmap[filtReject], filt) filtmap[filtReject] = append(filtmap[filtReject], filt)
@ -169,9 +177,15 @@ func matchfilter(h *Honk, f *Filter) bool {
} }
if match && f.Text != "" { if match && f.Text != "" {
match = false match = false
for _, d := range h.Donks { re := f.re_text
if d.Desc == f.Text { if re.MatchString(h.Noise) || re.MatchString(h.Precis) {
match = true match = true
}
if !match {
for _, d := range h.Donks {
if re.MatchString(d.Desc) {
match = true
}
} }
} }
} }
@ -202,7 +216,13 @@ func skipMedia(xonk *Honk) bool {
} }
// todo // todo
func unsee(filts []*Filter, h *Honk) string { func unsee(userid int64, h *Honk) string {
filts := getfilters(userid, filtCollapse)
for _, f := range filts {
if matchfilter(h, f) {
return f.Text
}
}
return "" return ""
} }