5
5
"math/rand"
6
6
"strconv"
7
7
"strings"
8
+ "time"
8
9
9
10
"github.com/fumiama/deepinfra"
10
11
"github.com/fumiama/deepinfra/model"
40
41
"- 设置AI聊天(不)响应AT\n " +
41
42
"- 设置AI聊天最大长度4096\n " +
42
43
"- 设置AI聊天TopP 0.9\n " +
43
- "- 设置AI语音群号1048452984 (tips:群里必须有AI声聊应用) \n " +
44
+ "- 查看AI聊天配置 \n " +
44
45
"- [启用|禁用]AI语音\n " +
46
+ "- 设置AI语音群号1048452984 (tips:群里必须有AI声聊应用)\n " +
45
47
"- 设置AI语音模型\n " +
46
48
"- 发送AI语音xxx" ,
47
49
PrivateDataFolder : "aichat" ,
@@ -278,6 +280,10 @@ func init() {
278
280
Handle (newextrasetuint (& cfg .MaxN ))
279
281
en .OnPrefix ("设置AI聊天TopP" , ensureconfig , zero .OnlyPrivate , zero .SuperUserPermission ).SetBlock (true ).
280
282
Handle (newextrasetfloat32 (& cfg .TopP ))
283
+ en .OnFullMatch ("查看AI聊天配置" , ensureconfig , zero .SuperUserPermission ).SetBlock (true ).
284
+ Handle (func (ctx * zero.Ctx ) {
285
+ ctx .SendChain (message .Text (printConfig (cfg )))
286
+ })
281
287
en .OnPrefix ("设置AI语音群号" , zero .SuperUserPermission ).SetBlock (true ).
282
288
Handle (func (ctx * zero.Ctx ) {
283
289
u := strings .TrimSpace (ctx .State ["args" ].(string ))
@@ -291,36 +297,39 @@ func init() {
291
297
})
292
298
en .OnFullMatch ("设置AI语音模型" , zero .SuperUserPermission ).SetBlock (true ).
293
299
Handle (func (ctx * zero.Ctx ) {
300
+ next := zero .NewFutureEvent ("message" , 999 , false , ctx .CheckSession ())
301
+ recv , cancel := next .Repeat ()
302
+ defer cancel ()
294
303
jsonData := ctx .GetAICharacters (customgid , 1 )
295
304
296
305
// 转换为字符串数组
297
306
var names []string
298
307
// 初始化两个映射表
299
308
nameToID := make (map [string ]string )
300
309
nameToURL := make (map [string ]string )
301
- characters := jsonData .Get ("#.characters.# " )
310
+ characters := jsonData .Get ("#.characters" )
302
311
303
312
// 遍历每个角色对象
304
- characters .ForEach (func (_ , character gjson.Result ) bool {
305
- // 提取当前角色的三个字段
306
- name := character . Get ( "character_name" ). String ()
307
- names = append ( names , name )
308
- id := character . Get ( "character_id" ). String ( )
309
- url := character . Get ( "preview_url" ). String ()
310
-
311
- // 存入映射表(重复名称会覆盖,保留最后出现的条目)
312
- nameToID [ name ] = id
313
- nameToURL [ name ] = url
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
+ })
314
323
return true // 继续遍历
315
324
})
316
325
var builder strings.Builder
317
326
// 写入开头文本
318
- builder .WriteString ("请选择模型序号 :\n " )
327
+ builder .WriteString ("请选择语音模型序号 :\n " )
319
328
320
329
// 遍历names数组,拼接序号和名称
321
330
for i , v := range names {
322
331
// 将数字转换为字符串(不依赖fmt)
323
- numStr := strconv .Itoa (i + 1 )
332
+ numStr := strconv .Itoa (i )
324
333
// 拼接格式:"序号. 名称\n"
325
334
builder .WriteString (numStr )
326
335
builder .WriteString (". " )
@@ -329,5 +338,27 @@ func init() {
329
338
}
330
339
// 获取最终字符串
331
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
+ }
332
363
})
333
364
}
0 commit comments