Skip to content

Commit 4303b8f

Browse files
authored
Update main.go
1 parent 5045f2f commit 4303b8f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

plugin/wordcount/main.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,30 @@ import (
1111
"sync"
1212
"time"
1313

14+
"github.com/go-ego/gse"
15+
"github.com/golang/freetype"
16+
"github.com/sirupsen/logrus"
17+
"github.com/tidwall/gjson"
18+
"github.com/wcharczuk/go-chart/v2"
19+
1420
"github.com/FloatTech/floatbox/binary"
1521
fcext "github.com/FloatTech/floatbox/ctxext"
1622
"github.com/FloatTech/floatbox/file"
1723
ctrl "github.com/FloatTech/zbpctrl"
1824
"github.com/FloatTech/zbputils/control"
1925
"github.com/FloatTech/zbputils/ctxext"
2026
"github.com/FloatTech/zbputils/img/text"
21-
"github.com/go-ego/gse"
22-
"github.com/golang/freetype"
23-
"github.com/sirupsen/logrus"
24-
"github.com/tidwall/gjson"
25-
"github.com/wcharczuk/go-chart/v2"
27+
2628
zero "github.com/wdvxdr1123/ZeroBot"
2729
"github.com/wdvxdr1123/ZeroBot/message"
30+
"github.com/wdvxdr1123/ZeroBot/utils/helper"
2831
)
2932

3033
var (
3134
re = regexp.MustCompile(`^[一-龥]+$`)
3235
stopwords []string
36+
seg gse.Segmenter
3337
)
34-
var seg gse.Segmenter
3538

3639
func init() {
3740
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
@@ -42,7 +45,10 @@ func init() {
4245
})
4346
cachePath := engine.DataFolder() + "cache/"
4447
// 读取gse内置中文词典
45-
_ = seg.LoadDictEmbed("zh_s")
48+
err := seg.LoadDictEmbed()
49+
if err != nil {
50+
panic(err)
51+
}
4652
_ = os.RemoveAll(cachePath)
4753
_ = os.MkdirAll(cachePath, 0755)
4854
engine.OnRegex(`^热词\s?(\d*)\s?(\d*)$`, zero.OnlyGroup, fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
@@ -124,7 +130,7 @@ func init() {
124130
if tex == "" {
125131
continue
126132
}
127-
segments := seg.Segment([]byte(tex))
133+
segments := seg.Segment(helper.StringToBytes(tex))
128134
words := gse.ToSlice(segments, true)
129135
for _, word := range words {
130136
word = strings.TrimSpace(word)

0 commit comments

Comments
 (0)