Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OneBot] Fix private chat file message push and get_msg to get the private chat file record #706

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lagrange.Core/Message/Entity/FileEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public class FileEntity : IMessageEntity
/// </summary>
public string? FileId { get; set; }

internal string? FileUuid { get; set; }
public string? FileUuid { get; set; }

internal string? FileHash { get; set; }
public string? FileHash { get; set; }

internal Stream? FileStream { get; set; }

Expand Down
45 changes: 45 additions & 0 deletions Lagrange.OneBot/Message/Entity/FileSegment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Text.Json.Serialization;
using Lagrange.Core.Message;
using Lagrange.Core.Message.Entity;

namespace Lagrange.OneBot.Message.Entity;

[Serializable]
public partial class FileSegment(string fileName, string fileHash, string fileId, string url)
{
public FileSegment() : this("", "", "", "") { }

[JsonPropertyName("filename")] public string Filename { get; set; } = fileName;

[JsonPropertyName("filehash")] public string Filehash { get; set; } = fileHash;

[JsonPropertyName("id")] public string Fileid { get; set; } = fileId;

[JsonPropertyName("url")] public string Url { get; set; } = url;

}

[SegmentSubscriber(typeof(FileEntity), "file")]
public partial class FileSegment : SegmentBase
{
public override void Build(MessageBuilder builder, SegmentBase segment)
{
if (segment is FileSegment fileSegment and not { Fileid: "" })
{
builder.Add(new FileEntity
{
FileName = fileSegment.Filename,
FileUrl = fileSegment.Url,
FileId = fileSegment.Fileid,
FileHash = fileSegment.Filehash
});
}
}

public override SegmentBase FromEntity(MessageChain chain, IMessageEntity entity)
{
if (entity is not FileEntity fileEntity) throw new ArgumentException("Invalid entity type.");

return new FileSegment(fileEntity.FileName, fileEntity.FileHash ?? "", fileEntity.FileId ?? fileEntity.FileUuid ?? "", fileEntity.FileUrl ?? "");
}
}
Loading