2024-03-16 06:19:26 +00:00
|
|
|
package spam
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
2024-07-13 19:05:36 +00:00
|
|
|
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/models"
|
2024-03-16 06:19:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SpamWebsites to third-party video hosting apps: we already have our own chat room, and third-party links shared in
|
|
|
|
// public places can pose a risk to user privacy/safety.
|
|
|
|
var SpamWebsites = []string{
|
|
|
|
"join.skype.com",
|
|
|
|
"zoom.us",
|
|
|
|
"whereby.com",
|
|
|
|
"meet.jit.si",
|
|
|
|
"https://t.me",
|
|
|
|
}
|
|
|
|
|
|
|
|
// DetectSpamMessage searches a message (such as a comment, forum post, etc.) for spammy contents such as Skype invite links
|
|
|
|
// and returns an error if found.
|
|
|
|
func DetectSpamMessage(message string) error {
|
|
|
|
for _, link := range SpamWebsites {
|
|
|
|
if strings.Contains(message, link) {
|
|
|
|
return errors.New(
|
|
|
|
"Your message could not be posted because it contains a link to a third-party video chat website. " +
|
|
|
|
"In the interest of protecting our community, we do not allow linking to third-party video conferencing apps where user " +
|
|
|
|
"privacy and security may not hold up to our standards, or where the content may run against our terms of service.",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2024-07-13 19:05:36 +00:00
|
|
|
|
|
|
|
// RestrictSearchTerm can remove/replace search words to exclude blacklisted terms.
|
|
|
|
func RestrictSearchTerms(terms *models.Search) (*models.Search, error) {
|
|
|
|
var (
|
|
|
|
m = map[string]interface{}{}
|
|
|
|
result = &models.Search{}
|
|
|
|
r1, r2 int
|
|
|
|
)
|
|
|
|
|
|
|
|
// Map the blacklist for easy lookup.
|
|
|
|
for _, term := range restrictedSearchTerms {
|
|
|
|
m[term] = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter the includes+excludes.
|
|
|
|
result.Includes, r1 = restrictTermsFrom(terms.Includes, m)
|
|
|
|
result.Excludes, r2 = restrictTermsFrom(terms.Excludes, m)
|
|
|
|
|
|
|
|
// If we have excluded everything down to zero.
|
|
|
|
if len(terms.Includes) > 0 && len(result.Includes) == 0 {
|
|
|
|
result.Includes = append(result.Includes, "36c49b88-dd0c-4b9f-a4e1-f0c73c976ce2")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Were there restrictions?
|
|
|
|
if r1+r2 > 0 {
|
|
|
|
return result, errors.New("some search terms were restricted")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restricted search terms.
|
|
|
|
var restrictedSearchTerms = []string{
|
2024-07-16 04:08:28 +00:00
|
|
|
"open", "mind", "minded", "openminded", "openmind", "taboo", "tabboo", "perv", "pervy", "grew", "raised", "raise",
|
2024-07-26 04:11:09 +00:00
|
|
|
"children", "child", "kid", "kids", "dad", "dads", "mom", "moms", "father", "mother", "underage", "yng", "ynger", "family", "families",
|
|
|
|
"18", "shota", "shotacon", "loli", "lolicon", "jailbait", "incest", "limit", "limits", "uninhibited", "depraved", "age", "ages",
|
|
|
|
"son", "daughter", "sons", "daughters",
|
2024-07-13 19:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func restrictTermsFrom(terms []string, blacklist map[string]interface{}) ([]string, int) {
|
|
|
|
var (
|
|
|
|
result []string
|
|
|
|
count int
|
|
|
|
)
|
|
|
|
|
|
|
|
for _, term := range terms {
|
2024-07-26 04:11:09 +00:00
|
|
|
// Break words in "quoted strings" too.
|
|
|
|
words := strings.Split(term, " ")
|
|
|
|
for _, word := range words {
|
|
|
|
if _, ok := blacklist[strings.ToLower(word)]; ok {
|
|
|
|
count++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
result = append(result, word)
|
2024-07-13 19:05:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, count
|
|
|
|
}
|