Skip to content

Commit

Permalink
new servicepic!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiang-Red committed Aug 20, 2024
1 parent af6f677 commit e6b7826
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 264 deletions.
87 changes: 8 additions & 79 deletions control/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@
package control

import (
"encoding/base64"
"image"
"image/jpeg"
"os"
"strconv"
"strings"
"sync"

"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension"
"github.com/wdvxdr1123/ZeroBot/message"

"github.com/FloatTech/floatbox/binary"
"github.com/FloatTech/floatbox/file"
"github.com/FloatTech/imgfactory"
"github.com/FloatTech/rendercard"
ctrl "github.com/FloatTech/zbpctrl"

"github.com/FloatTech/zbputils/ctxext"
)

const (
Expand All @@ -30,7 +22,6 @@ const (
// Md5File ...
Md5File = StorageFolder + "stor.spb"
dbfile = StorageFolder + "plugins.db"
lnfile = StorageFolder + "lnperpg.txt"
)

var (
Expand Down Expand Up @@ -79,21 +70,6 @@ func init() {
if err != nil {
panic(err)
}
// 载入用户配置
if file.IsExist(lnfile) {
data, err := os.ReadFile(lnfile)
if err != nil {
logrus.Warnln("[control] 读取配置文件失败,将使用默认的显示行数:", err)
} else {
mun, err := strconv.Atoi(binary.BytesToString(data))
if err != nil {
logrus.Warnln("[control] 获取设置的服务列表显示行数错误,将使用默认的显示行数:", err)
} else if mun > 0 {
lnperpg = mun
logrus.Infoln("[control] 获取到当前设置的服务列表显示行数为:", lnperpg)
}
}
}
zero.OnCommandGroup([]string{
"响应", "response", "沉默", "silence",
}, zero.UserOrGrpAdmin, zero.OnlyToMe).SetBlock(true).SecondPriority().Handle(func(ctx *zero.Ctx) {
Expand Down Expand Up @@ -474,65 +450,18 @@ func init() {
if gid == 0 {
gid = -ctx.Event.UserID
}
var imgs []image.Image
imgs, err = drawservicesof(gid)
img, err := renderservepicof(gid)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
if len(imgs) > 1 {
wg := sync.WaitGroup{}
msg := make(message.Message, len(imgs))
wg.Add(len(imgs))
for i := 0; i < len(imgs); i++ {
go func(i int) {
defer wg.Done()
msg[i] = ctxext.FakeSenderForwardNode(ctx, message.Image(binary.BytesToString(binary.NewWriterF(func(w *binary.Writer) {
w.WriteString("base64://")
encoder := base64.NewEncoder(base64.StdEncoding, w)
var opt jpeg.Options
opt.Quality = 70
if err1 := jpeg.Encode(encoder, imgs[i], &opt); err1 != nil {
err = err1
return
}
_ = encoder.Close()
}))))
}(i)
}
wg.Wait()
if id := ctx.Send(msg); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
}
} else {
b64, err := imgfactory.ToBase64(imgs[0])
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
if id := ctx.SendChain(message.Image("base64://" + binary.BytesToString(b64))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
}
b64, err := imgfactory.ToBase64(img)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
if id := ctx.SendChain(message.Image("base64://" + binary.BytesToString(b64))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
}
})

zero.OnCommand("设置服务列表显示行数", zero.SuperUserPermission, zero.OnlyToMe).SetBlock(true).SecondPriority().Handle(func(ctx *zero.Ctx) {
model := extension.CommandModel{}
_ = ctx.Parse(&model)
mun, err := strconv.Atoi(model.Args)
if err != nil {
ctx.SendChain(message.Text("请输入正确的数字"))
return
}
err = os.WriteFile(lnfile, binary.StringToBytes(model.Args), 0644)
if err != nil {
ctx.SendChain(message.Text(err))
return
}
lnperpg = mun
// 清除缓存
titlecache = nil
fullpageshadowcache = nil
ctx.SendChain(message.Text("已设置列表单页显示数为 " + strconv.Itoa(lnperpg)))
})
}
Loading

0 comments on commit e6b7826

Please sign in to comment.