@@ -5,12 +5,10 @@ import (
5
5
"math/rand"
6
6
"strconv"
7
7
"strings"
8
- "time"
9
8
10
9
"github.com/fumiama/deepinfra"
11
10
"github.com/fumiama/deepinfra/model"
12
11
"github.com/sirupsen/logrus"
13
- "github.com/tidwall/gjson"
14
12
15
13
zero "github.com/wdvxdr1123/ZeroBot"
16
14
"github.com/wdvxdr1123/ZeroBot/message"
42
40
"- 设置AI聊天最大长度4096\n " +
43
41
"- 设置AI聊天TopP 0.9\n " +
44
42
"- 查看AI聊天配置\n " +
45
- "- [启用|禁用]AI语音\n " +
46
- "- 设置AI语音群号1048452984 (tips:群里必须有AI声聊应用)\n " +
47
- "- 设置AI语音模型\n " +
48
- "- 发送AI语音xxx" ,
43
+ "- [启用|禁用]AI语音\n " ,
49
44
PrivateDataFolder : "aichat" ,
50
45
})
51
46
)
56
51
"OLLaMA" : 1 ,
57
52
"GenAI" : 2 ,
58
53
}
59
- customgid = int64 (1048452984 )
60
- modelName = "lucy-voice-xueling"
61
54
)
62
55
63
56
func init () {
@@ -284,81 +277,4 @@ func init() {
284
277
Handle (func (ctx * zero.Ctx ) {
285
278
ctx .SendChain (message .Text (printConfig (cfg )))
286
279
})
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
- })
364
280
}
0 commit comments