mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
fix: slow 自检
This commit is contained in:
parent
f82ba852ba
commit
6a0a16662e
2
data
2
data
@ -1 +1 @@
|
||||
Subproject commit 5e0fa81c3b0b989b27cf73cac76091d530d3d2fd
|
||||
Subproject commit e4004f113a06e5e82fdcd3676807d1314ae17f97
|
||||
@ -10,7 +10,9 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/bilibili"
|
||||
"github.com/FloatTech/floatbox/file"
|
||||
@ -42,7 +44,11 @@ const (
|
||||
referer = "https://weibo.com/"
|
||||
)
|
||||
|
||||
var boottime = time.Now()
|
||||
var (
|
||||
boottime = time.Now()
|
||||
bgdata *[]byte
|
||||
bgcount uintptr
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("aifalse", &ctrl.Options[*zero.Ctx]{
|
||||
@ -134,14 +140,20 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
return
|
||||
}
|
||||
|
||||
url, err := bilibili.GetRealURL(backgroundURL)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
data, err := web.RequestDataWith(web.NewDefaultClient(), url, "", referer, "", nil)
|
||||
if err != nil {
|
||||
return
|
||||
data := **(**[]byte)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&bgdata))))
|
||||
if data == nil || uintptr(time.Since(boottime).Hours())/24 <= atomic.LoadUintptr(&bgcount) {
|
||||
url, err1 := bilibili.GetRealURL(backgroundURL)
|
||||
if err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
data, err1 = web.RequestDataWith(web.NewDefaultClient(), url, "", referer, "", nil)
|
||||
if err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
atomic.AddUintptr(&bgcount, 1)
|
||||
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&bgdata)), unsafe.Pointer(&data))
|
||||
}
|
||||
|
||||
back, _, err := image.Decode(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
Loading…
Reference in New Issue
Block a user