diff --git a/data b/data index 485fc261..e8d06b15 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 485fc2618e37ee2a4065785cd068df9a90b7d014 +Subproject commit e8d06b150b2cf84d9c7dc2f8a9f573da2b2290fd diff --git a/plugin/thesaurus/chat.go b/plugin/thesaurus/chat.go index dca4bdc4..b124856c 100644 --- a/plugin/thesaurus/chat.go +++ b/plugin/thesaurus/chat.go @@ -2,9 +2,8 @@ package thesaurus import ( + "bytes" "encoding/json" - "io" - "io/fs" "math/rand" "strings" @@ -82,7 +81,7 @@ func init() { if err != nil { panic(err) } - seg, err := jieba.LoadDictionary(&mockfile{data: data}) + seg, err := jieba.LoadDictionary(bytes.NewReader(data)) if err != nil { panic(err) } @@ -120,13 +119,13 @@ func init() { } logrus.Infoln("[thesaurus]加载", len(chatListD), "条傲娇词库", len(chatListK), "条可爱词库") - engine.OnMessage(canmatch(tKIMO), match(chatList, seg, getmsg)). + engine.OnMessage(canmatch(tKIMO), match(chatList, seg)). SetBlock(false). Handle(randreply(kimomap)) - engine.OnMessage(canmatch(tDERE), match(chatListD, seg, getmsg)). + engine.OnMessage(canmatch(tDERE), match(chatListD, seg)). SetBlock(false). Handle(randreply(sm.D)) - engine.OnMessage(canmatch(tKAWA), match(chatListK, seg, getmsg)). + engine.OnMessage(canmatch(tKAWA), match(chatListK, seg)). SetBlock(false). Handle(randreply(sm.K)) }() @@ -139,42 +138,20 @@ type simai struct { K map[string][]string `yaml:"可爱"` } -type mockfile struct { - p uintptr - data []byte -} - -func (*mockfile) Stat() (fs.FileInfo, error) { - return nil, nil -} -func (f *mockfile) Read(buf []byte) (int, error) { - if int(f.p) >= len(f.data) { - return 0, io.EOF - } - n := copy(buf, f.data[f.p:]) - f.p += uintptr(n) - return n, nil -} -func (f *mockfile) Close() error { - if f.data == nil { - return fs.ErrClosed - } - f.data = nil - return nil -} - const ( tKIMO = iota tDERE tKAWA ) -func match(l []string, seg *jieba.Segmenter, getmsg func(*zero.Ctx) string) zero.Rule { +func match(l []string, seg *jieba.Segmenter) zero.Rule { return func(ctx *zero.Ctx) bool { if zero.FullMatchRule(l...)(ctx) { return true } - return ctxext.JiebaFullMatch(seg, getmsg, l...)(ctx) + return ctxext.JiebaFullMatch(seg, func(ctx *zero.Ctx) string { + return ctx.ExtractPlainText() + }, l...)(ctx) } } @@ -196,10 +173,6 @@ func canmatch(typ int64) zero.Rule { } } -func getmsg(ctx *zero.Ctx) string { - return ctx.MessageString() -} - func randreply(m map[string][]string) zero.Handler { return func(ctx *zero.Ctx) { key := ctx.State["matched"].(string)