diff --git a/Lagrange.Core/Common/Interface/Api/GroupExt.cs b/Lagrange.Core/Common/Interface/Api/GroupExt.cs index 91dbca303..86d765464 100644 --- a/Lagrange.Core/Common/Interface/Api/GroupExt.cs +++ b/Lagrange.Core/Common/Interface/Api/GroupExt.cs @@ -113,6 +113,9 @@ public static Task GroupFSDelete(this BotContext bot, uint groupUin, strin public static Task<(int, string)> GroupFSDeleteFolder(this BotContext bot, uint groupUin, string folderId) => bot.ContextCollection.Business.OperationLogic.GroupFSDeleteFolder(groupUin, folderId); + public static Task<(int, string)> GroupFSRenameFolder(this BotContext bot, uint groupUin, string folderId, string newFolderName) + => bot.ContextCollection.Business.OperationLogic.GroupFSRenameFolder(groupUin, folderId, newFolderName); + public static Task GroupFSUpload(this BotContext bot, uint groupUin, FileEntity fileEntity, string targetDirectory = "/") => bot.ContextCollection.Business.OperationLogic.GroupFSUpload(groupUin, fileEntity, targetDirectory); diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs index 5fa9c786b..2e38a6107 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs @@ -182,6 +182,15 @@ public async Task GroupFSDelete(uint groupUin, string fileId) return new(retCode, retMsg); } + public async Task<(int, string)> GroupFSRenameFolder(uint groupUin, string folderId, string newFolderName) + { + var groupFSDeleteFolderEvent = GroupFSRenameFolderEvent.Create(groupUin, folderId, newFolderName); + var events = await Collection.Business.SendEvent(groupFSDeleteFolderEvent); + var retCode = events.Count > 0 ? ((GroupFSRenameFolderEvent)events[0]).ResultCode : -1; + var retMsg = events.Count > 0 ? ((GroupFSRenameFolderEvent)events[0]).RetMsg : ""; + return new(retCode, retMsg); + } + public Task GroupFSUpload(uint groupUin, FileEntity fileEntity, string targetDirectory) { try diff --git a/Lagrange.Core/Internal/Event/Action/GroupFSRenameFolderEvent.cs b/Lagrange.Core/Internal/Event/Action/GroupFSRenameFolderEvent.cs new file mode 100644 index 000000000..259c4c8f8 --- /dev/null +++ b/Lagrange.Core/Internal/Event/Action/GroupFSRenameFolderEvent.cs @@ -0,0 +1,28 @@ +namespace Lagrange.Core.Internal.Event.Action; + +internal class GroupFSRenameFolderEvent : ProtocolEvent +{ + public uint GroupUin { get; } + + public string FolderId { get; } = string.Empty; + + public string NewFolderName { get; } = string.Empty; + + public string RetMsg { get; set; } = string.Empty; + + private GroupFSRenameFolderEvent(uint groupUin, string folderId, string newFolderName) : base(true) + { + GroupUin = groupUin; + FolderId = folderId; + NewFolderName = newFolderName; + } + + private GroupFSRenameFolderEvent(int resultCode, string retMsg) : base(resultCode) + { + RetMsg = retMsg; + } + + public static GroupFSRenameFolderEvent Create(uint groupUin, string folderId, string newFolderName) => new(groupUin, folderId, newFolderName); + + public static GroupFSRenameFolderEvent Result(int resultCode, string retMsg) => new(resultCode, retMsg); +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x6D7_2.cs b/Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x6D7_2.cs new file mode 100644 index 000000000..5ee84ac14 --- /dev/null +++ b/Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x6D7_2.cs @@ -0,0 +1,26 @@ +using ProtoBuf; + +namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request; + +#pragma warning disable CS8618 +// ReSharper disable InconsistentNaming + +/// +/// Delete Folder +/// +[ProtoContract] +[OidbSvcTrpcTcp(0x6D7, 2)] +internal class OidbSvcTrpcTcp0x6D7_2 +{ + [ProtoMember(3)] public OidbSvcTrpcTcp0x6D7_2Rename Rename { get; set; } +} + +[ProtoContract] +internal class OidbSvcTrpcTcp0x6D7_2Rename +{ + [ProtoMember(1)] public uint GroupUin { get; set; } + + [ProtoMember(3)] public string FolderId { get; set; } + + [ProtoMember(4)] public string NewFolderName { get; set; } +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D7Response.cs b/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D7Response.cs index a898b54fa..344520a6f 100644 --- a/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D7Response.cs +++ b/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D7Response.cs @@ -10,5 +10,7 @@ internal class OidbSvcTrpcTcp0x6D7Response { [ProtoMember(1)] public OidbSvcTrpcTcp0x6D7_0Response Create { get; set; } - [ProtoMember(2)] public OidbSvcTrpcTcp0x6D7_1Response Delete { get; set; } + [ProtoMember(2)] public OidbSvcTrpcTcp0x6D7_1_2Response Delete { get; set; } + + [ProtoMember(3)] public OidbSvcTrpcTcp0x6D7_1_2Response Rename { get; set; } } diff --git a/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D7_1Response.cs b/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D7_1_2Response.cs similarity index 88% rename from Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D7_1Response.cs rename to Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D7_1_2Response.cs index 25e9b3757..ca45872b1 100644 --- a/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D7_1Response.cs +++ b/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D7_1_2Response.cs @@ -6,7 +6,7 @@ namespace Lagrange.Core.Internal.Packets.Service.Oidb.Response; // ReSharper disable InconsistentNaming [ProtoContract] -internal class OidbSvcTrpcTcp0x6D7_1Response +internal class OidbSvcTrpcTcp0x6D7_1_2Response { [ProtoMember(1)] public Int32 Retcode { get; set; } diff --git a/Lagrange.Core/Internal/Service/Action/GroupFSRenameFolderService.cs b/Lagrange.Core/Internal/Service/Action/GroupFSRenameFolderService.cs new file mode 100644 index 000000000..d2b3cb26e --- /dev/null +++ b/Lagrange.Core/Internal/Service/Action/GroupFSRenameFolderService.cs @@ -0,0 +1,43 @@ +using Lagrange.Core.Common; +using Lagrange.Core.Internal.Event; +using Lagrange.Core.Internal.Event.Action; +using Lagrange.Core.Internal.Packets.Service.Oidb; +using Lagrange.Core.Internal.Packets.Service.Oidb.Request; +using Lagrange.Core.Internal.Packets.Service.Oidb.Response; +using Lagrange.Core.Utility.Extension; +using ProtoBuf; + +namespace Lagrange.Core.Internal.Service.Action; + +[EventSubscribe(typeof(GroupFSRenameFolderEvent))] +[Service("OidbSvcTrpcTcp.0x6d7_2")] +internal class GroupFSRenameFolderService : BaseService +{ + protected override bool Build(GroupFSRenameFolderEvent input, BotKeystore keystore, BotAppInfo appInfo, + BotDeviceInfo device, out Span output, out List>? extraPackets) + { + var packet = new OidbSvcTrpcTcpBase(new OidbSvcTrpcTcp0x6D7_2 + { + Rename = new OidbSvcTrpcTcp0x6D7_2Rename + { + GroupUin = input.GroupUin, + FolderId = input.FolderId, + NewFolderName = input.NewFolderName + } + }, false, true); + + output = packet.Serialize(); + extraPackets = null; + return true; + } + + protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, + out GroupFSRenameFolderEvent output, out List? extraEvents) + { + var packet = Serializer.Deserialize>(input); + + output = GroupFSRenameFolderEvent.Result(packet.Body.Rename.Retcode, packet.Body.Rename.RetMsg); + extraEvents = null; + return true; + } +} \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Entity/Action/OneBotRenameFolder.cs b/Lagrange.OneBot/Core/Entity/Action/OneBotRenameFolder.cs new file mode 100644 index 000000000..dbf737fa4 --- /dev/null +++ b/Lagrange.OneBot/Core/Entity/Action/OneBotRenameFolder.cs @@ -0,0 +1,13 @@ +using System.Text.Json.Serialization; + +namespace Lagrange.OneBot.Core.Entity.Action; + +[Serializable] +public class OneBotRenameFolder +{ + [JsonPropertyName("group_id")] public uint GroupId { get; set; } + + [JsonPropertyName("folder_id")] public string FolderId { get; set; } = string.Empty; + + [JsonPropertyName("new_folder_name")] public string NewFolderName { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Operation/File/GroupFSOperations.cs b/Lagrange.OneBot/Core/Operation/File/GroupFSOperations.cs index f88cdff4f..e95531af8 100644 --- a/Lagrange.OneBot/Core/Operation/File/GroupFSOperations.cs +++ b/Lagrange.OneBot/Core/Operation/File/GroupFSOperations.cs @@ -129,6 +129,21 @@ public async Task HandleOperation(BotContext context, JsonNode? pa 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 HandleOperation(BotContext context, JsonNode? payload) + { + if (payload.Deserialize(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(); } } \ No newline at end of file