-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OneBot] Implemented upload_private_file
- Loading branch information
1 parent
92da94f
commit f46fda0
Showing
3 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
Lagrange.OneBot/Core/Entity/Action/OneBotUploadPrivateFile.cs
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,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; } | ||
} |
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
27 changes: 27 additions & 0 deletions
27
Lagrange.OneBot/Core/Operation/Message/UploadPrivateFileOperation.cs
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,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(); | ||
} | ||
} |