-
Notifications
You must be signed in to change notification settings - Fork 2k
Feature airecord 20250704 #1180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fumiama
merged 16 commits into
FloatTech:master
from
guohuiyuan:feature-airecord-20250704
Jul 20, 2025
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9aaa448
✨ 添加一部分代码
guohuiyuan dd1381d
✨ 添加设置AI语音模型
guohuiyuan ee2c3db
🔥 把ai声聊移动到zbputils
guohuiyuan 4d30f3d
🎨 修改权限
guohuiyuan 007ee1d
🤡测试导包
guohuiyuan 7cf6ccc
✨ 添加以语音输出
guohuiyuan afb735a
🎨 优化一下地址
guohuiyuan 4e7c0b8
Merge branch 'master' into feature-airecord-20250704
guohuiyuan c8c3cc5
✨ 添加AI声聊
guohuiyuan 7e8539c
🎨 尽量发送声音
guohuiyuan 97f36f4
✨ 修改版本号
guohuiyuan 981298e
✨ 修改权限
guohuiyuan d6e6342
Update plugin/aichat/main.go
guohuiyuan ab933df
🐛 导包问题
guohuiyuan f594161
✨ 修改为数据库
guohuiyuan f4d2392
🐛 修改接口变化
guohuiyuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // Package airecord 群应用:AI声聊 | ||
| package airecord | ||
|
|
||
| import ( | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/tidwall/gjson" | ||
|
|
||
| zero "github.com/wdvxdr1123/ZeroBot" | ||
| "github.com/wdvxdr1123/ZeroBot/message" | ||
|
|
||
| "github.com/FloatTech/AnimeAPI/airecord" | ||
| ctrl "github.com/FloatTech/zbpctrl" | ||
| "github.com/FloatTech/zbputils/control" | ||
| ) | ||
|
|
||
| func init() { | ||
| en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{ | ||
| DisableOnDefault: false, | ||
| Extra: control.ExtraFromString("airecord"), | ||
| Brief: "群应用:AI声聊", | ||
| Help: "- 设置AI语音群号1048452984(tips:机器人任意所在群聊即可)\n" + | ||
| "- 设置AI语音模型\n" + | ||
| "- 查看AI语音配置\n" + | ||
| "- 发送AI语音xxx", | ||
| PrivateDataFolder: "airecord", | ||
| }) | ||
|
|
||
| en.OnPrefix("设置AI语音群号", zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true). | ||
| Handle(func(ctx *zero.Ctx) { | ||
| u := strings.TrimSpace(ctx.State["args"].(string)) | ||
| num, err := strconv.ParseInt(u, 10, 64) | ||
| if err != nil { | ||
| ctx.SendChain(message.Text("ERROR: parse gid err: ", err)) | ||
| return | ||
| } | ||
| err = airecord.SetCustomGID(num) | ||
| if err != nil { | ||
| ctx.SendChain(message.Text("ERROR: set gid err: ", err)) | ||
| return | ||
| } | ||
| ctx.SendChain(message.Text("设置AI语音群号为", num)) | ||
| }) | ||
| en.OnFullMatch("设置AI语音模型", zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true). | ||
| Handle(func(ctx *zero.Ctx) { | ||
| next := zero.NewFutureEvent("message", 999, false, ctx.CheckSession()) | ||
| recv, cancel := next.Repeat() | ||
| defer cancel() | ||
| jsonData := ctx.GetAICharacters(0, 1) | ||
|
|
||
| // 转换为字符串数组 | ||
| var names []string | ||
| // 初始化两个映射表 | ||
| nameToID := make(map[string]string) | ||
| nameToURL := make(map[string]string) | ||
| characters := jsonData.Get("#.characters") | ||
|
|
||
| // 遍历每个角色对象 | ||
| characters.ForEach(func(_, group gjson.Result) bool { | ||
| group.ForEach(func(_, character gjson.Result) bool { | ||
| // 提取当前角色的三个字段 | ||
| name := character.Get("character_name").String() | ||
| names = append(names, name) | ||
| // 存入映射表(重复名称会覆盖,保留最后出现的条目) | ||
| nameToID[name] = character.Get("character_id").String() | ||
| nameToURL[name] = character.Get("preview_url").String() | ||
| return true // 继续遍历 | ||
| }) | ||
| return true // 继续遍历 | ||
| }) | ||
| var builder strings.Builder | ||
| // 写入开头文本 | ||
| builder.WriteString("请选择语音模型序号:\n") | ||
|
|
||
| // 遍历names数组,拼接序号和名称 | ||
| for i, v := range names { | ||
| // 将数字转换为字符串(不依赖fmt) | ||
| numStr := strconv.Itoa(i) | ||
| // 拼接格式:"序号. 名称\n" | ||
| builder.WriteString(numStr) | ||
| builder.WriteString(". ") | ||
| builder.WriteString(v) | ||
| builder.WriteString("\n") | ||
| } | ||
| // 获取最终字符串 | ||
| ctx.SendChain(message.Text(builder.String())) | ||
| for { | ||
| select { | ||
| case <-time.After(time.Second * 120): | ||
| ctx.SendChain(message.Text("设置AI语音模型指令过期")) | ||
| return | ||
| case ct := <-recv: | ||
| msg := ct.Event.Message.ExtractPlainText() | ||
| num, err := strconv.Atoi(msg) | ||
| if err != nil { | ||
| ctx.SendChain(message.Text("请输入数字!")) | ||
| continue | ||
| } | ||
| if num < 0 || num >= len(names) { | ||
| ctx.SendChain(message.Text("序号非法!")) | ||
| continue | ||
| } | ||
| err = airecord.SetRecordModel(names[num], nameToID[names[num]]) | ||
| if err != nil { | ||
| ctx.SendChain(message.Text("ERROR: set model err: ", err)) | ||
| continue | ||
| } | ||
| ctx.SendChain(message.Text("已选择语音模型: ", names[num])) | ||
| ctx.SendChain(message.Record(nameToURL[names[num]])) | ||
| return | ||
| } | ||
| } | ||
| }) | ||
| en.OnFullMatch("查看AI语音配置", zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true). | ||
| Handle(func(ctx *zero.Ctx) { | ||
| ctx.SendChain(message.Text(airecord.PrintRecordConfig())) | ||
| }) | ||
| en.OnPrefix("发送AI语音", zero.UserOrGrpAdmin).SetBlock(true). | ||
| Handle(func(ctx *zero.Ctx) { | ||
| u := strings.TrimSpace(ctx.State["args"].(string)) | ||
| recCfg := airecord.GetConfig() | ||
| record := ctx.GetAIRecord(recCfg.ModelID, recCfg.Customgid, u) | ||
| if record == "" { | ||
| id := ctx.SendGroupAIRecord(recCfg.ModelID, ctx.Event.GroupID, u) | ||
| if id == "" { | ||
| ctx.SendChain(message.Text("ERROR: get record err: empty record")) | ||
| return | ||
| } | ||
| } | ||
| ctx.SendChain(message.Record(record)) | ||
| }) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.