mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-21 07:10: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"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"github.com/FloatTech/AnimeAPI/bilibili"
|
"github.com/FloatTech/AnimeAPI/bilibili"
|
||||||
"github.com/FloatTech/floatbox/file"
|
"github.com/FloatTech/floatbox/file"
|
||||||
@ -42,7 +44,11 @@ const (
|
|||||||
referer = "https://weibo.com/"
|
referer = "https://weibo.com/"
|
||||||
)
|
)
|
||||||
|
|
||||||
var boottime = time.Now()
|
var (
|
||||||
|
boottime = time.Now()
|
||||||
|
bgdata *[]byte
|
||||||
|
bgcount uintptr
|
||||||
|
)
|
||||||
|
|
||||||
func init() { // 插件主体
|
func init() { // 插件主体
|
||||||
engine := control.Register("aifalse", &ctrl.Options[*zero.Ctx]{
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
url, err := bilibili.GetRealURL(backgroundURL)
|
data := **(**[]byte)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&bgdata))))
|
||||||
if err != nil {
|
if data == nil || uintptr(time.Since(boottime).Hours())/24 <= atomic.LoadUintptr(&bgcount) {
|
||||||
return
|
url, err1 := bilibili.GetRealURL(backgroundURL)
|
||||||
|
if err1 != nil {
|
||||||
|
return nil, err1
|
||||||
}
|
}
|
||||||
data, err := web.RequestDataWith(web.NewDefaultClient(), url, "", referer, "", nil)
|
data, err1 = web.RequestDataWith(web.NewDefaultClient(), url, "", referer, "", nil)
|
||||||
if err != nil {
|
if err1 != nil {
|
||||||
return
|
return nil, err1
|
||||||
}
|
}
|
||||||
|
atomic.AddUintptr(&bgcount, 1)
|
||||||
|
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&bgdata)), unsafe.Pointer(&data))
|
||||||
|
}
|
||||||
|
|
||||||
back, _, err := image.Decode(bytes.NewReader(data))
|
back, _, err := image.Decode(bytes.NewReader(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user