Skip to content

Commit ee2c3db

Browse files
committed
🔥 把ai声聊移动到zbputils
1 parent dd1381d commit ee2c3db

File tree

2 files changed

+4
-86
lines changed

2 files changed

+4
-86
lines changed

plugin/aichat/cfg.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import (
1414
"github.com/wdvxdr1123/ZeroBot/message"
1515
)
1616

17-
var cfg = newconfig()
17+
var (
18+
cfg = newconfig()
19+
)
1820

1921
type config struct {
2022
ModelName string

plugin/aichat/main.go

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import (
55
"math/rand"
66
"strconv"
77
"strings"
8-
"time"
98

109
"github.com/fumiama/deepinfra"
1110
"github.com/fumiama/deepinfra/model"
1211
"github.com/sirupsen/logrus"
13-
"github.com/tidwall/gjson"
1412

1513
zero "github.com/wdvxdr1123/ZeroBot"
1614
"github.com/wdvxdr1123/ZeroBot/message"
@@ -42,10 +40,7 @@ var (
4240
"- 设置AI聊天最大长度4096\n" +
4341
"- 设置AI聊天TopP 0.9\n" +
4442
"- 查看AI聊天配置\n" +
45-
"- [启用|禁用]AI语音\n" +
46-
"- 设置AI语音群号1048452984 (tips:群里必须有AI声聊应用)\n" +
47-
"- 设置AI语音模型\n" +
48-
"- 发送AI语音xxx",
43+
"- [启用|禁用]AI语音\n",
4944
PrivateDataFolder: "aichat",
5045
})
5146
)
@@ -56,8 +51,6 @@ var (
5651
"OLLaMA": 1,
5752
"GenAI": 2,
5853
}
59-
customgid = int64(1048452984)
60-
modelName = "lucy-voice-xueling"
6154
)
6255

6356
func init() {
@@ -284,81 +277,4 @@ func init() {
284277
Handle(func(ctx *zero.Ctx) {
285278
ctx.SendChain(message.Text(printConfig(cfg)))
286279
})
287-
en.OnPrefix("设置AI语音群号", zero.SuperUserPermission).SetBlock(true).
288-
Handle(func(ctx *zero.Ctx) {
289-
u := strings.TrimSpace(ctx.State["args"].(string))
290-
num, err := strconv.ParseInt(u, 10, 64)
291-
if err != nil {
292-
ctx.SendChain(message.Text("ERROR: parse gid err: ", err))
293-
return
294-
}
295-
ctx.SendChain(message.Text("设置AI语音群号为", num))
296-
customgid = num
297-
})
298-
en.OnFullMatch("设置AI语音模型", zero.SuperUserPermission).SetBlock(true).
299-
Handle(func(ctx *zero.Ctx) {
300-
next := zero.NewFutureEvent("message", 999, false, ctx.CheckSession())
301-
recv, cancel := next.Repeat()
302-
defer cancel()
303-
jsonData := ctx.GetAICharacters(customgid, 1)
304-
305-
// 转换为字符串数组
306-
var names []string
307-
// 初始化两个映射表
308-
nameToID := make(map[string]string)
309-
nameToURL := make(map[string]string)
310-
characters := jsonData.Get("#.characters")
311-
312-
// 遍历每个角色对象
313-
characters.ForEach(func(_, group gjson.Result) bool {
314-
group.ForEach(func(_, character gjson.Result) bool {
315-
// 提取当前角色的三个字段
316-
name := character.Get("character_name").String()
317-
names = append(names, name)
318-
// 存入映射表(重复名称会覆盖,保留最后出现的条目)
319-
nameToID[name] = character.Get("character_id").String()
320-
nameToURL[name] = character.Get("preview_url").String()
321-
return true // 继续遍历
322-
})
323-
return true // 继续遍历
324-
})
325-
var builder strings.Builder
326-
// 写入开头文本
327-
builder.WriteString("请选择语音模型序号:\n")
328-
329-
// 遍历names数组,拼接序号和名称
330-
for i, v := range names {
331-
// 将数字转换为字符串(不依赖fmt)
332-
numStr := strconv.Itoa(i)
333-
// 拼接格式:"序号. 名称\n"
334-
builder.WriteString(numStr)
335-
builder.WriteString(". ")
336-
builder.WriteString(v)
337-
builder.WriteString("\n")
338-
}
339-
// 获取最终字符串
340-
ctx.SendChain(message.Text(builder.String()))
341-
for {
342-
select {
343-
case <-time.After(time.Second * 120):
344-
ctx.SendChain(message.Text("设置AI语音模型指令过期"))
345-
return
346-
case c := <-recv:
347-
msg := c.Event.Message.ExtractPlainText()
348-
num, err := strconv.Atoi(msg)
349-
if err != nil {
350-
ctx.SendChain(message.Text("请输入数字!"))
351-
continue
352-
}
353-
if num < 0 || num >= len(names) {
354-
ctx.SendChain(message.Text("序号非法!"))
355-
continue
356-
}
357-
modelName = nameToID[names[num]]
358-
ctx.SendChain(message.Text("已选择语音模型: ", names[num]))
359-
ctx.SendChain(message.Record(nameToURL[names[num]]))
360-
return
361-
}
362-
}
363-
})
364280
}

0 commit comments

Comments
 (0)