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)
|
log.Printf("[Diana]从镜像下载小作文%d字节...", resp.ContentLength)
|
||||||
data, err := io.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err == nil && len(data) > 0 {
|
if err == nil && len(data) > 0 {
|
||||||
f.Write(data)
|
_, _ = f.Write(data)
|
||||||
return compo.Unmarshal(data)
|
return compo.Unmarshal(data)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// Package hs 炉石
|
||||||
package hs
|
package hs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -5,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/imroc/req"
|
"github.com/imroc/req"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
@ -12,12 +14,19 @@ import (
|
|||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const cachedir = "data/hs/"
|
||||||
|
|
||||||
var header = req.Header{
|
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`,
|
"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`,
|
"referer": `https://hs.fbigame.com`,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
os.RemoveAll(cachedir)
|
||||||
|
err := os.MkdirAll(cachedir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
zero.OnRegex(`^搜卡(.+)$`).
|
zero.OnRegex(`^搜卡(.+)$`).
|
||||||
SetBlock(true).SetPriority(20).Handle(func(ctx *zero.Ctx) {
|
SetBlock(true).SetPriority(20).Handle(func(ctx *zero.Ctx) {
|
||||||
List := ctx.State["regex_matched"].([]string)[1]
|
List := ctx.State["regex_matched"].([]string)[1]
|
||||||
@ -26,8 +35,12 @@ func init() {
|
|||||||
gjson.Get(g, `list.0.CardID`).String()+
|
gjson.Get(g, `list.0.CardID`).String()+
|
||||||
`.png?auth_key=`+
|
`.png?auth_key=`+
|
||||||
gjson.Get(g, `list.0.auth_key`).String(), header)
|
gjson.Get(g, `list.0.auth_key`).String(), header)
|
||||||
im.ToFile("data/image/1.png")
|
cachefile := cachedir + strconv.Itoa(int(time.Now().Unix()))
|
||||||
file, _ := os.Open("data/image/1.png")
|
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{
|
sg, _ := req.Post("https://pic.sogou.com/pic/upload_pic.jsp", req.FileUpload{
|
||||||
File: file,
|
File: file,
|
||||||
FieldName: "image", // FieldName 是表单字段名
|
FieldName: "image", // FieldName 是表单字段名
|
||||||
@ -36,7 +49,7 @@ func init() {
|
|||||||
var tx string
|
var tx string
|
||||||
t := int(gjson.Get(g, `list.#`).Int())
|
t := int(gjson.Get(g, `list.#`).Int())
|
||||||
if t == 0 {
|
if t == 0 {
|
||||||
ctx.SendChain(message.Text("查询为空!"))
|
ctx.Send("查询为空!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i := 0; i < t && i < 10; i++ {
|
for i := 0; i < t && i < 10; i++ {
|
||||||
@ -50,6 +63,8 @@ func init() {
|
|||||||
message.Image(sg.String()),
|
message.Image(sg.String()),
|
||||||
message.Text(tx),
|
message.Text(tx),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// 卡组
|
// 卡组
|
||||||
zero.OnRegex(`^[\s\S]*?(AAE[a-zA-Z0-9/\+=]{70,})[\s\S]*$`).
|
zero.OnRegex(`^[\s\S]*?(AAE[a-zA-Z0-9/\+=]{70,})[\s\S]*$`).
|
||||||
|
|||||||
@ -4,7 +4,6 @@ package setutime
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -12,11 +11,11 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/FloatTech/AnimeAPI/pixiv"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
"github.com/FloatTech/AnimeAPI/pixiv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Pools 图片缓冲池
|
// Pools 图片缓冲池
|
||||||
@ -58,10 +57,13 @@ func newPools() *imgpool {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.ContentLength > 0 {
|
if resp.ContentLength > 0 {
|
||||||
log.Printf("[Setu]从镜像下载数据库%d字节...", resp.ContentLength)
|
logrus.Printf("[Setu]从镜像下载数据库%d字节...", resp.ContentLength)
|
||||||
data, err := io.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err == nil && len(data) > 0 {
|
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