mirror of
https://github.com/wonli/aqi.git
synced 2025-10-26 02:10:36 +08:00
init
This commit is contained in:
33
utils/sensitive/sensitive_init.go
Normal file
33
utils/sensitive/sensitive_init.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package sensitive
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/importcjj/sensitive"
|
||||
)
|
||||
|
||||
var Entity *sensitive.Filter
|
||||
var sensitiveOnce sync.Once
|
||||
|
||||
func Init() {
|
||||
sensitiveOnce.Do(func() {
|
||||
Entity = sensitive.New()
|
||||
dd, err := Words.ReadDir("words")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range dd {
|
||||
data, err := Words.ReadFile("words/" + v.Name())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
Entity.AddWord(strings.Split(string(data), "\n")...)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Replace(msg string) string {
|
||||
return Entity.Replace(msg, '*')
|
||||
}
|
||||
Reference in New Issue
Block a user