refactor: 优化 SendMsg 函数中的消息处理逻辑,使用类型断言提升代码灵活性和可读性

This commit is contained in:
lixiangwuxian 2025-05-05 03:25:07 +08:00
parent 26b8d2b03a
commit 7b664f436b

View File

@ -45,11 +45,11 @@ func (am *actionManager) SendMsg(reply *model.Reply) error {
ID: int(reply.FromMsg.OriginMsgId), ID: int(reply.FromMsg.OriginMsgId),
}, },
} }
switch reply.ReplyMsg.(type) { switch replyMsgVal := reply.ReplyMsg.(type) {
case []any: case []any:
reply.ReplyMsg = append([]any{replyMsg}, reply.ReplyMsg) reply.ReplyMsg = append([]any{replyMsg}, replyMsgVal...)
case string: case string:
reply.ReplyMsg = fmt.Sprintf("%s%s", replyMsg.ToCQString(), reply.ReplyMsg) reply.ReplyMsg = fmt.Sprintf("%s%s", replyMsg.ToCQString(), replyMsgVal)
} }
} }
userID := strconv.FormatInt(reply.FromMsg.UserId, 10) userID := strconv.FormatInt(reply.FromMsg.UserId, 10)