加速word count

This commit is contained in:
源文雨 2022-04-28 23:15:27 +08:00
parent 0e8bef0541
commit 136e6bddf4
10 changed files with 65 additions and 63 deletions

8
go.mod
View File

@ -3,9 +3,9 @@ module github.com/FloatTech/ZeroBot-Plugin
go 1.18
require (
github.com/FloatTech/AnimeAPI v1.3.4-0.20220428141807-b64a0be87863
github.com/FloatTech/AnimeAPI v1.3.4-0.20220428145645-93a688024a47
github.com/FloatTech/sqlite v0.2.1
github.com/FloatTech/zbputils v1.3.4-0.20220428141409-0e05f9db1a14
github.com/FloatTech/zbputils v1.3.4-0.20220428145324-45613dd2fd32
github.com/antchfx/htmlquery v1.2.4
github.com/corona10/goimagehash v1.0.3
github.com/fogleman/gg v1.3.0
@ -21,9 +21,9 @@ require (
github.com/pkumza/numcn v1.0.0
github.com/shirou/gopsutil/v3 v3.22.3
github.com/sirupsen/logrus v1.8.1
github.com/tidwall/gjson v1.14.0
github.com/tidwall/gjson v1.14.1
github.com/wcharczuk/go-chart/v2 v2.1.0
github.com/wdvxdr1123/ZeroBot v1.5.1-mid
github.com/wdvxdr1123/ZeroBot v1.5.2-0.20220428145048-a63af3145952
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9
)

18
go.sum
View File

@ -1,9 +1,9 @@
github.com/FloatTech/AnimeAPI v1.3.4-0.20220428141807-b64a0be87863 h1:Iff5BubgIQRDKZLLfml/2xOwQclvCd9AvfJdWnFRcpY=
github.com/FloatTech/AnimeAPI v1.3.4-0.20220428141807-b64a0be87863/go.mod h1:JFlDzq+4lrg0AAhw0CJIpF5gvQjDhKriYdkUmVh1hfU=
github.com/FloatTech/AnimeAPI v1.3.4-0.20220428145645-93a688024a47 h1:/91ayCAwvhyJw9iQ4so9QDfJcu1GMPFJNTq1JjePkcY=
github.com/FloatTech/AnimeAPI v1.3.4-0.20220428145645-93a688024a47/go.mod h1:K10BsQlE9FJtDRfcjvH2XNX/JFejWfL3oTdMjHvEHr4=
github.com/FloatTech/sqlite v0.2.1 h1:9t6Me48XJJCIoPy4nLRvcdhcVKfT0c2lilp7SEKROG8=
github.com/FloatTech/sqlite v0.2.1/go.mod h1:6NfHRzqOo9RWeMJEoAQVuo51Omd5LFNxCNQhMF02/9U=
github.com/FloatTech/zbputils v1.3.4-0.20220428141409-0e05f9db1a14 h1:cYWXNDANXTC9gjvmP0yJoBWQ0tWRaW77Yg0WYCywX3o=
github.com/FloatTech/zbputils v1.3.4-0.20220428141409-0e05f9db1a14/go.mod h1:iBbE5rzR2ikZ6CorEqpol1ZtFh1i1zVEnwqU9pRx6H0=
github.com/FloatTech/zbputils v1.3.4-0.20220428145324-45613dd2fd32 h1:YUNRju20/AJ9JpKyHyX6N30q5A7AbHh45GdkSq37PKI=
github.com/FloatTech/zbputils v1.3.4-0.20220428145324-45613dd2fd32/go.mod h1:k2z5ZECUlLIstq/FP8uN2Mol8zH0P4NOnB2AqOBtJrI=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c h1:cNPOdTNiVwxLpROLjXCgbIPvdkE+BwvxDvgmdYmWx6Q=
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c/go.mod h1:KqZzu7slNKROh3TSYEH/IUMG6f4M+1qubZ5e52QypsE=
@ -95,8 +95,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/gjson v1.14.0 h1:6aeJ0bzojgWLa82gDQHcx3S0Lr/O51I9bJ5nv6JFx5w=
github.com/tidwall/gjson v1.14.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
@ -107,8 +107,8 @@ github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//
github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
github.com/wcharczuk/go-chart/v2 v2.1.0 h1:tY2slqVQ6bN+yHSnDYwZebLQFkphK4WNrVwnt7CJZ2I=
github.com/wcharczuk/go-chart/v2 v2.1.0/go.mod h1:yx7MvAVNcP/kN9lKXM/NTce4au4DFN99j6i1OwDclNA=
github.com/wdvxdr1123/ZeroBot v1.5.1-mid h1:MmdkgV7pOCbBq2gV7muX99mLyZ32khejsMntPdhD6z4=
github.com/wdvxdr1123/ZeroBot v1.5.1-mid/go.mod h1:K2vu0mslV8s4qhIAu/a03Z7YW24qjM0j3imIR+k21KI=
github.com/wdvxdr1123/ZeroBot v1.5.2-0.20220428145048-a63af3145952 h1:akKAfBlunZ6S8zqhBmNcRl1l6t7cs6I1pkC2lziQZ5A=
github.com/wdvxdr1123/ZeroBot v1.5.2-0.20220428145048-a63af3145952/go.mod h1:LJ+VOf523i3IrykuLK53UEeWqnAclRL5d2wGT4sS4Zk=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
@ -164,8 +164,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
modernc.org/cc/v3 v3.33.6/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
modernc.org/cc/v3 v3.33.9/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=

View File

@ -3,7 +3,6 @@ package bilibili
import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
@ -166,7 +165,6 @@ func medalwall(uid string) (result []medal, err error) {
if err != nil {
return
}
fmt.Println("medalwall:", binary.BytesToString(data))
j := gjson.ParseBytes(data)
if j.Get("code").Int() == -101 {
err = errNeedCookie

View File

@ -2,7 +2,6 @@
package bilibiliparse
import (
"fmt"
"regexp"
"strings"
@ -51,9 +50,7 @@ func parseURL(bilibiliURL string) (m message.Message, err error) {
title := htmlquery.FindOne(doc, "//*[@id='viewbox_report']/h1/span/text()").Data
m = append(m, message.Text(title+"\n"))
upName := strings.TrimSpace(htmlquery.FindOne(doc, "//*[@id='v_upinfo']/div[2]/div[1]/a[1]/text()").Data)
fmt.Println(upName)
fanNumber := htmlquery.InnerText(htmlquery.FindOne(doc, "//i[@class='van-icon-general_addto_s']").NextSibling.NextSibling)
fmt.Println(fanNumber)
m = append(m, message.Text("up"+upName+",粉丝:"+fanNumber+"\n"))
view := htmlquery.FindOne(doc, "//*[@id='viewbox_report']/div/span[@class='view']/text()").Data
dm := htmlquery.FindOne(doc, "//*[@id='viewbox_report']/div/span[@class='dm']/text()").Data

View File

@ -205,12 +205,10 @@ func init() {
gid = -ctx.Event.UserID
}
bpl := bdb.getAllPushByGroup(gid)
fmt.Println(bpl)
msg := "--------b站推送列表--------"
for _, v := range bpl {
if _, ok := upMap[v.BilibiliUID]; !ok {
bdb.updateAllUp()
fmt.Println(upMap)
}
msg += fmt.Sprintf("\nuid:%-12d 动态:", v.BilibiliUID)
if v.DynamicDisable == 0 {

View File

@ -2,7 +2,6 @@
package hs
import (
"fmt"
"os"
"strconv"
"strings"
@ -87,7 +86,6 @@ func init() {
// 卡组
engine.OnRegex(`^[\s\S]*?(AAE[a-zA-Z0-9/\+=]{70,})[\s\S]*$`).
SetBlock(true).Handle(func(ctx *zero.Ctx) {
fmt.Print("成功")
List := ctx.State["regex_matched"].([]string)[1]
ctx.SendChain(
message.Image(kz(List)),

View File

@ -349,11 +349,7 @@ func init() { // 插件主体
engine.OnFullMatchGroup([]string{"翻牌"}, zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
// 无缓存获取群员列表
list := ctx.CallAction("get_group_member_list", zero.Params{
"group_id": ctx.Event.GroupID,
"no_cache": true,
}).Data
temp := list.Array()
temp := ctx.GetThisGroupMemberListNoCache().Array()
sort.SliceStable(temp, func(i, j int) bool {
return temp[i].Get("last_sent_time").Int() < temp[j].Get("last_sent_time").Int()
})

View File

@ -88,7 +88,6 @@ func init() { // 插件主体
// 开始搜索图片
ctx.SendChain(message.Text("少女祈祷中......"))
for _, pic := range ctx.State["image_url"].([]string) {
fmt.Println(pic)
if result, err := saucenao.SauceNAO(pic); err != nil {
ctx.SendChain(message.Text("ERROR:", err))
} else {

View File

@ -2,8 +2,6 @@
package tracemoe
import (
"fmt"
control "github.com/FloatTech/zbputils/control"
trmoe "github.com/fumiama/gotracemoe"
zero "github.com/wdvxdr1123/ZeroBot"
@ -25,7 +23,6 @@ func init() { // 插件主体
// 开始搜索图片
ctx.SendChain(message.Text("少女祈祷中......"))
for _, pic := range ctx.State["image_url"].([]string) {
fmt.Println(pic)
if result, err := moe.Search(pic, true, true); err != nil {
ctx.SendChain(message.Text("ERROR:", err))
} else if len(result.Result) > 0 {

View File

@ -8,6 +8,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"time"
"github.com/FloatTech/zbputils/binary"
@ -17,6 +18,7 @@ import (
"github.com/FloatTech/zbputils/img/text"
"github.com/golang/freetype"
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/wcharczuk/go-chart/v2"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
@ -54,6 +56,22 @@ func init() {
return true
})).Limit(ctxext.LimitByUser).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
_, err := file.GetLazyData(text.FontFile, false, true)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
b, err := os.ReadFile(text.FontFile)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
font, err := freetype.ParseFont(b)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
ctx.SendChain(message.Text("少女祈祷中..."))
gid, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
p, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
@ -77,28 +95,44 @@ func init() {
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
return
}
messageMap := make(map[string]int)
h := ctx.CallAction("get_group_msg_history", zero.Params{"group_id": gid}).Data
messageMap := make(map[string]int, 256)
h := ctx.GetLatestGroupMessageHistory(gid)
messageSeq := h.Get("messages.0.message_seq").Int()
for i := 0; i < int(p/20) && messageSeq != 0; i++ {
if i != 0 {
h = ctx.CallAction("get_group_msg_history", zero.Params{"group_id": gid, "message_seq": messageSeq}).Data
msghists := make(chan *gjson.Result, 64)
msghists <- &h
go func() {
for i := 1; i < int(p/20) && messageSeq != 0; i++ {
h := ctx.GetGroupMessageHistory(gid, messageSeq)
msghists <- &h
messageSeq = h.Get("messages.0.message_seq").Int()
}
for _, v := range h.Get("messages.#.message").Array() {
tex := strings.TrimSpace(message.ParseMessageFromString(v.Str).ExtractPlainText())
if tex == "" {
continue
}
for _, t := range ctx.GetWordSlices(tex).Get("slices").Array() {
tex := strings.TrimSpace(t.Str)
i := sort.SearchStrings(stopwords, tex)
if re.MatchString(tex) && (i >= len(stopwords) || stopwords[i] != tex) {
messageMap[tex]++
close(msghists)
}()
var wg sync.WaitGroup
var mapmu sync.Mutex
for h := range msghists {
wg.Add(1)
go func(h *gjson.Result) {
for _, v := range h.Get("messages.#.message").Array() {
tex := strings.TrimSpace(message.ParseMessageFromString(v.Str).ExtractPlainText())
if tex == "" {
continue
}
for _, t := range ctx.GetWordSlices(tex).Get("slices").Array() {
tex := strings.TrimSpace(t.Str)
i := sort.SearchStrings(stopwords, tex)
if re.MatchString(tex) && (i >= len(stopwords) || stopwords[i] != tex) {
mapmu.Lock()
messageMap[tex]++
mapmu.Unlock()
}
}
}
}
messageSeq = h.Get("messages.0.message_seq").Int()
wg.Done()
}(h)
}
wg.Wait()
wc := rankByWordCount(messageMap)
if len(wc) > 20 {
wc = wc[:20]
@ -108,21 +142,6 @@ func init() {
ctx.SendChain(message.Text("ERROR:历史消息为空或者无法获得历史消息"))
return
}
_, err := file.GetLazyData(text.FontFile, false, true)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
b, err := os.ReadFile(text.FontFile)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
font, err := freetype.ParseFont(b)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
bars := make([]chart.Value, len(wc))
for i, v := range wc {
bars[i] = chart.Value{