submodule对gitea不管用,所以直接拉了一份拉格兰
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.Core.Common.Entity;
|
||||
using Lagrange.Core.Common.Interface.Api;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Entity.Action.Response;
|
||||
using Lagrange.OneBot.Core.Entity.File;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
using Lagrange.OneBot.Utility;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.File;
|
||||
|
||||
[Operation("get_group_file_url")]
|
||||
public class GetGroupFileUrlOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotGetFileUrl>(SerializerOptions.DefaultOptions) is { } url)
|
||||
{
|
||||
string raw = await context.FetchGroupFSDownload(url.GroupId, url.FileId);
|
||||
return new OneBotResult(new JsonObject { { "url", raw } }, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[Operation("get_group_root_files")]
|
||||
[Operation("get_group_files_by_folder")]
|
||||
public class GetGroupRootFilesOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotGetFiles>(SerializerOptions.DefaultOptions) is { } file)
|
||||
{
|
||||
var entries = await context.FetchGroupFSList(file.GroupId, file.FolderId ?? "/");
|
||||
var files = new List<OneBotFile>();
|
||||
var folders = new List<OneBotFolder>();
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
switch (entry)
|
||||
{
|
||||
case BotFileEntry fileEntry:
|
||||
{
|
||||
var members = await context.FetchMembers(file.GroupId);
|
||||
var member = members.FirstOrDefault(x => x.Uin == fileEntry.UploaderUin);
|
||||
files.Add(new OneBotFile
|
||||
{
|
||||
GroupId = file.GroupId,
|
||||
FileId = fileEntry.FileId,
|
||||
FileName = fileEntry.FileName,
|
||||
BusId = 0,
|
||||
FileSize = fileEntry.FileSize,
|
||||
UploadTime = fileEntry.UploadedTime.ToTimestamp(),
|
||||
DeadTime = fileEntry.ExpireTime.ToTimestamp(),
|
||||
ModifyTime = fileEntry.ModifiedTime.ToTimestamp(),
|
||||
DownloadTimes = fileEntry.DownloadedTimes,
|
||||
Uploader = fileEntry.UploaderUin,
|
||||
UploaderName = member?.MemberName ?? string.Empty
|
||||
});
|
||||
break;
|
||||
}
|
||||
case BotFolderEntry folderEntry:
|
||||
{
|
||||
var members = await context.FetchMembers(file.GroupId);
|
||||
var member = members.FirstOrDefault(x => x.Uin == folderEntry.CreatorUin);
|
||||
folders.Add(new OneBotFolder
|
||||
{
|
||||
GroupId = file.GroupId,
|
||||
FolderId = folderEntry.FolderId,
|
||||
FolderName = folderEntry.FolderName,
|
||||
CreateTime = folderEntry.CreateTime.ToTimestamp(),
|
||||
Creator = folderEntry.CreatorUin,
|
||||
CreatorName = member?.MemberName ?? string.Empty,
|
||||
TotalFileCount = folderEntry.TotalFileCount
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new OneBotResult(new OneBotGetFilesResponse(files, folders), 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[Operation("move_group_file")]
|
||||
public class MoveGroupFileOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotMoveFile>(SerializerOptions.DefaultOptions) is { } file)
|
||||
{
|
||||
var res = await context.GroupFSMove(file.GroupId, file.FileId, file.ParentDirectory, file.TargetDirectory);
|
||||
return new OneBotResult(new JsonObject { { "msg", res.Item2 } }, res.Item1, res.Item1 == 0 ? "ok" : "failed");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[Operation("delete_group_file")]
|
||||
public class DeleteGroupFileOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotDeleteFile>(SerializerOptions.DefaultOptions) is { } file)
|
||||
{
|
||||
var res = await context.GroupFSDelete(file.GroupId, file.FileId);
|
||||
return new OneBotResult(new JsonObject { { "msg", res.Item2 } }, res.Item1, res.Item1 == 0 ? "ok" : "failed");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[Operation("create_group_file_folder")]
|
||||
public class CreateGroupFileFolderOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotCreateFolder>(SerializerOptions.DefaultOptions) is { } folder)
|
||||
{
|
||||
var res = await context.GroupFSCreateFolder(folder.GroupId, folder.Name);
|
||||
return new OneBotResult(new JsonObject { { "msg", res.Item2 } }, res.Item1, res.Item1 == 0 ? "ok" : "failed");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[Operation("delete_group_file_folder")]
|
||||
public class DeleteGroupFileFolderOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotDeleteFolder>(SerializerOptions.DefaultOptions) is { } folder)
|
||||
{
|
||||
var res = await context.GroupFSDeleteFolder(folder.GroupId, folder.FolderId);
|
||||
return new OneBotResult(new JsonObject { { "msg", res.Item2 } }, res.Item1, res.Item1 == 0 ? "ok" : "failed");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[Operation("rename_group_file_folder")]
|
||||
public class RenameGroupFileFolderOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotRenameFolder>(SerializerOptions.DefaultOptions) is { } folder)
|
||||
{
|
||||
var res = await context.GroupFSRenameFolder(folder.GroupId, folder.FolderId, folder.NewFolderName);
|
||||
return new OneBotResult(new JsonObject { { "msg", res.Item2 } }, res.Item1, res.Item1 == 0 ? "ok" : "failed");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.Core.Common.Interface.Api;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.File;
|
||||
|
||||
[Operation("get_private_file_url")]
|
||||
public class GetPrivateFileUrlOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotGetPrivateFile>(SerializerOptions.DefaultOptions) is { } url)
|
||||
{
|
||||
string raw = await context.FetchPrivateFSDownload(url.FileId, url.FileHash, url.UserId);
|
||||
return new OneBotResult(new JsonObject { { "url", raw } }, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -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.File;
|
||||
|
||||
[Operation("upload_group_file")]
|
||||
public class UploadGroupFileOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotUploadGroupFile>(SerializerOptions.DefaultOptions) is { } file)
|
||||
{
|
||||
var entity = new FileEntity(file.File);
|
||||
if (file.Name != null) entity.FileName = file.Name;
|
||||
|
||||
bool result = await context.GroupFSUpload(file.GroupId, entity, file.Folder ?? "/");
|
||||
return new OneBotResult(null, result ? 0 : 1, result ? "ok" : "failed");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -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.File;
|
||||
|
||||
[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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user