Skip to content

Commit f2ed01f

Browse files
committed
✨ use pool instead of iw233
1 parent 2130ac1 commit f2ed01f

5 files changed

Lines changed: 25 additions & 36 deletions

File tree

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/FloatTech/zbpctrl v1.6.0
1313
github.com/FloatTech/zbputils v1.7.1-0.20231017135158-7e6c839764eb
1414
github.com/disintegration/imaging v1.6.2
15-
github.com/fumiama/NanoBot v0.0.0-20231117141225-3c2b37d5d79d
15+
github.com/fumiama/NanoBot v0.0.0-20231122085036-99b256c0433b
1616
github.com/fumiama/go-base16384 v1.7.0
1717
github.com/fumiama/go-registry v0.2.6
1818
github.com/fumiama/unibase2n v0.0.0-20221020155353-02876e777430
@@ -32,6 +32,7 @@ require (
3232
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e // indirect
3333
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 // indirect
3434
github.com/blend/go-sdk v1.20220411.3 // indirect
35+
github.com/corona10/goimagehash v1.1.0 // indirect
3536
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 // indirect
3637
github.com/fumiama/cron v1.3.0 // indirect
3738
github.com/fumiama/go-simple-protobuf v0.1.0 // indirect
@@ -45,6 +46,7 @@ require (
4546
github.com/kr/pretty v0.3.1 // indirect
4647
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
4748
github.com/mattn/go-isatty v0.0.16 // indirect
49+
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
4850
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
4951
github.com/pkg/errors v0.9.1 // indirect
5052
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5/go.mod h1:0Uc
2424
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
2525
github.com/blend/go-sdk v1.20220411.3 h1:GFV4/FQX5UzXLPwWV03gP811pj7B8J2sbuq+GJQofXc=
2626
github.com/blend/go-sdk v1.20220411.3/go.mod h1:7lnH8fTi6U4i1fArEXRyOIY2E1X4MALg09qsQqY1+ak=
27+
github.com/corona10/goimagehash v1.1.0 h1:teNMX/1e+Wn/AYSbLHX8mj+mF9r60R1kBeqE9MkoYwI=
28+
github.com/corona10/goimagehash v1.1.0/go.mod h1:VkvE0mLn84L4aF8vCb6mafVajEb6QYMHl2ZJLn0mOGI=
2729
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
2830
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2931
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -36,8 +38,8 @@ github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 h1:BBade+Jl
3638
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4/go.mod h1:H7chHJglrhPPzetLdzBleF8d22WYOv7UM/lEKYiwlKM=
3739
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
3840
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
39-
github.com/fumiama/NanoBot v0.0.0-20231117141225-3c2b37d5d79d h1:3ITP7RVzbQGkqvXl7YMm36JPbzEzTvzXpMLulAfyMF8=
40-
github.com/fumiama/NanoBot v0.0.0-20231117141225-3c2b37d5d79d/go.mod h1:z9IDRRwntGIrnnxcwgjVge7lUa2GkGWFT7F1uYZbvh8=
41+
github.com/fumiama/NanoBot v0.0.0-20231122085036-99b256c0433b h1:Xx/4GYSE2vx0dmiMC09lZJAhr40bwlX+CaAY3kwq65c=
42+
github.com/fumiama/NanoBot v0.0.0-20231122085036-99b256c0433b/go.mod h1:z9IDRRwntGIrnnxcwgjVge7lUa2GkGWFT7F1uYZbvh8=
4143
github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b h1:Zt3pFQditAdWTHCOVkiloc9ZauBoWrb37guFV4iIRvE=
4244
github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
4345
github.com/fumiama/cron v1.3.0 h1:ZWlwuexF+HQHl3cYytEE5HNwD99q+3vNZF1GrEiXCFo=
@@ -94,6 +96,8 @@ github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peK
9496
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
9597
github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA=
9698
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
99+
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
100+
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
97101
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
98102
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
99103
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=

plugin/score/draw.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ func floatstyle(a *scoredata) (img image.Image, err error) {
2626
return
2727
}
2828

29-
getAvatar, err := initPic(a.picfile, a.avatarurl)
29+
picFile, getAvatar, err := initPic(a.avatarurl)
3030
if err != nil {
3131
return
3232
}
33+
a.picfile = picFile
3334

3435
back, err := gg.LoadImage(a.picfile)
3536
if err != nil {
@@ -204,7 +205,7 @@ func customtext(a *scoredata, fontdata []byte, cw, ch, aw float64, textcolor col
204205
if a.rank < 10 {
205206
nextrankScore = rankArray[a.rank+1]
206207
} else {
207-
nextrankScore = SCOREMAX
208+
nextrankScore = scoreMax
208209
}
209210
nextLevelStyle := strconv.Itoa(a.level) + "/" + strconv.Itoa(nextrankScore)
210211

plugin/score/sign_in.go

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/FloatTech/AnimeAPI/bilibili"
11+
"github.com/FloatTech/AnimeAPI/setu"
1212
"github.com/FloatTech/AnimeAPI/wallet"
1313
"github.com/FloatTech/NanoBot-Plugin/utils/ctxext"
1414
"github.com/FloatTech/floatbox/file"
@@ -23,11 +23,9 @@ import (
2323
)
2424

2525
const (
26-
backgroundURL = "https://iw233.cn/api.php?sort=pc"
27-
referer = "https://weibo.com/"
28-
signinMax = 1
29-
// SCOREMAX 分数上限定为1200
30-
SCOREMAX = 1200
26+
signinMax = 1
27+
// scoreMax 分数上限定为1200
28+
scoreMax = 1200
3129
)
3230

3331
var (
@@ -71,7 +69,6 @@ func init() {
7169
today := time.Now().Format("20060102")
7270
// 签到图片
7371
drawedFile := cachePath + uid + today + "signin.png"
74-
picFile := cachePath + uid + today + ".png"
7572
// 获取签到时间
7673
si := sdb.GetSignInByUID(int64(uidint))
7774
siUpdateTimeStr := si.UpdatedAt.Format("20060102")
@@ -105,8 +102,8 @@ func init() {
105102
}
106103
// 更新经验
107104
level := sdb.GetScoreByUID(int64(uidint)).Score + 1
108-
if level > SCOREMAX {
109-
level = SCOREMAX
105+
if level > scoreMax {
106+
level = scoreMax
110107
_, err := ctx.SendPlainMessage(true, "你的等级已经达到上限")
111108
if err != nil {
112109
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
@@ -130,7 +127,6 @@ func init() {
130127
}()
131128
alldata := &scoredata{
132129
drawedfile: drawedFile,
133-
picfile: picFile,
134130
avatarurl: ctx.Message.Author.Avatar,
135131
inc: add,
136132
score: wallet.GetWalletOf(int64(uidint)),
@@ -297,24 +293,14 @@ func getrank(count int) int {
297293
return -1
298294
}
299295

300-
func initPic(picFile string, avatarurl string) (avatar []byte, err error) {
296+
func initPic(avatarurl string) (pic string, avatar []byte, err error) {
301297
if avatarurl != "" {
302298
avatar, err = web.GetData(avatarurl)
303299
if err != nil {
304300
return
305301
}
306302
}
307303
defer process.SleepAbout1sTo2s()
308-
if file.IsExist(picFile) {
309-
return
310-
}
311-
url, err := bilibili.GetRealURL(backgroundURL)
312-
if err != nil {
313-
return
314-
}
315-
data, err := web.RequestDataWith(web.NewDefaultClient(), url, "", referer, "", nil)
316-
if err != nil {
317-
return
318-
}
319-
return avatar, os.WriteFile(picFile, data, 0644)
304+
pic, err = setu.DefaultPool.Roll("")
305+
return
320306
}

plugin/status/main.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"image"
88
"image/color"
99
"math"
10+
"os"
1011
"runtime"
1112
"strconv"
1213
"strings"
@@ -25,7 +26,7 @@ import (
2526

2627
nano "github.com/fumiama/NanoBot"
2728

28-
"github.com/FloatTech/AnimeAPI/bilibili"
29+
"github.com/FloatTech/AnimeAPI/setu"
2930
"github.com/FloatTech/floatbox/file"
3031
"github.com/FloatTech/floatbox/web"
3132
"github.com/FloatTech/gg"
@@ -37,11 +38,6 @@ import (
3738
"github.com/FloatTech/NanoBot-Plugin/kanban/banner"
3839
)
3940

40-
const (
41-
backgroundURL = "https://iw233.cn/api.php?sort=mp"
42-
referer = "https://weibo.com/"
43-
)
44-
4541
var (
4642
boottime = time.Now()
4743
bgdata *[]byte
@@ -104,11 +100,11 @@ func drawstatus(m *ctrl.Control[*nano.Ctx], botavartarurl, botname string) (send
104100

105101
dldata := (*[]byte)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&bgdata))))
106102
if dldata == (*[]byte)(nil) || uintptr(time.Since(boottime).Hours()/24) >= atomic.LoadUintptr(&bgcount) {
107-
url, err1 := bilibili.GetRealURL(backgroundURL)
103+
pic, err1 := setu.DefaultPool.Roll("")
108104
if err1 != nil {
109105
return nil, err1
110106
}
111-
data, err1 := web.RequestDataWith(web.NewDefaultClient(), url, "", referer, "", nil)
107+
data, err1 := os.ReadFile(pic)
112108
if err1 != nil {
113109
return nil, err1
114110
}

0 commit comments

Comments
 (0)