Skip to content

Commit

Permalink
[OneBot] Implemented upload_group_file API
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan04 committed Mar 2, 2024
1 parent 4d0af92 commit 09caec4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Lagrange.OneBot/Core/Entity/Action/OneBotUploadGroupFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Text.Json.Serialization;

namespace Lagrange.OneBot.Core.Entity.Action;

[Serializable]
public class OneBotUploadGroupFile
{
[JsonPropertyName("group_id")] public uint GroupId { get; set; }

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

[JsonPropertyName("name")] public string? Name { get; set; }

[JsonPropertyName("folder")] public string Folder { get; set; } = string.Empty;
}
26 changes: 26 additions & 0 deletions Lagrange.OneBot/Core/Operation/Message/UploadGroupFileOperation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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;

namespace Lagrange.OneBot.Core.Operation.Message;

[Operation("upload_group_file")]
public class UploadGroupFileOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
{
if (payload.Deserialize<OneBotUploadGroupFile>() is { } file)
{
var entity = new FileEntity(file.File);
if (file.Name != null) entity.FileName = file.Name; // TODO: Implement Folder Parameter

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

throw new Exception();
}
}

0 comments on commit 09caec4

Please sign in to comment.