commit b14990cefdc97e3e6aa698d4e19d091b3b02045f
parent 1d11e362542eb3db30778616552abe90bf4f14b2
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Mon, 20 Mar 2023 03:28:51 -0700
spam
Diffstat:
2 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/pkg/web/handlers/api/v1/spamInterceptor.go b/pkg/web/handlers/api/v1/spamInterceptor.go
@@ -105,16 +105,18 @@ func checkSpam(db *database.DkfDB, origMessage string, authUser *database.User)
}
}
- profanityWords := []string{"cock", "dick", "nigger", "niggers", "nigga", "niggas", "sex", "rape", "porn"}
- profanity := 0
- for _, w := range profanityWords {
- if n, ok := wordsMap[w]; ok {
- profanity += n
+ if authUser.GeneralMessagesCount < 10 {
+ if autoKickProfanity(tot, wordsMap) {
+ _ = dutils.SelfKick(db, *authUser, silentSelfKick)
+ return ErrSpamFilterTriggered
}
}
if authUser.GeneralMessagesCount < 10 {
- if wordsMap["porn"] > 0 && (wordsMap["link"] > 0 || wordsMap["links"] > 0) {
+ if ((wordsMap["learn"] > 0 || wordsMap["teach"] > 0) && (wordsMap["hacking"] > 0 || wordsMap["hack"] > 0)) ||
+ (wordsMap["cook"] > 0 && wordsMap["meth"] > 0) ||
+ (wordsMap["creepy"] > 0 && (wordsMap["site"] > 0 || wordsMap["sites"] > 0)) ||
+ (wordsMap["porn"] > 0 && (wordsMap["link"] > 0 || wordsMap["links"] > 0)) {
_ = dutils.SelfKick(db, *authUser, silentSelfKick)
return ErrSpamFilterTriggered
}
@@ -130,6 +132,31 @@ func checkSpam(db *database.DkfDB, origMessage string, authUser *database.User)
return nil
}
+func autoKickProfanityTmp(orig string) bool {
+ tot, m := utils.WordCount(strings.ToLower(orig))
+ return autoKickProfanity(tot, m)
+}
+
+func autoKickProfanity(tot int, wordsMap map[string]int) bool {
+ if tot > 4 && countProfanity(wordsMap) >= 4 {
+ return true
+ }
+ return false
+}
+
+func countProfanity(wordsMap map[string]int) int {
+ profanityWords := []string{"anus", "asshole", "cock", "dick", "nigger", "niggers", "nigga", "niggas", "sex", "rape", "porn",
+ "cunt", "murder", "fuck", "blood", "corpse", "hole", "slut", "bitch", "shit", "poop", "butt", "faggot",
+ "submissive", "slurping", "suck", "nuts", "gore", "stupid", "dumb", "jerking", "rotten", "rotted", "stinky"}
+ profanity := 0
+ for _, w := range profanityWords {
+ if n, ok := wordsMap[w]; ok {
+ profanity += n
+ }
+ }
+ return profanity
+}
+
var spamCharsRgx = regexp.MustCompile("[^a-z0-9]+")
func autoKickSpammers(authUser *database.User, lowerCaseMessage string) bool {
diff --git a/pkg/web/handlers/api/v1/spamInterceptor_test.go b/pkg/web/handlers/api/v1/spamInterceptor_test.go
@@ -44,3 +44,25 @@ func Test_autoKickSpammers(t *testing.T) {
})
}
}
+
+func Test_autoKickProfanityTmp(t *testing.T) {
+ type args struct {
+ orig string
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {"", args{orig: "biden is dumb fuck can suck my dick stupid nigger"}, true},
+ {"", args{orig: "u can suck his nuts like the submissive faggot u are. slurping eye contact for deep man love with dirty butthole sniffing."}, true},
+ {"", args{orig: "how to tear a human slut bitch from the cunt to the part in her hairline then shit into the chest cavity for happy dumpling poop soup"}, true},
+ {"", args{orig: "lets murder a nun and fuck the blood scabs into her corpse pussy hole"}, true},
+ {"", args{orig: "quick question, whats the best method to plant a grenaed in old ladys stinky rotted cunt hole to blast her bloods on a hotel walls"}, true},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ assert.Equalf(t, tt.want, autoKickProfanityTmp(tt.args.orig), "autoKickProfanityTmp(%v)", tt.args.orig)
+ })
+ }
+}