Skip to content

Commit

Permalink
[All] Add RenameGroupFolderOp (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
pk5ls20 authored Aug 26, 2024
1 parent 02d160a commit 361252c
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Lagrange.Core/Common/Interface/Api/GroupExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public static Task<bool> 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<bool> GroupFSUpload(this BotContext bot, uint groupUin, FileEntity fileEntity, string targetDirectory = "/")
=> bot.ContextCollection.Business.OperationLogic.GroupFSUpload(groupUin, fileEntity, targetDirectory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ public async Task<bool> 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<bool> GroupFSUpload(uint groupUin, FileEntity fileEntity, string targetDirectory)
{
try
Expand Down
28 changes: 28 additions & 0 deletions Lagrange.Core/Internal/Event/Action/GroupFSRenameFolderEvent.cs
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;

#pragma warning disable CS8618
// ReSharper disable InconsistentNaming

/// <summary>
/// Delete Folder
/// </summary>
[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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
Original file line number Diff line number Diff line change
@@ -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<GroupFSRenameFolderEvent>
{
protected override bool Build(GroupFSRenameFolderEvent input, BotKeystore keystore, BotAppInfo appInfo,
BotDeviceInfo device, out Span<byte> output, out List<Memory<byte>>? extraPackets)
{
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x6D7_2>(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<byte> input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out GroupFSRenameFolderEvent output, out List<ProtocolEvent>? extraEvents)
{
var packet = Serializer.Deserialize<OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x6D7Response>>(input);

output = GroupFSRenameFolderEvent.Result(packet.Body.Rename.Retcode, packet.Body.Rename.RetMsg);
extraEvents = null;
return true;
}
}
13 changes: 13 additions & 0 deletions Lagrange.OneBot/Core/Entity/Action/OneBotRenameFolder.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 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;
}
15 changes: 15 additions & 0 deletions Lagrange.OneBot/Core/Operation/File/GroupFSOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ public async Task<OneBotResult> 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<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 comments on commit 361252c

Please sign in to comment.