@@ -426,25 +426,20 @@ func init() {
426
426
var query string
427
427
var replyContent string
428
428
429
- // 检查是否是回复消息
430
- if strings .Contains (text , "[CQ:reply," ) {
431
- // 提取被回复的消息ID
432
- start := strings .Index (text , "[CQ:reply,id=" )
433
- if start != - 1 {
434
- idStart := start + len ("[CQ:reply,id=" )
435
- idEnd := strings .IndexAny (text [idStart :], ",]" )
436
- if idEnd != - 1 {
437
- idEnd += idStart
438
- replyIDStr := text [idStart :idEnd ]
439
- replyID , err := strconv .ParseInt (replyIDStr , 10 , 64 )
440
- if err == nil {
441
- // 获取被回复的消息内容
442
- replyMsg := ctx .GetMessage (replyID )
443
- if replyMsg .Elements != nil {
444
- replyContent = message .Message (replyMsg .Elements ).ExtractPlainText ()
445
- }
429
+ // 检查是否是回复消息 (使用MessageElement检查而不是CQ码)
430
+ for _ , elem := range ctx .Event .Message {
431
+ if elem .Type == "reply" {
432
+ // 提取被回复的消息ID
433
+ replyIDStr := elem .Data ["id" ]
434
+ replyID , err := strconv .ParseInt (replyIDStr , 10 , 64 )
435
+ if err == nil {
436
+ // 获取被回复的消息内容
437
+ replyMsg := ctx .GetMessage (replyID )
438
+ if replyMsg .Elements != nil {
439
+ replyContent = message .Message (replyMsg .Elements ).ExtractPlainText ()
446
440
}
447
441
}
442
+ break // 找到回复元素后退出循环
448
443
}
449
444
}
450
445
@@ -456,14 +451,15 @@ func init() {
456
451
gContent = strings .TrimSpace (parts [1 ])
457
452
}
458
453
459
- // 组合内容:如果有回复内容,则使用回复内容 + /g 内容;否则只使用 /g 内容
460
- if replyContent != "" && gContent != "" {
454
+ // 组合内容:优先使用回复内容,如果同时有/gpt内容则拼接
455
+ switch {
456
+ case replyContent != "" && gContent != "" :
461
457
query = replyContent + "\n " + gContent
462
- } else if replyContent != "" {
458
+ case replyContent != "" :
463
459
query = replyContent
464
- } else if gContent != "" {
460
+ case gContent != "" :
465
461
query = gContent
466
- } else {
462
+ default :
467
463
return
468
464
}
469
465
0 commit comments