diff --git a/go.mod b/go.mod index bb3ef871..d6e1fb10 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/FloatTech/sqlite v1.7.1 github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 github.com/FloatTech/zbpctrl v1.7.0 - github.com/FloatTech/zbputils v1.7.2-0.20250923162319-dcba1aa52b1d + github.com/FloatTech/zbputils v1.7.2-0.20250925155009-638ed762e15e github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 github.com/Tnze/go-mc v1.20.2 @@ -24,7 +24,7 @@ require ( github.com/fumiama/cron v1.3.0 github.com/fumiama/deepinfra v0.0.0-20250924162107-cf156d49a0fa github.com/fumiama/go-base16384 v1.7.0 - github.com/fumiama/go-onebot-agent v0.0.0-20250924153727-0cdc929590cf + github.com/fumiama/go-onebot-agent v0.0.0-20250925150209-46ace7c2b17a github.com/fumiama/go-registry v0.2.7 github.com/fumiama/gotracemoe v0.0.3 github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565 diff --git a/go.sum b/go.sum index 79f3e94d..bcb5e1fe 100644 --- a/go.sum +++ b/go.sum @@ -17,8 +17,8 @@ github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 h1:snfw7FNFym1eNnLrQ github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs= github.com/FloatTech/zbpctrl v1.7.0 h1:Hxo6EIhJo+pHjcQP9QgIJgluaT1pHH99zkk3njqTNMo= github.com/FloatTech/zbpctrl v1.7.0/go.mod h1:xmM4dSwHA02Gei3ogCRiG+RTrw/7Z69PfrN5NYf8BPE= -github.com/FloatTech/zbputils v1.7.2-0.20250923162319-dcba1aa52b1d h1:B7pvVpZSSfCjSNLONq0dWTm5JahCdE2017hzDP/DmzY= -github.com/FloatTech/zbputils v1.7.2-0.20250923162319-dcba1aa52b1d/go.mod h1:CpwrdL0xCiUfN1819TDKk470WGMYQZZanLjAYVfHCEM= +github.com/FloatTech/zbputils v1.7.2-0.20250925155009-638ed762e15e h1:M+pIxQFztHqrtUVmfctSs/D5ytn0ag6twP6iJg3gdEk= +github.com/FloatTech/zbputils v1.7.2-0.20250925155009-638ed762e15e/go.mod h1:AUDxqs7liBF2H7TpSs+OXZj1Akyh0moUN/J/j8iNFxc= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 h1:S/ferNiehVjNaBMNNBxUjLtVmP/YWD6Yh79RfPv4ehU= github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w= @@ -63,8 +63,8 @@ github.com/fumiama/deepinfra v0.0.0-20250924162107-cf156d49a0fa h1:UMMNejpPp8dn9 github.com/fumiama/deepinfra v0.0.0-20250924162107-cf156d49a0fa/go.mod h1:uqsWK/GM9OvKV0pXZOQB63rWugBbiXInY8E1JoRKhkg= github.com/fumiama/go-base16384 v1.7.0 h1:6fep7XPQWxRlh4Hu+KsdH+6+YdUp+w6CwRXtMWSsXCA= github.com/fumiama/go-base16384 v1.7.0/go.mod h1:OEn+947GV5gsbTAnyuUW/SrfxJYUdYupSIQXOuGOcXM= -github.com/fumiama/go-onebot-agent v0.0.0-20250924153727-0cdc929590cf h1:yFkCBQlFBCRQLru/ANWvvWDTRpT3qLhBP94aAJnlmaY= -github.com/fumiama/go-onebot-agent v0.0.0-20250924153727-0cdc929590cf/go.mod h1:FIhZxVeFAs201W06EgXxx/6b/l/ETSmu2sQOj10kjdk= +github.com/fumiama/go-onebot-agent v0.0.0-20250925150209-46ace7c2b17a h1:PapkA1fkFCzBbcmFaxRQvRAHbRig3NIgstzG7OFcXjQ= +github.com/fumiama/go-onebot-agent v0.0.0-20250925150209-46ace7c2b17a/go.mod h1:FIhZxVeFAs201W06EgXxx/6b/l/ETSmu2sQOj10kjdk= github.com/fumiama/go-registry v0.2.7 h1:tLEqgEpsiybQMqBv0dLHm5leia/z1DhajMupwnOHeNs= github.com/fumiama/go-registry v0.2.7/go.mod h1:m+wp5fF8dYgVoFkBPZl+vlK90loymaJE0JCtocVQLEs= github.com/fumiama/go-simple-protobuf v0.2.0 h1:ACyN1MAlu7pDR3EszWgzUeNP+IRsSHwH6V9JCJA5R5o= diff --git a/plugin/aichat/main.go b/plugin/aichat/main.go index b8a70703..98ac2f39 100644 --- a/plugin/aichat/main.go +++ b/plugin/aichat/main.go @@ -4,7 +4,6 @@ package aichat import ( "encoding/json" "math/rand" - "reflect" "strconv" "strings" "time" @@ -16,6 +15,7 @@ import ( "github.com/tidwall/gjson" zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/extension/single" "github.com/wdvxdr1123/ZeroBot/message" "github.com/FloatTech/AnimeAPI/airecord" @@ -54,7 +54,15 @@ var ( "- /gpt [内容] (使用大模型聊天)\n", PrivateDataFolder: "aichat", - }) + }).ApplySingle(single.New( + single.WithKeyFn(func(ctx *zero.Ctx) int64 { + if ctx.Event.GroupID == 0 { + return -ctx.Event.UserID + } + return ctx.Event.GroupID + }), + // no post option, silently quit + )) ) var ( @@ -113,31 +121,23 @@ func init() { } ag.SetViewImageAPI(deepinfra.NewAPI(cfg.ImageAPI, string(cfg.ImageKey)), mod) } - reqs, err := ag.GetAction(x, mod, gid, role, false) - if err != nil { - logrus.Warnln("[aichat] agent err:", err, reqs) - return - } - logrus.Infoln("[aichat] agent do:", reqs) - for _, req := range reqs { - if req.Action == "send_group_msg" { - v, ok := req.Params["group_id"].(json.Number) - if !ok { - logrus.Warnln("[aichat] invalid group_id type", reflect.TypeOf(req.Params["group_id"])) - continue - } - gid, err = v.Int64() - if !ok { - logrus.Warnln("[aichat] agent conv req gid err:", err) - continue - } - if ctx.Event.GroupID != gid && !zero.SuperUserPermission(ctx) { - logrus.Warnln("[aichat] refuse to send out of grp from", ctx.Event.GroupID, "to", gid) - continue - } + ctx.NoTimeout() + for i := 0; i < 8; i++ { // 最大运行 8 轮因为问答上下文只有 16 + reqs := chat.CallAgent(ag, zero.SuperUserPermission(ctx), x, mod, gid, role) + if len(reqs) == 0 { + return + } + for _, req := range reqs { + resp := ctx.CallAction(req.Action, req.Params) + logrus.Infoln("[aichat] agent get resp:", reqs) + ag.AddResponse(gid, &goba.APIResponse{ + Status: resp.Status, + Data: json.RawMessage(resp.Data.Raw), + Message: resp.Message, + Wording: resp.Wording, + RetCode: resp.RetCode, + }) } - ctx.CallAction(req.Action, req.Params) - process.SleepAbout1sTo2s() } return } diff --git a/plugin/chess/chess.go b/plugin/chess/chess.go index f32e6bf2..4f693d7c 100644 --- a/plugin/chess/chess.go +++ b/plugin/chess/chess.go @@ -13,7 +13,6 @@ import ( "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/extension/single" "github.com/wdvxdr1123/ZeroBot/message" ) @@ -35,16 +34,7 @@ var ( Brief: "国际象棋", Help: helpString, PrivateDataFolder: "chess", - }).ApplySingle(single.New( - single.WithKeyFn(func(ctx *zero.Ctx) int64 { return ctx.Event.GroupID }), - single.WithPostFn[int64](func(ctx *zero.Ctx) { - ctx.Send( - message.ReplyWithMessage(ctx.Event.MessageID, - message.Text("有操作正在执行, 请稍后再试..."), - ), - ) - }), - )) + }).ApplySingle(ctxext.GroupSingle) ) func init() { diff --git a/plugin/guessmusic/main.go b/plugin/guessmusic/main.go index 3c758d55..0974aba7 100644 --- a/plugin/guessmusic/main.go +++ b/plugin/guessmusic/main.go @@ -15,7 +15,6 @@ import ( "github.com/FloatTech/zbputils/ctxext" "github.com/pkg/errors" zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/extension/single" "github.com/wdvxdr1123/ZeroBot/message" // 图片输出 @@ -65,17 +64,7 @@ var ( "- 下载歌单[网易云歌单链接/ID]到[歌单名称]\n" + "- 解除绑定 [歌单名称]", PrivateDataFolder: "guessmusic", - }).ApplySingle(single.New( - single.WithKeyFn(func(ctx *zero.Ctx) int64 { return ctx.Event.GroupID }), - single.WithPostFn[int64](func(ctx *zero.Ctx) { - ctx.Break() - ctx.Send( - message.ReplyWithMessage(ctx.Event.MessageID, - message.Text("已经有正在进行的游戏..."), - ), - ) - }), - )) + }).ApplySingle(ctxext.NewGroupSingle("已经有正在进行的游戏...")) // 用于存放歌曲三个片段的缓存文件夹 cachePath = engine.DataFolder() + "cache/" // 用于存放用户的配置 diff --git a/plugin/qqwife/command.go b/plugin/qqwife/command.go index 9f548bd0..fe53b0c6 100644 --- a/plugin/qqwife/command.go +++ b/plugin/qqwife/command.go @@ -17,7 +17,7 @@ import ( "github.com/wdvxdr1123/ZeroBot/message" // 反并发 - "github.com/wdvxdr1123/ZeroBot/extension/single" + // 数据库 sql "github.com/FloatTech/sqlite" // 画图 @@ -67,16 +67,7 @@ var ( "\"娶群友\"&\"(娶|嫁)@对方QQ\"指令好感度随机增加1~5。\n\"A牛B的C\"会导致C恨A, 好感度-5;\nB为了报复A, 好感度+5(什么柜子play)\nA为BC做媒,成功B、C对A好感度+1反之-1\n做媒成功BC好感度+1" + "\nTips: 群老婆列表过0点刷新", PrivateDataFolder: "qqwife", - }).ApplySingle(single.New( - single.WithKeyFn(func(ctx *zero.Ctx) int64 { return ctx.Event.GroupID }), - single.WithPostFn[int64](func(ctx *zero.Ctx) { - ctx.Send( - message.ReplyWithMessage(ctx.Event.MessageID, - message.Text("别着急,民政局门口排长队了!"), - ), - ) - }), - )) + }).ApplySingle(ctxext.NewGroupSingle("别着急,民政局门口排长队了!")) getdb = fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool { 民政局.db = sql.New(engine.DataFolder() + "结婚登记表.db") err := 民政局.db.Open(time.Hour) diff --git a/plugin/robbery/robbery.go b/plugin/robbery/robbery.go index e393161b..dfda1c48 100644 --- a/plugin/robbery/robbery.go +++ b/plugin/robbery/robbery.go @@ -11,7 +11,6 @@ import ( sql "github.com/FloatTech/sqlite" ctrl "github.com/FloatTech/zbpctrl" "github.com/FloatTech/zbputils/control" - "github.com/wdvxdr1123/ZeroBot/extension/single" "github.com/FloatTech/AnimeAPI/wallet" "github.com/FloatTech/floatbox/math" @@ -45,16 +44,7 @@ func init() { "7. 每日可打劫或被打劫一次\n" + "8. 打劫失败不计入次数\n", PrivateDataFolder: "robbery", - }).ApplySingle(single.New( - single.WithKeyFn(func(ctx *zero.Ctx) int64 { return ctx.Event.GroupID }), - single.WithPostFn[int64](func(ctx *zero.Ctx) { - ctx.Send( - message.ReplyWithMessage(ctx.Event.MessageID, - message.Text("别着急,警察局门口排长队了!"), - ), - ) - }), - )) + }).ApplySingle(ctxext.NewGroupSingle("别着急,警察局门口排长队了!")) getdb := fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool { police.db = sql.New(engine.DataFolder() + "robbery.db") err := police.db.Open(time.Hour) diff --git a/plugin/wenxinvilg/main.go b/plugin/wenxinvilg/main.go index 36d64f82..0f510b85 100644 --- a/plugin/wenxinvilg/main.go +++ b/plugin/wenxinvilg/main.go @@ -14,7 +14,6 @@ import ( "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/extension/single" "github.com/wdvxdr1123/ZeroBot/message" // 数据库 @@ -83,17 +82,7 @@ func init() { // 插件主体 "指令示例:\n" + name + "帮我画几张金凤凰,背景绚烂,高饱和,古风,仙境,高清,4K,古风的油画方图", PrivateDataFolder: "wenxinAI", - }).ApplySingle(single.New( - single.WithKeyFn(func(ctx *zero.Ctx) int64 { return ctx.Event.GroupID }), - single.WithPostFn[int64](func(ctx *zero.Ctx) { - ctx.Break() - ctx.Send( - message.ReplyWithMessage(ctx.Event.MessageID, - message.Text(zero.BotConfig.NickName[0], "正在给别人画图,请不要打扰哦"), - ), - ) - }), - )) + }).ApplySingle(ctxext.NewGroupSingle("正在给别人画图,请不要打扰哦")) getdb := fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool { vilginfo.db = sql.New(engine.DataFolder() + "ernieVilg.db") err := vilginfo.db.Open(time.Hour) @@ -285,17 +274,7 @@ func init() { // 插件主体 "文心自定义 请写出下面这道题的解题过程。\\n题目:养殖场养鸭376只,养鸡的只数比鸭多258只,这个养殖场一共养鸭和鸡多少只?\\n解:\n\n" + "文心自定义 1+1=?\n" + "文心自定义 歌曲名:大风车转啊转\\n歌词:", - }).ApplySingle(single.New( - single.WithKeyFn(func(ctx *zero.Ctx) int64 { return ctx.Event.GroupID }), - single.WithPostFn[int64](func(ctx *zero.Ctx) { - ctx.Break() - ctx.Send( - message.ReplyWithMessage(ctx.Event.MessageID, - message.Text(zero.BotConfig.NickName[0], "正在给别人编辑,请不要打扰哦"), - ), - ) - }), - )) + }).ApplySingle(ctxext.NewGroupSingle("正在给别人编辑,请不要打扰哦")) getmodeldb := fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool { modelinfo.db = sql.New(engine.DataFolder() + "ernieModel.db") err := modelinfo.db.Open(time.Hour) diff --git a/plugin/wife/wifegame.go b/plugin/wife/wifegame.go index 815dfb10..f2b1c286 100644 --- a/plugin/wife/wifegame.go +++ b/plugin/wife/wifegame.go @@ -16,7 +16,6 @@ import ( "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/extension/single" "github.com/wdvxdr1123/ZeroBot/message" zbmath "github.com/FloatTech/floatbox/math" @@ -29,21 +28,7 @@ var ( DisableOnDefault: false, Help: "- 猜老婆", Brief: "从老婆库猜老婆", - }).ApplySingle(single.New( - single.WithKeyFn(func(ctx *zero.Ctx) int64 { - if ctx.Event.GroupID != 0 { - return ctx.Event.GroupID - } - return -ctx.Event.UserID - }), - single.WithPostFn[int64](func(ctx *zero.Ctx) { - ctx.Send( - message.ReplyWithMessage(ctx.Event.MessageID, - message.Text("已经有正在进行的游戏..."), - ), - ) - }), - )) + }).ApplySingle(ctxext.NewGroupSingle("已经有正在进行的游戏...")) ) func init() { diff --git a/plugin/wordle/wordle.go b/plugin/wordle/wordle.go index 491f27de..0f12bddb 100644 --- a/plugin/wordle/wordle.go +++ b/plugin/wordle/wordle.go @@ -22,7 +22,6 @@ import ( "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/extension/single" "github.com/wdvxdr1123/ZeroBot/message" ) @@ -69,16 +68,7 @@ func init() { "- 团队六阶猜单词\n" + "- 团队七阶猜单词", PublicDataFolder: "Wordle", - }).ApplySingle(single.New( - single.WithKeyFn(func(ctx *zero.Ctx) int64 { return ctx.Event.GroupID }), - single.WithPostFn[int64](func(ctx *zero.Ctx) { - ctx.Send( - message.ReplyWithMessage(ctx.Event.MessageID, - message.Text("已经有正在进行的游戏..."), - ), - ) - }), - )) + }).ApplySingle(ctxext.NewGroupSingle("已经有正在进行的游戏...")) en.OnRegex(`^(个人|团队)(五阶|六阶|七阶)?猜单词$`, zero.OnlyGroup, fcext.DoOnceOnSuccess( func(ctx *zero.Ctx) bool { diff --git a/plugin/ymgal/ymgal.go b/plugin/ymgal/ymgal.go index 4b492a49..56017277 100644 --- a/plugin/ymgal/ymgal.go +++ b/plugin/ymgal/ymgal.go @@ -72,7 +72,7 @@ func init() { func sendYmgal(y ymgal, ctx *zero.Ctx) { if y.PictureList == "" { - ctx.SendChain(message.Text(zero.BotConfig.NickName[0] + "暂时没有这样的图呢")) + ctx.SendChain(message.Text(zero.BotConfig.NickName[0], "暂时没有这样的图呢")) return } m := message.Message{ctxext.FakeSenderForwardNode(ctx, message.Text(y.Title))}