Skip to content

Commit

Permalink
watch the language πŸ™…πŸΌβ€β™‚οΈ
Browse files Browse the repository at this point in the history
  • Loading branch information
ghophp committed Nov 21, 2023
1 parent 9c1e632 commit 0282878
Showing 1 changed file with 82 additions and 45 deletions.
127 changes: 82 additions & 45 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"sync"
"time"
"unicode"

"github.com/gempir/go-twitch-irc/v4"
"github.com/llumus/lulis/internal/fs/s3"
Expand All @@ -23,41 +24,6 @@ import (

var log = logrus.New()

var bannedWords = []string{
"ass",
"fuck",
"suck",
"bitch",
"crap",
"puta",
"sex",
"learning disability",
"learning disabilities",
"learning disorder",
"learning disorders",
"learning difficulties",
"learning difficulty",
"problemas de aprendizagem",
"problema de aprendizagem",
"transtorno de aprendizagem",
"replace",
"replaced",
"replacing",
"replaces",
"substitua",
"substituir",
"substituindo",
"\"",
"β€œ",
"”",
"’",
"β€˜",
"''",
"``",
"\\",
"!*",
}

// healthCheckHandler is a simple HTTP handler function which writes a response used for cloud deploys
func healthCheckHandler(w http.ResponseWriter, _ *http.Request) {
_, _ = fmt.Fprintf(w, "OK")
Expand Down Expand Up @@ -158,16 +124,9 @@ func main() {
if ok {
log.Debugf("Message from queue: %s", message)

var bannedWordDetected string
for _, word := range bannedWords {
if strings.Contains(message, word) {
bannedWordDetected = word
break
}
}

if bannedWordDetected != "" {
log.Warnf("Banned word detected: %s", bannedWordDetected)
if containsBannedWord(message) {
log.Warnf("Banned word detected in message: %s", message)
client.Say(twitchChannelName, "Sorry, I can't say that.")
continue
}

Expand Down Expand Up @@ -256,3 +215,81 @@ func addPlayedVideo(videoPath string) {

playedVideos = append(playedVideos, videoPath)
}

var bannedWords = []string{
"porn",
"nude",
"sexually",
"shit",
"damn",
"hell",
"kill",
"murder",
"hit",
"fight",
"cocaine",
"weed",
"meth",
"idiot",
"stupid",
"dumb",
"suicide",
"abuse",
"trauma",
"rape",
"ass",
"fuck",
"suck",
"bitch",
"crap",
"puta",
"caralho",
"sex",
"disability",
"disabilities",
"disorder",
"disorders",
"aprendizagem",
"replace",
"replaced",
"replacing",
"replaces",
"substitua",
"substituir",
"substituindo",
"\"",
"β€œ",
"”",
"’",
"β€˜",
"''",
"``",
"\\",
"!*",
}

// containsBannedWord checks the message for any banned words
func containsBannedWord(message string) bool {
// Split the message into words
words := strings.FieldsFunc(message, func(r rune) bool {
return !unicode.IsLetter(r) && !unicode.IsNumber(r)
})

// Check each word
for _, word := range words {
if isBannedWord(word) {
return true
}
}

return false
}

func isBannedWord(word string) bool {
for _, banned := range bannedWords {
if strings.EqualFold(word, banned) {
return true
}
}
return false
}

0 comments on commit 0282878

Please sign in to comment.