mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-04-21 08:47:33 -05:00
55 lines
937 B
Go
55 lines
937 B
Go
package nas
|
|
|
|
import (
|
|
"bufio"
|
|
"errors"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
var profanityFilePath = "./profanity.txt"
|
|
var profanityFileLines []string = nil
|
|
|
|
func CacheProfanityFile() error {
|
|
file, err := os.Open(profanityFilePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer file.Close()
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
for scanner.Scan() {
|
|
line := scanner.Text()
|
|
|
|
if line == "" {
|
|
continue
|
|
}
|
|
|
|
profanityFileLines = append(profanityFileLines, line)
|
|
}
|
|
|
|
if profanityFileLines == nil {
|
|
return errors.New("the file '" + profanityFilePath + "' is empty")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func IsBadWord(word string) (bool, error) {
|
|
if !isProfanityFileCached() {
|
|
return false, errors.New("the file '" + profanityFilePath + "' has not been cached")
|
|
}
|
|
|
|
for _, line := range profanityFileLines {
|
|
if strings.EqualFold(line, word) {
|
|
return true, nil
|
|
}
|
|
}
|
|
|
|
return false, nil
|
|
}
|
|
|
|
func isProfanityFileCached() bool {
|
|
return profanityFileLines != nil
|
|
}
|