From d3ab1e156044499664cd43d0f06fc441ca4c6e5d Mon Sep 17 00:00:00 2001 From: himawari <54976075+guohuiyuan@users.noreply.github.com> Date: Sat, 17 Sep 2022 14:53:25 +0800 Subject: [PATCH] Refactor image (#419) --- README.md | 4 +++- plugin/bilibili/bilibili.go | 2 +- plugin/coser/coser.go | 7 ++----- plugin/lolicon/lolicon.go | 26 ++++++++++++++------------ plugin/score/sign_in.go | 2 +- plugin/ymgal/model.go | 2 +- plugin/ymgal/ymgal.go | 4 +--- 7 files changed, 23 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 4f9c13ae..c8183236 100644 --- a/README.md +++ b/README.md @@ -733,7 +733,9 @@ print("run[CQ:image,file="+j["img"]+"]") `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/lolicon"` - - [x] 来份萝莉 + - [x] 随机图片 + + - [x] 随机图片 萝莉|少女 - [x] 设置随机图片地址[http...] diff --git a/plugin/bilibili/bilibili.go b/plugin/bilibili/bilibili.go index a0c4108e..788619c4 100644 --- a/plugin/bilibili/bilibili.go +++ b/plugin/bilibili/bilibili.go @@ -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", }) diff --git a/plugin/coser/coser.go b/plugin/coser/coser.go index 8d05b903..6bd68761 100644 --- a/plugin/coser/coser.go +++ b/plugin/coser/coser.go @@ -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) @@ -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: 可能被风控或下载图片用时过长,请耐心等待")) } }) diff --git a/plugin/lolicon/lolicon.go b/plugin/lolicon/lolicon.go index 96ad27c3..4b7cbc25 100644 --- a/plugin/lolicon/lolicon.go +++ b/plugin/lolicon/lolicon.go @@ -3,6 +3,7 @@ package lolicon import ( "encoding/base64" + "net/url" "strings" "time" @@ -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++ { @@ -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 @@ -79,12 +86,10 @@ 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: 可能被风控或下载图片用时过长,请耐心等待")) } } } @@ -92,10 +97,7 @@ func init() { 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 }) } diff --git a/plugin/score/sign_in.go b/plugin/score/sign_in.go index b03eefe5..27598a41 100644 --- a/plugin/score/sign_in.go +++ b/plugin/score/sign_in.go @@ -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() diff --git a/plugin/ymgal/model.go b/plugin/ymgal/model.go index 59b452d9..3477e398 100644 --- a/plugin/ymgal/model.go +++ b/plugin/ymgal/model.go @@ -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/" diff --git a/plugin/ymgal/ymgal.go b/plugin/ymgal/ymgal.go index f6811135..ba17a10e 100644 --- a/plugin/ymgal/ymgal.go +++ b/plugin/ymgal/ymgal.go @@ -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: 可能被风控了")) } }