diff --git a/go.mod b/go.mod index 1def269..1e6a39b 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/FloatTech/zbpctrl v1.6.0 github.com/FloatTech/zbputils v1.7.1-0.20231017135158-7e6c839764eb github.com/disintegration/imaging v1.6.2 - github.com/fumiama/NanoBot v0.0.0-20231117141225-3c2b37d5d79d + github.com/fumiama/NanoBot v0.0.0-20231122085036-99b256c0433b github.com/fumiama/go-base16384 v1.7.0 github.com/fumiama/go-registry v0.2.6 github.com/fumiama/unibase2n v0.0.0-20221020155353-02876e777430 @@ -32,6 +32,7 @@ require ( github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e // indirect github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 // indirect github.com/blend/go-sdk v1.20220411.3 // indirect + github.com/corona10/goimagehash v1.1.0 // indirect github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 // indirect github.com/fumiama/cron v1.3.0 // indirect github.com/fumiama/go-simple-protobuf v0.1.0 // indirect @@ -45,6 +46,7 @@ require ( github.com/kr/pretty v0.3.1 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/mattn/go-isatty v0.0.16 // indirect + github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect diff --git a/go.sum b/go.sum index 036ebff..8189131 100644 --- a/go.sum +++ b/go.sum @@ -24,6 +24,8 @@ github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5/go.mod h1:0Uc github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/blend/go-sdk v1.20220411.3 h1:GFV4/FQX5UzXLPwWV03gP811pj7B8J2sbuq+GJQofXc= github.com/blend/go-sdk v1.20220411.3/go.mod h1:7lnH8fTi6U4i1fArEXRyOIY2E1X4MALg09qsQqY1+ak= +github.com/corona10/goimagehash v1.1.0 h1:teNMX/1e+Wn/AYSbLHX8mj+mF9r60R1kBeqE9MkoYwI= +github.com/corona10/goimagehash v1.1.0/go.mod h1:VkvE0mLn84L4aF8vCb6mafVajEb6QYMHl2ZJLn0mOGI= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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 github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4/go.mod h1:H7chHJglrhPPzetLdzBleF8d22WYOv7UM/lEKYiwlKM= github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y= github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= -github.com/fumiama/NanoBot v0.0.0-20231117141225-3c2b37d5d79d h1:3ITP7RVzbQGkqvXl7YMm36JPbzEzTvzXpMLulAfyMF8= -github.com/fumiama/NanoBot v0.0.0-20231117141225-3c2b37d5d79d/go.mod h1:z9IDRRwntGIrnnxcwgjVge7lUa2GkGWFT7F1uYZbvh8= +github.com/fumiama/NanoBot v0.0.0-20231122085036-99b256c0433b h1:Xx/4GYSE2vx0dmiMC09lZJAhr40bwlX+CaAY3kwq65c= +github.com/fumiama/NanoBot v0.0.0-20231122085036-99b256c0433b/go.mod h1:z9IDRRwntGIrnnxcwgjVge7lUa2GkGWFT7F1uYZbvh8= github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b h1:Zt3pFQditAdWTHCOVkiloc9ZauBoWrb37guFV4iIRvE= github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= 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 github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA= github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= +github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= +github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= diff --git a/plugin/score/draw.go b/plugin/score/draw.go index 9b652db..30e8741 100644 --- a/plugin/score/draw.go +++ b/plugin/score/draw.go @@ -26,10 +26,11 @@ func floatstyle(a *scoredata) (img image.Image, err error) { return } - getAvatar, err := initPic(a.picfile, a.avatarurl) + picFile, getAvatar, err := initPic(a.avatarurl) if err != nil { return } + a.picfile = picFile back, err := gg.LoadImage(a.picfile) if err != nil { @@ -204,7 +205,7 @@ func customtext(a *scoredata, fontdata []byte, cw, ch, aw float64, textcolor col if a.rank < 10 { nextrankScore = rankArray[a.rank+1] } else { - nextrankScore = SCOREMAX + nextrankScore = scoreMax } nextLevelStyle := strconv.Itoa(a.level) + "/" + strconv.Itoa(nextrankScore) diff --git a/plugin/score/sign_in.go b/plugin/score/sign_in.go index d6493fb..bb711c7 100644 --- a/plugin/score/sign_in.go +++ b/plugin/score/sign_in.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/FloatTech/AnimeAPI/bilibili" + "github.com/FloatTech/AnimeAPI/setu" "github.com/FloatTech/AnimeAPI/wallet" "github.com/FloatTech/NanoBot-Plugin/utils/ctxext" "github.com/FloatTech/floatbox/file" @@ -23,11 +23,9 @@ import ( ) const ( - backgroundURL = "https://iw233.cn/api.php?sort=pc" - referer = "https://weibo.com/" - signinMax = 1 - // SCOREMAX 分数上限定为1200 - SCOREMAX = 1200 + signinMax = 1 + // scoreMax 分数上限定为1200 + scoreMax = 1200 ) var ( @@ -71,7 +69,6 @@ func init() { today := time.Now().Format("20060102") // 签到图片 drawedFile := cachePath + uid + today + "signin.png" - picFile := cachePath + uid + today + ".png" // 获取签到时间 si := sdb.GetSignInByUID(int64(uidint)) siUpdateTimeStr := si.UpdatedAt.Format("20060102") @@ -105,8 +102,8 @@ func init() { } // 更新经验 level := sdb.GetScoreByUID(int64(uidint)).Score + 1 - if level > SCOREMAX { - level = SCOREMAX + if level > scoreMax { + level = scoreMax _, err := ctx.SendPlainMessage(true, "你的等级已经达到上限") if err != nil { _, _ = ctx.SendPlainMessage(false, "ERROR: ", err) @@ -130,7 +127,6 @@ func init() { }() alldata := &scoredata{ drawedfile: drawedFile, - picfile: picFile, avatarurl: ctx.Message.Author.Avatar, inc: add, score: wallet.GetWalletOf(int64(uidint)), @@ -297,7 +293,7 @@ func getrank(count int) int { return -1 } -func initPic(picFile string, avatarurl string) (avatar []byte, err error) { +func initPic(avatarurl string) (pic string, avatar []byte, err error) { if avatarurl != "" { avatar, err = web.GetData(avatarurl) if err != nil { @@ -305,16 +301,6 @@ func initPic(picFile string, avatarurl string) (avatar []byte, err error) { } } defer process.SleepAbout1sTo2s() - if file.IsExist(picFile) { - return - } - url, err := bilibili.GetRealURL(backgroundURL) - if err != nil { - return - } - data, err := web.RequestDataWith(web.NewDefaultClient(), url, "", referer, "", nil) - if err != nil { - return - } - return avatar, os.WriteFile(picFile, data, 0644) + pic, err = setu.DefaultPool.Roll("") + return } diff --git a/plugin/status/main.go b/plugin/status/main.go index 0978dfe..3ef591d 100644 --- a/plugin/status/main.go +++ b/plugin/status/main.go @@ -7,6 +7,7 @@ import ( "image" "image/color" "math" + "os" "runtime" "strconv" "strings" @@ -25,7 +26,7 @@ import ( nano "github.com/fumiama/NanoBot" - "github.com/FloatTech/AnimeAPI/bilibili" + "github.com/FloatTech/AnimeAPI/setu" "github.com/FloatTech/floatbox/file" "github.com/FloatTech/floatbox/web" "github.com/FloatTech/gg" @@ -37,11 +38,6 @@ import ( "github.com/FloatTech/NanoBot-Plugin/kanban/banner" ) -const ( - backgroundURL = "https://iw233.cn/api.php?sort=mp" - referer = "https://weibo.com/" -) - var ( boottime = time.Now() bgdata *[]byte @@ -104,11 +100,11 @@ func drawstatus(m *ctrl.Control[*nano.Ctx], botavartarurl, botname string) (send dldata := (*[]byte)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&bgdata)))) if dldata == (*[]byte)(nil) || uintptr(time.Since(boottime).Hours()/24) >= atomic.LoadUintptr(&bgcount) { - url, err1 := bilibili.GetRealURL(backgroundURL) + pic, err1 := setu.DefaultPool.Roll("") if err1 != nil { return nil, err1 } - data, err1 := web.RequestDataWith(web.NewDefaultClient(), url, "", referer, "", nil) + data, err1 := os.ReadFile(pic) if err1 != nil { return nil, err1 }