Skip to content

Commit

Permalink
Processing speed update (faster processing)
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffy-melli committed Jan 19, 2025
1 parent 1bc99f3 commit 889cbbb
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 356 deletions.
76 changes: 75 additions & 1 deletion cache/blacklist.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cache

import "sync"
import (
"sync"

"github.com/google/btree"
)

var BlacklistMu = sync.RWMutex{}
var Blacklist = map[string]string{}
Expand Down Expand Up @@ -254,3 +258,73 @@ var Chinese = &[]string{
var Emoji = &[]string{
"🖕🏻", "👌🏻👈🏻", "👉🏻👌🏻", "🤏🏻", "🖕", "🖕🏼", "🖕🏽", "🖕🏾", "🖕🏿", ":middle_finger:",
}

const (
DGeneral int = iota + 1
DMinor
DSexual
DBelittle
DRace
DParent
DPolitics
DEnglish
DJapanese
DChinese
DSpecial
)

type TrieNode struct {
children map[rune]*TrieNode
isEnd bool
}

type Trie struct {
Root *TrieNode
}

func NewTrie() *Trie {
return &Trie{
Root: &TrieNode{
children: make(map[rune]*TrieNode),
},
}
}

func (t *Trie) Insert(word string) {
node := t.Root
for _, ch := range word {
if _, ok := node.children[ch]; !ok {
node.children[ch] = &TrieNode{children: make(map[rune]*TrieNode)}
}
node = node.children[ch]
}
node.isEnd = true
}

func (t *Trie) Search(word string) bool {
node := t.Root
for _, ch := range word {
if _, ok := node.children[ch]; !ok {
return false
}
node = node.children[ch]
}
return node.isEnd
}

type WordEntry struct {
Word string
WType int
}

func (w WordEntry) Less(than btree.Item) bool {
return w.Word < than.(WordEntry).Word
}

var (
ProfanityTrie = NewTrie()

BTree = btree.New(8)

Mu sync.RWMutex
)
24 changes: 17 additions & 7 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ import (
)

func main() {
// Discord Message Event Logic
ck := korcen.Check("MESSAGE")
korcen.InitProfanityData()

sampleInput := "MESSAGE"

ck := korcen.Check(sampleInput)

if ck.Detect {
dtif := ck.Swear[0]
message := ck.NewText[:dtif.Start] + "\x1b[1m\x1b[41m\"" + ck.NewText[dtif.Start:dtif.End] + "\"\x1b[0m" + ck.NewText[dtif.End:]
discord_ansi := "```ansi\n" + message + "\n```"
fmt.Println(discord_ansi)
for _, dtif := range ck.Swear {
message := ck.NewText[:dtif.Start] +
"\x1b[1m\x1b[41m\"" + ck.NewText[dtif.Start:dtif.End] + "\"\x1b[0m" +
ck.NewText[dtif.End:]

discord_ansi := "```ansi\n" + message + "\n```"
fmt.Println(discord_ansi)
}
} else {
fmt.Println("비속어가 감지되지 않았습니다.")
}
// Discord Send Logic

}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ module github.com/fluffy-melli/korcen-go
go 1.20

require github.com/gyarang/gohangul v0.1.3

require github.com/google/btree v1.1.3 // indirect
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
github.com/gyarang/gohangul v0.1.3 h1:UV5TCR2+XheNr+q79nJoHCzDyUow4Z/AmOqxZqm3SvQ=
github.com/gyarang/gohangul v0.1.3/go.mod h1:EzJMLXEkhFBcEgmMNklqj6vlZh+cBv4AzAcyz7KU2Mw=
Loading

0 comments on commit 889cbbb

Please sign in to comment.