diff --git a/Lagrange.Core/Message/Entity/RecordEntity.cs b/Lagrange.Core/Message/Entity/RecordEntity.cs index 74d563481..1319cc786 100644 --- a/Lagrange.Core/Message/Entity/RecordEntity.cs +++ b/Lagrange.Core/Message/Entity/RecordEntity.cs @@ -1,4 +1,5 @@ using Lagrange.Core.Internal.Packets.Message.Component; +using Lagrange.Core.Internal.Packets.Message.Component.Extra; using Lagrange.Core.Internal.Packets.Message.Element; using Lagrange.Core.Internal.Packets.Message.Element.Implementation; using Lagrange.Core.Internal.Packets.Service.Oidb.Common; @@ -12,12 +13,14 @@ public class RecordEntity : IMessageEntity { public int AudioLength { get; set; } + [Obsolete] public string FilePath { get; set; } = string.Empty; public byte[] AudioMd5 { get; set; } = Array.Empty(); public string AudioName { get; set; } = string.Empty; + [Obsolete] public int AudioSize { get; } public string AudioUrl { get; set; } = string.Empty; @@ -38,24 +41,23 @@ public class RecordEntity : IMessageEntity internal RecordEntity() { } - public RecordEntity(string filePath, int audioLength = 0) + public RecordEntity(string audioUuid, string audioName, byte[] audioMd5, string audioUrl) { - FilePath = filePath; - AudioStream = new Lazy(() => new FileStream(filePath, FileMode.Open, FileAccess.Read)); - AudioLength = audioLength; - AudioSize = (int)new System.IO.FileInfo(filePath).Length; + AudioUuid = audioUuid; + AudioName = audioName; + AudioMd5 = audioMd5; + AudioUrl = audioUrl; } + public RecordEntity(string filePath, int audioLength = 0) : this(File.ReadAllBytes(filePath), audioLength) { } + public RecordEntity(byte[] file, int audioLength = 0) { - FilePath = string.Empty; + // We should first determine whether the parameters are valid + if (file == null) throw new ArgumentNullException(nameof(file)); + AudioStream = new Lazy(() => new MemoryStream(file)); AudioLength = audioLength; - if (file == null) - { - throw new ArgumentNullException(nameof(file)); - } - AudioSize = file.Length; } internal RecordEntity(string audioUuid, string audioName, byte[] audioMd5) @@ -104,4 +106,4 @@ IEnumerable IMessageEntity.PackElement() public string ToPreviewString() => $"[{nameof(RecordEntity)}: {AudioUrl}]"; public string ToPreviewText() => "[语音]"; -} +} \ No newline at end of file