上传铭感词系统
This commit is contained in:
parent
5cc19eae0d
commit
67f1d979e0
16878
bin/wordfilter.txt
Normal file
16878
bin/wordfilter.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
// 世界任务完成
|
||||
|
||||
func (this *apiComp) FinishCheck(session comm.IUserSession, req *pb.WorldtaskFinishReq) (errdata *pb.ErrorData) {
|
||||
if req.TaskId == 0 {
|
||||
this.module.Error("世界任务完成参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
|
||||
type Option func(*Options)
|
||||
type Options struct {
|
||||
WorldFile string //词组文件
|
||||
WorldFile []string //词组文件
|
||||
Debug bool //日志是否开启
|
||||
Log log.Ilogf
|
||||
}
|
||||
|
||||
func SetWorldFile(v string) Option {
|
||||
func SetWorldFile(v []string) Option {
|
||||
return func(o *Options) {
|
||||
o.WorldFile = v
|
||||
}
|
||||
|
@ -3,15 +3,16 @@ package wordfilter
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/lego/utils/codec/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
func newSys(options *Options) (sys *Sys, err error) {
|
||||
@ -20,8 +21,21 @@ func newSys(options *Options) (sys *Sys, err error) {
|
||||
trie: NewTrie(),
|
||||
noise: regexp.MustCompile(`[\|\s&%$@*]+`),
|
||||
}
|
||||
if options.WorldFile != "" {
|
||||
err = sys.Loadjson(options.WorldFile)
|
||||
if len(options.WorldFile) > 0 {
|
||||
for _, v := range options.WorldFile {
|
||||
ext := filepath.Ext(v)
|
||||
switch ext {
|
||||
case ".json":
|
||||
err = sys.Loadjson(v)
|
||||
case ".txt", ".text":
|
||||
err = sys.Loadtext(v)
|
||||
default:
|
||||
log.Warn("不支持的文件类型", log.Field{Key: "ext", Value: ext})
|
||||
continue
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -78,6 +92,18 @@ func (Sys *Sys) Load(rd io.Reader) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (Sys *Sys) Loadtext(fliepath string) (err error) {
|
||||
var (
|
||||
file *os.File
|
||||
)
|
||||
if file, err = os.Open(fliepath); err != nil {
|
||||
err = fmt.Errorf("no found file:%s", fliepath)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
return Sys.Load(file)
|
||||
}
|
||||
|
||||
func (Sys *Sys) Loadjson(fliepath string) (err error) {
|
||||
var (
|
||||
file *os.File
|
||||
@ -95,7 +121,7 @@ func (Sys *Sys) Loadjson(fliepath string) (err error) {
|
||||
return
|
||||
}
|
||||
word = &WordJson{}
|
||||
if err = jsoniter.Unmarshal(bytes, word); err != nil {
|
||||
if err = json.Unmarshal(bytes, word); err != nil {
|
||||
err = fmt.Errorf("read file:%s json.Unmarshal err:%v", fliepath, err)
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user