Skip to content

Commit

Permalink
Refactor image (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
guohuiyuan authored Sep 17, 2022
1 parent 598a255 commit d3ab1e1
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 24 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,9 @@ print("run[CQ:image,file="+j["img"]+"]")

`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/lolicon"`

- [x] 来份萝莉
- [x] 随机图片

- [x] 随机图片 萝莉|少女

- [x] 设置随机图片地址[http...]

Expand Down
2 changes: 1 addition & 1 deletion plugin/bilibili/bilibili.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func init() {
"- >user info [xxx]\n" +
"- 查成分 [xxx]\n" +
"- 查弹幕 [xxx]\n" +
"- 设置b站cookie SESSDATA=82da790d,1663822823,06ecf*31\n" +
"- 设置b站cookie [xxx]\n" +
"- 更新vup",
PublicDataFolder: "Bilibili",
})
Expand Down
7 changes: 2 additions & 5 deletions plugin/coser/coser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {
control.Register("coser", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Help: "三次元小姐姐\n- coser",
}).ApplySingle(ctxext.DefaultSingle).OnFullMatch("coser", zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByGroup).
}).ApplySingle(ctxext.DefaultSingle).OnFullMatch("coser").SetBlock(true).Limit(ctxext.LimitByGroup).
Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text("少女祈祷中......"))
data, err := web.RequestDataWith(web.NewDefaultClient(), coserURL, "GET", "", ua)
Expand All @@ -46,10 +46,7 @@ func init() {
m = append(m, ctxext.FakeSenderForwardNode(ctx, message.Image(value.String())))
return true
})

if id := ctx.SendGroupForwardMessage(
ctx.Event.GroupID,
m).Get("message_id").Int(); id == 0 {
if id := ctx.Send(m).ID(); id == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控或下载图片用时过长,请耐心等待"))
}
})
Expand Down
26 changes: 14 additions & 12 deletions plugin/lolicon/lolicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lolicon

import (
"encoding/base64"
"net/url"
"strings"
"time"

Expand Down Expand Up @@ -33,10 +34,11 @@ func init() {
en := control.Register("lolicon", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Help: "lolicon\n" +
"- 来份萝莉\n" +
"- 随机图片\n" +
"- 随机图片 萝莉|少女\n" +
"- 设置随机图片地址[http...]",
}).ApplySingle(ctxext.DefaultSingle)
en.OnFullMatch("来份萝莉").Limit(ctxext.LimitByGroup).SetBlock(true).
en.OnPrefix("随机图片").Limit(ctxext.LimitByUser).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
go func() {
for i := 0; i < math.Min(cap(queue)-len(queue), 2); i++ {
Expand All @@ -49,7 +51,12 @@ func init() {
queue <- "base64://" + base64.StdEncoding.EncodeToString(data)
continue
}
data, err := web.GetData(api)
rapi := api
args := strings.TrimSpace(ctx.State["args"].(string))
if args != "" {
rapi += "?tag=" + url.QueryEscape(args)
}
data, err := web.GetData(rapi)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
continue
Expand Down Expand Up @@ -79,23 +86,18 @@ func init() {
case <-time.After(time.Minute):
ctx.SendChain(message.Text("ERROR: 等待填充,请稍后再试......"))
case img := <-queue:
id := ctx.SendChain(message.Image(img))
if id.ID() == 0 {
if id := ctx.Send(message.Message{ctxext.FakeSenderForwardNode(ctx, message.Image(img))}).ID(); id == 0 {
process.SleepAbout1sTo2s()
id = ctx.SendChain(message.Image(img).Add("cache", "0"))
if id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 图片发送失败,可能被风控了~"))
if id := ctx.Send(message.Message{ctxext.FakeSenderForwardNode(ctx, message.Image(img).Add("cache", "0"))}).ID(); id == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控或下载图片用时过长,请耐心等待"))
}
}
}
})
en.OnPrefix("设置随机图片地址", zero.SuperUserPermission).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
u := strings.TrimSpace(ctx.State["args"].(string))
if !strings.HasPrefix(u, "http") {
ctx.SendChain(message.Text("ERROR: url非法!"))
return
}
ctx.SendChain(message.Text("成功设置随机图片地址为", u))
custapi = u
})
}
2 changes: 1 addition & 1 deletion plugin/score/sign_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func init() {
}
sdb = initialize(engine.DataFolder() + "score.db")
}()
engine.OnFullMatch("签到", zero.OnlyGroup).Limit(ctxext.LimitByGroup).SetBlock(true).
engine.OnFullMatch("签到").Limit(ctxext.LimitByUser).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID
now := time.Now()
Expand Down
2 changes: 1 addition & 1 deletion plugin/ymgal/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (gdb *ymgaldb) getYmgalByKey(pictureType, key string) (y ymgal) {
}

const (
webURL = "https://www.ymgal.com"
webURL = "https://www.ymgal.games"
cgType = "Gal CG"
emoticonType = "其他"
webPicURL = webURL + "/co/picset/"
Expand Down
4 changes: 1 addition & 3 deletions plugin/ymgal/ymgal.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ func sendYmgal(y ymgal, ctx *zero.Ctx) {
for _, v := range strings.Split(y.PictureList, ",") {
m = append(m, ctxext.FakeSenderForwardNode(ctx, message.Image(v)))
}
if id := ctx.SendGroupForwardMessage(
ctx.Event.GroupID,
m).Get("message_id").Int(); id == 0 {
if id := ctx.Send(m).ID(); id == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
}
}

0 comments on commit d3ab1e1

Please sign in to comment.