Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sisi0318 committed Sep 5, 2024
1 parent 396080b commit dd8613d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions Lagrange.Core/Message/Entity/RecordEntity.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<byte>();

public string AudioName { get; set; } = string.Empty;

[Obsolete]
public int AudioSize { get; }

public string AudioUrl { get; set; } = string.Empty;
Expand All @@ -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<Stream>(() => 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<Stream>(() => new MemoryStream(file));
AudioLength = audioLength;
if (file == null)
{
throw new ArgumentNullException(nameof(file));
}
AudioSize = file.Length;
}

internal RecordEntity(string audioUuid, string audioName, byte[] audioMd5)
Expand Down Expand Up @@ -104,4 +106,4 @@ IEnumerable<Elem> IMessageEntity.PackElement()
public string ToPreviewString() => $"[{nameof(RecordEntity)}: {AudioUrl}]";

public string ToPreviewText() => "[语音]";
}
}

0 comments on commit dd8613d

Please sign in to comment.