-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OneBot] Fix private chat file message push and
get_msg
to get the …
…private chat file record (#706) * [OneBot] impl FileSegment Signed-off-by: ishkong <[email protected]> * [Core] Save key information needed to refresh private chat file links Signed-off-by: ishkong <[email protected]> --------- Signed-off-by: ishkong <[email protected]>
- Loading branch information
Showing
2 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ?? ""); | ||
} | ||
} |