上传铭感词系统
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) {
|
func (this *apiComp) FinishCheck(session comm.IUserSession, req *pb.WorldtaskFinishReq) (errdata *pb.ErrorData) {
|
||||||
if req.TaskId == 0 {
|
if req.TaskId == 0 {
|
||||||
this.module.Error("世界任务完成参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
|
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 Option func(*Options)
|
||||||
type Options struct {
|
type Options struct {
|
||||||
WorldFile string //词组文件
|
WorldFile []string //词组文件
|
||||||
Debug bool //日志是否开启
|
Debug bool //日志是否开启
|
||||||
Log log.Ilogf
|
Log log.Ilogf
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetWorldFile(v string) Option {
|
func SetWorldFile(v []string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.WorldFile = v
|
o.WorldFile = v
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,16 @@ package wordfilter
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"go_dreamfactory/lego/utils/codec/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func newSys(options *Options) (sys *Sys, err error) {
|
func newSys(options *Options) (sys *Sys, err error) {
|
||||||
@ -20,8 +21,21 @@ func newSys(options *Options) (sys *Sys, err error) {
|
|||||||
trie: NewTrie(),
|
trie: NewTrie(),
|
||||||
noise: regexp.MustCompile(`[\|\s&%$@*]+`),
|
noise: regexp.MustCompile(`[\|\s&%$@*]+`),
|
||||||
}
|
}
|
||||||
if options.WorldFile != "" {
|
if len(options.WorldFile) > 0 {
|
||||||
err = sys.Loadjson(options.WorldFile)
|
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
|
return
|
||||||
}
|
}
|
||||||
@ -78,6 +92,18 @@ func (Sys *Sys) Load(rd io.Reader) error {
|
|||||||
return nil
|
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) {
|
func (Sys *Sys) Loadjson(fliepath string) (err error) {
|
||||||
var (
|
var (
|
||||||
file *os.File
|
file *os.File
|
||||||
@ -95,7 +121,7 @@ func (Sys *Sys) Loadjson(fliepath string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
word = &WordJson{}
|
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)
|
err = fmt.Errorf("read file:%s json.Unmarshal err:%v", fliepath, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user