refactor: 优化 SendMsg 函数中的消息处理逻辑,支持不同类型的 ReplyMsg,提升代码灵活性和可读性

This commit is contained in:
lixiangwuxian 2025-05-05 02:53:59 +08:00
parent 5f8609bef2
commit 26b8d2b03a

View File

@ -2,6 +2,7 @@ package action
import ( import (
"encoding/json" "encoding/json"
"fmt"
"log" "log"
"strconv" "strconv"
"sync" "sync"
@ -44,7 +45,12 @@ func (am *actionManager) SendMsg(reply *model.Reply) error {
ID: int(reply.FromMsg.OriginMsgId), ID: int(reply.FromMsg.OriginMsgId),
}, },
} }
reply.ReplyMsg = append([]any{replyMsg}, reply.ReplyMsg) switch reply.ReplyMsg.(type) {
case []any:
reply.ReplyMsg = append([]any{replyMsg}, reply.ReplyMsg)
case string:
reply.ReplyMsg = fmt.Sprintf("%s%s", replyMsg.ToCQString(), reply.ReplyMsg)
}
} }
userID := strconv.FormatInt(reply.FromMsg.UserId, 10) userID := strconv.FormatInt(reply.FromMsg.UserId, 10)
if reply.FromMsg.UserId == 0 { if reply.FromMsg.UserId == 0 {