mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
✏️ 线程安全
This commit is contained in:
parent
bf6714f231
commit
3a3c9e5018
@ -65,7 +65,7 @@ func LoadText() error {
|
||||
log.Printf("[Diana]从镜像下载小作文%d字节...", resp.ContentLength)
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err == nil && len(data) > 0 {
|
||||
f.Write(data)
|
||||
_, _ = f.Write(data)
|
||||
return compo.Unmarshal(data)
|
||||
}
|
||||
return err
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
// Package hs 炉石
|
||||
package hs
|
||||
|
||||
import (
|
||||
@ -5,6 +6,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/imroc/req"
|
||||
"github.com/tidwall/gjson"
|
||||
@ -12,12 +14,19 @@ import (
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
const cachedir = "data/hs/"
|
||||
|
||||
var header = req.Header{
|
||||
"user-agent": `Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Mobile Safari/537.36`,
|
||||
"referer": `https://hs.fbigame.com`,
|
||||
}
|
||||
|
||||
func init() {
|
||||
os.RemoveAll(cachedir)
|
||||
err := os.MkdirAll(cachedir, 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
zero.OnRegex(`^搜卡(.+)$`).
|
||||
SetBlock(true).SetPriority(20).Handle(func(ctx *zero.Ctx) {
|
||||
List := ctx.State["regex_matched"].([]string)[1]
|
||||
@ -26,8 +35,12 @@ func init() {
|
||||
gjson.Get(g, `list.0.CardID`).String()+
|
||||
`.png?auth_key=`+
|
||||
gjson.Get(g, `list.0.auth_key`).String(), header)
|
||||
im.ToFile("data/image/1.png")
|
||||
file, _ := os.Open("data/image/1.png")
|
||||
cachefile := cachedir + strconv.Itoa(int(time.Now().Unix()))
|
||||
err := im.ToFile(cachefile)
|
||||
if err == nil {
|
||||
file, err := os.Open(cachefile)
|
||||
if err == nil {
|
||||
defer file.Close()
|
||||
sg, _ := req.Post("https://pic.sogou.com/pic/upload_pic.jsp", req.FileUpload{
|
||||
File: file,
|
||||
FieldName: "image", // FieldName 是表单字段名
|
||||
@ -36,7 +49,7 @@ func init() {
|
||||
var tx string
|
||||
t := int(gjson.Get(g, `list.#`).Int())
|
||||
if t == 0 {
|
||||
ctx.SendChain(message.Text("查询为空!"))
|
||||
ctx.Send("查询为空!")
|
||||
return
|
||||
}
|
||||
for i := 0; i < t && i < 10; i++ {
|
||||
@ -50,8 +63,10 @@ func init() {
|
||||
message.Image(sg.String()),
|
||||
message.Text(tx),
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
//卡组
|
||||
// 卡组
|
||||
zero.OnRegex(`^[\s\S]*?(AAE[a-zA-Z0-9/\+=]{70,})[\s\S]*$`).
|
||||
SetBlock(true).SetPriority(20).Handle(func(ctx *zero.Ctx) {
|
||||
fmt.Print("成功")
|
||||
|
||||
@ -4,7 +4,6 @@ package setutime
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
@ -12,11 +11,11 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/pixiv"
|
||||
"github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/pixiv"
|
||||
)
|
||||
|
||||
// Pools 图片缓冲池
|
||||
@ -58,10 +57,13 @@ func newPools() *imgpool {
|
||||
if err == nil {
|
||||
defer resp.Body.Close()
|
||||
if resp.ContentLength > 0 {
|
||||
log.Printf("[Setu]从镜像下载数据库%d字节...", resp.ContentLength)
|
||||
logrus.Printf("[Setu]从镜像下载数据库%d字节...", resp.ContentLength)
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err == nil && len(data) > 0 {
|
||||
f.Write(data)
|
||||
_, err = f.Write(data)
|
||||
if err != nil {
|
||||
logrus.Errorf("[Setu]写入数据库失败: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user