mirror of
https://github.com/aljazceru/njump.git
synced 2026-02-19 13:04:39 +01:00
block words and tags based on gleasonator's policies.
This commit is contained in:
74
content_filtering.go
Normal file
74
content_filtering.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
)
|
||||
|
||||
func hasProhibitedWordOrTag(event *nostr.Event) bool {
|
||||
for _, tag := range event.Tags {
|
||||
if len(tag) >= 2 && tag[0] == "t" && slices.Contains(pornTags, tag[1]) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return pornWordsRe.MatchString(event.Content)
|
||||
}
|
||||
|
||||
// list copied from https://jsr.io/@gleasonator/policy/0.2.0/data/porntags.json
|
||||
var pornTags = []string{
|
||||
"adult",
|
||||
"ass",
|
||||
"assworship",
|
||||
"boobs",
|
||||
"boobies",
|
||||
"butt",
|
||||
"cock",
|
||||
"dick",
|
||||
"dickpic",
|
||||
"explosionloli",
|
||||
"femboi",
|
||||
"femboy",
|
||||
"fetish",
|
||||
"fuck",
|
||||
"freeporn",
|
||||
"girls",
|
||||
"loli",
|
||||
"milf",
|
||||
"nude",
|
||||
"nudity",
|
||||
"nsfw",
|
||||
"pantsu",
|
||||
"pussy",
|
||||
"porn",
|
||||
"porno",
|
||||
"porntube",
|
||||
"pornvideo",
|
||||
"sex",
|
||||
"sexpervertsyndicate",
|
||||
"sexporn",
|
||||
"sexy",
|
||||
"slut",
|
||||
"teen",
|
||||
"tits",
|
||||
"teenporn",
|
||||
"teens",
|
||||
"transnsfw",
|
||||
"xxx",
|
||||
}
|
||||
|
||||
var pornWordsRe = func() *regexp.Regexp {
|
||||
// list copied from https://jsr.io/@gleasonator/policy/0.2.0/data/pornwords.json
|
||||
pornWords := []string{
|
||||
"loli",
|
||||
"nsfw",
|
||||
"teen porn",
|
||||
}
|
||||
concat := strings.Join(pornWords, "|")
|
||||
regex := fmt.Sprintf(`\b()\b`, concat)
|
||||
return regexp.MustCompile(regex)
|
||||
}()
|
||||
@@ -111,11 +111,17 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
|
||||
// if it's porn we return a 404
|
||||
for _, url := range urlRegex.FindAllString(data.event.Content, len(data.event.Content)+1) {
|
||||
allUrls := urlRegex.FindAllString(data.event.Content, len(data.event.Content)+1)
|
||||
if len(allUrls) > 0 && hasProhibitedWordOrTag(data.event.Event) {
|
||||
log.Warn().Str("event", data.nevent).Msg("detect prohibited porn content")
|
||||
http.Error(w, "event is not allowed", 404)
|
||||
return
|
||||
}
|
||||
for _, url := range allUrls {
|
||||
if imageExtensionMatcher.MatchString(url) {
|
||||
if isImageNSFW(url) {
|
||||
log.Warn().Str("url", url).Str("event", data.nevent).Msg("detect nsfw image")
|
||||
http.Error(w, "event is unsuitable", 404)
|
||||
http.Error(w, "event is unsuitable for work", 404)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user