mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-06 15:20:22 +00:00
feat(aichat): add handling resp
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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/"
|
||||
// 用于存放用户的配置
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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))}
|
||||
|
||||
Reference in New Issue
Block a user