Skip to content

Commit

Permalink
[OneBot] Implemented upload_private_file
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan04 committed Mar 3, 2024
1 parent 92da94f commit f46fda0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Lagrange.OneBot/Core/Entity/Action/OneBotUploadPrivateFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Text.Json.Serialization;

namespace Lagrange.OneBot.Core.Entity.Action;

[Serializable]
public class OneBotUploadPrivateFile
{
[JsonPropertyName("user_id")] public uint UserId { get; set; }

[JsonPropertyName("file")] public string File { get; set; } = string.Empty;

[JsonPropertyName("name")] public string? Name { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Lagrange.Core.Common.Interface.Api;
using Lagrange.Core.Message.Entity;
using Lagrange.OneBot.Core.Entity.Action;
using Lagrange.OneBot.Core.Operation.Converters;

namespace Lagrange.OneBot.Core.Operation.Message;

Expand All @@ -12,7 +13,7 @@ public class UploadGroupFileOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
{
if (payload.Deserialize<OneBotUploadGroupFile>() is { } file)
if (payload.Deserialize<OneBotUploadGroupFile>(SerializerOptions.DefaultOptions) is { } file)
{
var entity = new FileEntity(file.File);
if (file.Name != null) entity.FileName = file.Name; // TODO: Implement Folder Parameter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using Lagrange.Core;
using Lagrange.Core.Common.Interface.Api;
using Lagrange.Core.Message.Entity;
using Lagrange.OneBot.Core.Entity.Action;
using Lagrange.OneBot.Core.Operation.Converters;

namespace Lagrange.OneBot.Core.Operation.Message;

[Operation("upload_private_file")]
public class UploadPrivateFile : IOperation
{
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
{
if (payload.Deserialize<OneBotUploadPrivateFile>(SerializerOptions.DefaultOptions) is { } file)
{
var entity = new FileEntity(file.File);
if (file.Name != null) entity.FileName = file.Name;

bool result = await context.UploadFriendFile(file.UserId, entity);
return new OneBotResult(null, result ? 0 : 1, result ? "ok" : "failed");
}

throw new Exception();
}
}

0 comments on commit f46fda0

Please sign in to comment.