diff --git a/plugin/lolicon/lolicon.go b/plugin/lolicon/lolicon.go index 4b7cbc25..2ae53fdb 100644 --- a/plugin/lolicon/lolicon.go +++ b/plugin/lolicon/lolicon.go @@ -3,6 +3,7 @@ package lolicon import ( "encoding/base64" + "errors" "net/url" "strings" "time" @@ -17,7 +18,7 @@ import ( ctrl "github.com/FloatTech/zbpctrl" "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" - "github.com/FloatTech/zbputils/img/pool" + imagepool "github.com/FloatTech/zbputils/img/pool" ) const ( @@ -26,8 +27,8 @@ const ( ) var ( - queue = make(chan string, capacity) - custapi = "" + queue = make(chan string, capacity) + customapi = "" ) func init() { @@ -40,10 +41,21 @@ func init() { }).ApplySingle(ctxext.DefaultSingle) en.OnPrefix("随机图片").Limit(ctxext.LimitByUser).SetBlock(true). Handle(func(ctx *zero.Ctx) { + if imgtype := strings.TrimSpace(ctx.State["args"].(string)); imgtype != "" { + imageurl, err := getimgurl(api + "?tag=" + url.QueryEscape(imgtype)) + if err != nil { + ctx.SendChain(message.Text("ERROR: ", err)) + return + } + if id := ctx.Send(message.Message{ctxext.FakeSenderForwardNode(ctx, message.Image(imageurl))}).ID(); id == 0 { + ctx.SendChain(message.Text("ERROR: 可能被风控了")) + } + return + } go func() { for i := 0; i < math.Min(cap(queue)-len(queue), 2); i++ { - if custapi != "" { - data, err := web.GetData(custapi) + if customapi != "" { + data, err := web.GetData(customapi) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) continue @@ -51,34 +63,22 @@ func init() { queue <- "base64://" + base64.StdEncoding.EncodeToString(data) continue } - rapi := api - args := strings.TrimSpace(ctx.State["args"].(string)) - if args != "" { - rapi += "?tag=" + url.QueryEscape(args) - } - data, err := web.GetData(rapi) + imageurl, err := getimgurl(api) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) continue } - json := gjson.ParseBytes(data) - if e := json.Get("error").Str; e != "" { - ctx.SendChain(message.Text("ERROR: ", e)) - continue - } - url := json.Get("data.0.urls.original").Str - url = strings.ReplaceAll(url, "i.pixiv.cat", "i.pixiv.re") - name := url[strings.LastIndex(url, "/")+1 : len(url)-4] - m, err := pool.GetImage(name) + name := imageurl[strings.LastIndex(imageurl, "/")+1 : len(imageurl)-4] + m, err := imagepool.GetImage(name) if err != nil { - m.SetFile(url) - _, err = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx)) + m.SetFile(imageurl) + _, _ = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx)) process.SleepAbout1sTo2s() } if err == nil { queue <- m.String() } else { - queue <- url + queue <- imageurl } } }() @@ -98,6 +98,22 @@ func init() { Handle(func(ctx *zero.Ctx) { u := strings.TrimSpace(ctx.State["args"].(string)) ctx.SendChain(message.Text("成功设置随机图片地址为", u)) - custapi = u + customapi = u }) } + +func getimgurl(url string) (string, error) { + data, err := web.GetData(url) + if err != nil { + return "", err + } + json := gjson.ParseBytes(data) + if e := json.Get("error").Str; e != "" { + return "", errors.New(e) + } + var imageurl string + if imageurl = json.Get("data.0.urls.original").Str; imageurl == "" { + return "", errors.New("未找到相关内容, 换个tag试试吧") + } + return strings.ReplaceAll(imageurl, "i.pixiv.cat", "i.pixiv.re"), nil +} diff --git a/plugin/qqwife/command.go b/plugin/qqwife/command.go index 2372ab87..d71ed4d6 100644 --- a/plugin/qqwife/command.go +++ b/plugin/qqwife/command.go @@ -61,7 +61,7 @@ func init() { DisableOnDefault: false, PrivateDataFolder: "qqwife", Help: "一群一天一夫一妻制群老婆\n(每天凌晨刷新CP)\n" + - "- 娶群友\n- 群老婆列表\n- 允许/禁止自由恋爱\n- 允许/禁止牛头人\n- 设置CD为xx小时 →(默认12小时)\n- 重置花名册\n" + + "- 娶群友\n- 群老婆列表\n- 允许/禁止自由恋爱\n- 允许/禁止牛头人\n- 设置CD为xx小时 →(默认12小时)\n- 重置花名册\n- 重置所有花名册(用于清除所有群数据及其设置)\n" + "--------------------------------\n以下指令存在CD,不跨天刷新,前两个受指令开关\n--------------------------------\n" + "- (娶|嫁)@对方QQ\n自由选择对象,自由恋爱(好感度越高成功率越高,保底30%概率)\n" + "- 当[对方Q号|@对方QQ]的小三\n我和你才是真爱,为了你我愿意付出一切(好感度越高成功率越高,保底10%概率)\n" + diff --git a/plugin/qqwife/function.go b/plugin/qqwife/function.go index be5eba37..ee0ec9a0 100644 --- a/plugin/qqwife/function.go +++ b/plugin/qqwife/function.go @@ -180,19 +180,34 @@ func (sql *婚姻登记) 清理花名册(gid string) error { return err } if gid != "0" { - grouplist = []string{gid} + grouplist = []string{"group" + gid} } for _, gid := range grouplist { - err = sql.db.Drop("group" + gid) - if err != nil { + if gid == "favorability" { + continue + } + err = sql.db.Drop(gid) + if err != nil || gid == "updateinfo" { continue } gidint, _ := strconv.ParseInt(gid, 10, 64) - updateinfo := updateinfo{ + upinfo := updateinfo{ GID: gidint, Updatetime: time.Now().Format("2006/01/02"), + CanMatch: 1, + CanNtr: 1, + CDtime: 12, } - err = sql.db.Insert("updateinfo", &updateinfo) + err = sql.db.Create("updateinfo", &updateinfo{}) + if err != nil { + if err = sql.db.Drop("updateinfo"); err == nil { + err = sql.db.Create("updateinfo", &updateinfo{}) + } + if err != nil { + return err + } + } + err = sql.db.Insert("updateinfo", &upinfo) } return err } diff --git a/plugin/saucenao/searcher.go b/plugin/saucenao/searcher.go index 89eb1082..2b33325d 100644 --- a/plugin/saucenao/searcher.go +++ b/plugin/saucenao/searcher.go @@ -95,15 +95,8 @@ func init() { // 插件主体 "直链: ", "https://pixivel.moe/detail?id=", illust.Pid, ) if imgs != nil { - if zero.OnlyGroup(ctx) { - ctx.SendGroupForwardMessage(ctx.Event.GroupID, message.Message{ - ctxext.FakeSenderForwardNode(ctx, txt), - ctxext.FakeSenderForwardNode(ctx, imgs...), - }) - } else { - // 发送搜索结果 - ctx.Send(append(imgs, message.Text("\n"), txt)) - } + ctx.Send(message.Message{ctxext.FakeSenderForwardNode(ctx, txt), + ctxext.FakeSenderForwardNode(ctx, imgs...)}) } else { // 图片下载失败,仅发送文字结果 ctx.SendChain(txt) @@ -113,7 +106,7 @@ func init() { // 插件主体 } }) // 以图搜图 - engine.OnKeywordGroup([]string{"以图搜图", "搜索图片", "以图识图"}, zero.OnlyGroup, zero.MustProvidePicture).SetBlock(true). + engine.OnKeywordGroup([]string{"以图搜图", "搜索图片", "以图识图"}, zero.MustProvidePicture).SetBlock(true). Handle(func(ctx *zero.Ctx) { // 开始搜索图片 ctx.SendChain(message.Text("少女祈祷中...")) @@ -154,7 +147,7 @@ func init() { // 插件主体 msg = append(msg, message.Image(pic)) } msg = append(msg, message.Text("\n图源: ", result.Header.IndexName, binary.BytesToString(b))) - ctx.Send(msg) + ctx.Send(ctxext.FakeSenderForwardNode(ctx, msg...)) if s > 80.0 { continue } @@ -182,10 +175,7 @@ func init() { // 插件主体 ))), ) } - if id := ctx.SendGroupForwardMessage( - ctx.Event.GroupID, - msg, - ).Get("message_id").Int(); id == 0 { + if id := ctx.Send(msg).ID(); id == 0 { ctx.SendChain(message.Text("ERROR: 可能被风控了")) } } diff --git a/plugin/setutime/setu_geter.go b/plugin/setutime/setu_geter.go index 05904cee..bcd08200 100644 --- a/plugin/setutime/setu_geter.go +++ b/plugin/setutime/setu_geter.go @@ -94,7 +94,7 @@ func init() { // 插件主体 } } // 从缓冲池里抽一张 - if id := ctx.SendChain(*pool.pop(imgtype)); id.ID() == 0 { + if id := ctx.Send(ctxext.FakeSenderForwardNode(ctx, *pool.pop(imgtype))); id.ID() == 0 { ctx.SendChain(message.Text("ERROR: 可能被风控了")) } }) diff --git a/plugin/tarot/tarot.go b/plugin/tarot/tarot.go index fab90556..488ba05b 100644 --- a/plugin/tarot/tarot.go +++ b/plugin/tarot/tarot.go @@ -162,7 +162,7 @@ func init() { message.Text("\n其释义为: ", description)} msg[i] = ctxext.FakeSenderForwardNode(ctx, tarotMsg...) } - ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg) + ctx.Send(msg) }) engine.OnRegex(`^解塔罗牌\s?(.*)`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) { @@ -248,7 +248,7 @@ func init() { return } msg[info.CardsNum] = ctxext.FakeSenderForwardNode(ctx, []message.MessageSegment{message.Image("base64://" + binary.BytesToString(formation))}...) - ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg) + ctx.Send(msg) } else { ctx.SendChain(message.Text("没有找到", match, "噢~\n现有牌阵列表: \n", strings.Join(formationName, "\n"))) }