Skip to content

Commit d8fdd52

Browse files
committed
✨ 添加lint优化
1 parent 7563158 commit d8fdd52

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

plugin/aichat/main.go

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -426,25 +426,20 @@ func init() {
426426
var query string
427427
var replyContent string
428428

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()
446440
}
447441
}
442+
break // 找到回复元素后退出循环
448443
}
449444
}
450445

@@ -456,14 +451,15 @@ func init() {
456451
gContent = strings.TrimSpace(parts[1])
457452
}
458453

459-
// 组合内容:如果有回复内容,则使用回复内容 + /g 内容;否则只使用 /g 内容
460-
if replyContent != "" && gContent != "" {
454+
// 组合内容:优先使用回复内容,如果同时有/gpt内容则拼接
455+
switch {
456+
case replyContent != "" && gContent != "":
461457
query = replyContent + "\n" + gContent
462-
} else if replyContent != "" {
458+
case replyContent != "":
463459
query = replyContent
464-
} else if gContent != "" {
460+
case gContent != "":
465461
query = gContent
466-
} else {
462+
default:
467463
return
468464
}
469465

0 commit comments

Comments
 (0)