package spam import ( "errors" "strings" "code.nonshy.com/nonshy/website/pkg/models" ) // 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 } // 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{ "open", "mind", "minded", "openminded", "openmind", "taboo", "tabboo", "perv", "pervy", "grew", "raised", "raise", "children", "kid", "kids", "dad", "dads", "mom", "moms", "underage", "yng", "ynger", "family", "families", "18", "shota", "shotacon", "loli", "lolicon", "jailbait", "incest", "limit", "limits", } func restrictTermsFrom(terms []string, blacklist map[string]interface{}) ([]string, int) { var ( result []string count int ) for _, term := range terms { if _, ok := blacklist[strings.ToLower(term)]; ok { count++ continue } result = append(result, term) } return result, count }