Skip to content

Commit

Permalink
✏️ 线程安全
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Aug 27, 2021
1 parent bf6714f commit 3a3c9e5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
2 changes: 1 addition & 1 deletion plugin_diana/data/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 39 additions & 24 deletions plugin_hs/run.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
// Package hs 炉石
package hs

import (
"fmt"
"os"
"strconv"
"strings"
"time"

"github.com/imroc/req"
"github.com/tidwall/gjson"
zero "github.com/wdvxdr1123/ZeroBot"
"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]
Expand All @@ -26,32 +35,38 @@ 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")
sg, _ := req.Post("https://pic.sogou.com/pic/upload_pic.jsp", req.FileUpload{
File: file,
FieldName: "image", // FieldName 是表单字段名
FileName: "avatar.png", // Filename 是要上传的文件的名称,我们使用它来猜测mimetype,并将其上传到服务器上
})
var tx string
t := int(gjson.Get(g, `list.#`).Int())
if t == 0 {
ctx.SendChain(message.Text("查询为空!"))
return
}
for i := 0; i < t && i < 10; i++ {
tx += strconv.Itoa(i+1) + ". 法力:" +
gjson.Get(g, `list.`+strconv.Itoa(i)+`.COST`).String() +
" " +
gjson.Get(g, `list.`+strconv.Itoa(i)+`.CARDNAME`).String() +
"\n"
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 是表单字段名
FileName: "avatar.png", // Filename 是要上传的文件的名称,我们使用它来猜测mimetype,并将其上传到服务器上
})
var tx string
t := int(gjson.Get(g, `list.#`).Int())
if t == 0 {
ctx.Send("查询为空!")
return
}
for i := 0; i < t && i < 10; i++ {
tx += strconv.Itoa(i+1) + ". 法力:" +
gjson.Get(g, `list.`+strconv.Itoa(i)+`.COST`).String() +
" " +
gjson.Get(g, `list.`+strconv.Itoa(i)+`.CARDNAME`).String() +
"\n"
}
ctx.SendChain(
message.Image(sg.String()),
message.Text(tx),
)
}
}
ctx.SendChain(
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("成功")
Expand Down
12 changes: 7 additions & 5 deletions plugin_setutime/setu_geter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ package setutime
import (
"fmt"
"io"
"log"
"net/http"
"os"
"strconv"
"strings"
"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 图片缓冲池
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down

0 comments on commit 3a3c9e5

Please sign in to comment.