()
| 35 | ) |
| 36 | |
| 37 | func init() { |
| 38 | engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{ |
| 39 | DisableOnDefault: false, |
| 40 | Brief: "聊天热词", |
| 41 | Help: "- 热词 [消息数目]|热词 1000", |
| 42 | PublicDataFolder: "WordCount", |
| 43 | }) |
| 44 | cachePath := engine.DataFolder() + "cache/" |
| 45 | dat, err := file.GetLazyData("data/Chat/dict.txt", control.Md5File, true) |
| 46 | if err != nil { |
| 47 | panic(err) |
| 48 | } |
| 49 | seg, err := jieba.LoadDictionary(bytes.NewReader(dat)) |
| 50 | if err != nil { |
| 51 | panic(err) |
| 52 | } |
| 53 | _ = os.RemoveAll(cachePath) |
| 54 | _ = os.MkdirAll(cachePath, 0755) |
| 55 | engine.OnRegex(`^热词\s?(\d*)$`, zero.OnlyGroup, fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool { |
| 56 | _, err := engine.GetLazyData("stopwords.txt", false) |
| 57 | if err != nil { |
| 58 | ctx.SendChain(message.Text("ERROR: ", err)) |
| 59 | return false |
| 60 | } |
| 61 | data, err := os.ReadFile(engine.DataFolder() + "stopwords.txt") |
| 62 | if err != nil { |
| 63 | ctx.SendChain(message.Text("ERROR: ", err)) |
| 64 | return false |
| 65 | } |
| 66 | stopwords = strings.Split(strings.ReplaceAll(binary.BytesToString(data), "\r", ""), "\n") |
| 67 | sort.Strings(stopwords) |
| 68 | logrus.Infoln("[wordcount]加载", len(stopwords), "条停用词") |
| 69 | return true |
| 70 | })).Limit(ctxext.LimitByUser).SetBlock(true). |
| 71 | Handle(func(ctx *zero.Ctx) { |
| 72 | _, err := file.GetLazyData(text.FontFile, control.Md5File, true) |
| 73 | if err != nil { |
| 74 | ctx.SendChain(message.Text("ERROR: ", err)) |
| 75 | return |
| 76 | } |
| 77 | b, err := os.ReadFile(text.FontFile) |
| 78 | if err != nil { |
| 79 | ctx.SendChain(message.Text("ERROR: ", err)) |
| 80 | return |
| 81 | } |
| 82 | font, err := freetype.ParseFont(b) |
| 83 | if err != nil { |
| 84 | ctx.SendChain(message.Text("ERROR: ", err)) |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | ctx.SendChain(message.Text("少女祈祷中...")) |
| 89 | p, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64) |
| 90 | if p > 10000 { |
| 91 | p = 10000 |
| 92 | } |
| 93 | if p == 0 { |
| 94 | p = 1000 |
nothing calls this directly
no test coverage detected