Skip to content

Commit c4819b6

Browse files
committed
[Core] Implemented GroupFS related services
1 parent 9cff1d6 commit c4819b6

8 files changed

Lines changed: 551 additions & 1 deletion

File tree

Lagrange.Core/Common/AndroidBotSignProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ internal class DefaultAndroidBotSignProvider : AndroidBotSignProvider, IDisposab
252252
"OidbSvcTrpcTcp.0x644_1",
253253
"OidbSvcTrpcTcp.0x6d6_2",
254254
"OidbSvcTrpcTcp.0x6d6_3",
255+
"OidbSvcTrpcTcp.0x6d8_1",
255256
"OidbSvcTrpcTcp.0x6d9_2",
256257
"OidbSvcTrpcTcp.0x6d9_4",
257258
"OidbSvcTrpcTcp.0x758_1",
@@ -266,6 +267,7 @@ internal class DefaultAndroidBotSignProvider : AndroidBotSignProvider, IDisposab
266267
"OidbSvcTrpcTcp.0x899_9",
267268
"OidbSvcTrpcTcp.0x89a_0",
268269
"OidbSvcTrpcTcp.0x89a_15",
270+
"OidbSvcTrpcTcp.0x8a0_1",
269271
"OidbSvcTrpcTcp.0x8a1_7",
270272
"OidbSvcTrpcTcp.0x8f9_14",
271273
"OidbSvcTrpcTcp.0x8fc_3",
@@ -642,4 +644,4 @@ internal class SignResponse
642644

643645
[JsonPropertyName("extra")] public string Extra { get; set; } = string.Empty;
644646
}
645-
}
647+
}

Lagrange.Core/Common/BotSignProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ internal class DefaultBotSignProvider : BotSignProvider, IDisposable
267267
"OidbSvcTrpcTcp.0x644_1",
268268
"OidbSvcTrpcTcp.0x6d6_2",
269269
"OidbSvcTrpcTcp.0x6d6_3",
270+
"OidbSvcTrpcTcp.0x6d8_1",
270271
"OidbSvcTrpcTcp.0x6d9_2",
271272
"OidbSvcTrpcTcp.0x6d9_4",
272273
"OidbSvcTrpcTcp.0x758_1", // create group
@@ -281,6 +282,7 @@ internal class DefaultBotSignProvider : BotSignProvider, IDisposable
281282
"OidbSvcTrpcTcp.0x899_9",
282283
"OidbSvcTrpcTcp.0x89a_0",
283284
"OidbSvcTrpcTcp.0x89a_15",
285+
"OidbSvcTrpcTcp.0x8a0_1",
284286
"OidbSvcTrpcTcp.0x8a1_7", // request group
285287
"OidbSvcTrpcTcp.0x8f9_14",
286288
"OidbSvcTrpcTcp.0x8fc_3",
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
namespace Lagrange.Core.Common.Entity;
2+
3+
/// <summary>
4+
/// Indicates an entry in a group file system listing.
5+
/// </summary>
6+
public interface IBotFSEntry;
7+
8+
[Serializable]
9+
public class BotFileEntry : IBotFSEntry
10+
{
11+
public string FileId { get; }
12+
13+
public string FileName { get; }
14+
15+
public string ParentDirectory { get; }
16+
17+
public ulong FileSize { get; }
18+
19+
public DateTime ExpireTime { get; }
20+
21+
public DateTime ModifiedTime { get; }
22+
23+
public long UploaderUin { get; }
24+
25+
public DateTime UploadedTime { get; }
26+
27+
public uint DownloadedTimes { get; }
28+
29+
internal BotFileEntry(string fileId, string fileName, string parentDirectory, ulong fileSize, DateTime expireTime, DateTime modifiedTime, long uploaderUin, DateTime uploadedTime, uint downloadedTimes)
30+
{
31+
FileId = fileId;
32+
FileName = fileName;
33+
ParentDirectory = parentDirectory;
34+
FileSize = fileSize;
35+
ExpireTime = expireTime;
36+
ModifiedTime = modifiedTime;
37+
UploaderUin = uploaderUin;
38+
UploadedTime = uploadedTime;
39+
DownloadedTimes = downloadedTimes;
40+
}
41+
}
42+
43+
[Serializable]
44+
public class BotFolderEntry : IBotFSEntry
45+
{
46+
public string FolderId { get; }
47+
48+
public string ParentFolderId { get; }
49+
50+
public string FolderName { get; }
51+
52+
public DateTime CreateTime { get; }
53+
54+
public DateTime ModifiedTime { get; }
55+
56+
public long CreatorUin { get; }
57+
58+
public uint TotalFileCount { get; }
59+
60+
internal BotFolderEntry(string folderId, string parentFolderId, string folderName, DateTime createTime, DateTime modifiedTime, long creatorUin, uint totalFileCount)
61+
{
62+
FolderId = folderId;
63+
ParentFolderId = parentFolderId;
64+
FolderName = folderName;
65+
CreateTime = createTime;
66+
ModifiedTime = modifiedTime;
67+
CreatorUin = creatorUin;
68+
TotalFileCount = totalFileCount;
69+
}
70+
}

Lagrange.Core/Common/Interface/MessageExt.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Lagrange.Core.Common.Entity;
12
using Lagrange.Core.Internal.Logic;
23
using Lagrange.Core.Message;
34

@@ -50,6 +51,15 @@ public static Task RemoveEssenceMessage(this BotContext context, long groupUin,
5051
public static Task<string> GroupFSDownload(this BotContext context, long groupUin, string fileId)
5152
=> context.EventContext.GetLogic<OperationLogic>().GroupFSDownload(groupUin, fileId);
5253

54+
public static Task<ulong> FetchGroupFSSpace(this BotContext context, long groupUin)
55+
=> context.EventContext.GetLogic<OperationLogic>().FetchGroupFSSpace(groupUin);
56+
57+
public static Task<uint> FetchGroupFSCount(this BotContext context, long groupUin)
58+
=> context.EventContext.GetLogic<OperationLogic>().FetchGroupFSCount(groupUin);
59+
60+
public static Task<List<IBotFSEntry>> FetchGroupFSList(this BotContext context, long groupUin, string targetDirectory = "/")
61+
=> context.EventContext.GetLogic<OperationLogic>().FetchGroupFSList(groupUin, targetDirectory);
62+
5363
public static Task GroupFSDelete(this BotContext context, long groupUin, string fileId)
5464
=> context.EventContext.GetLogic<OperationLogic>().GroupFSDelete(groupUin, fileId);
5565

@@ -77,6 +87,9 @@ public static Task GroupSetSpecialTitle(this BotContext context, long groupUin,
7787
public static Task GroupMemberRename(this BotContext context, long groupUin, long targetUin, string name)
7888
=> context.EventContext.GetLogic<OperationLogic>().GroupMemberRename(groupUin, targetUin, name);
7989

90+
public static Task<bool> KickGroupMember(this BotContext context, long groupUin, long targetUin, bool rejectAddRequest, string reason = "")
91+
=> context.EventContext.GetLogic<OperationLogic>().KickGroupMember(groupUin, targetUin, rejectAddRequest, reason);
92+
8093
public static Task GroupRename(this BotContext context, long groupUin, string name)
8194
=> context.EventContext.GetLogic<OperationLogic>().GroupRename(groupUin, name);
8295

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Lagrange.Core.Common.Entity;
2+
3+
namespace Lagrange.Core.Internal.Events.Message;
4+
5+
internal abstract class GroupFSViewEventReq(long groupUin) : ProtocolEvent
6+
{
7+
public long GroupUin { get; } = groupUin;
8+
}
9+
10+
internal class GroupFSListEventReq(long groupUin, string targetDirectory, uint startIndex, uint fileCount)
11+
: GroupFSViewEventReq(groupUin)
12+
{
13+
public string TargetDirectory { get; } = targetDirectory;
14+
15+
public uint StartIndex { get; } = startIndex;
16+
17+
public uint FileCount { get; } = fileCount;
18+
}
19+
20+
internal class GroupFSCountEventReq(long groupUin) : GroupFSViewEventReq(groupUin);
21+
22+
internal class GroupFSSpaceEventReq(long groupUin) : GroupFSViewEventReq(groupUin);
23+
24+
internal abstract class GroupFSViewEventResp(int resultCode, string? retMsg) : ProtocolEvent
25+
{
26+
public int ResultCode { get; } = resultCode;
27+
28+
public string? RetMsg { get; } = retMsg;
29+
}
30+
31+
internal class GroupFSListEventResp(int resultCode, string? retMsg, List<IBotFSEntry> fileEntries, bool isEnd)
32+
: GroupFSViewEventResp(resultCode, retMsg)
33+
{
34+
public List<IBotFSEntry> FileEntries { get; } = fileEntries;
35+
36+
public bool IsEnd { get; } = isEnd;
37+
}
38+
39+
internal class GroupFSCountEventResp(int resultCode, string? retMsg, uint fileCount, uint limitCount, bool isFull)
40+
: GroupFSViewEventResp(resultCode, retMsg)
41+
{
42+
public uint FileCount { get; } = fileCount;
43+
44+
public uint LimitCount { get; } = limitCount;
45+
46+
public bool IsFull { get; } = isFull;
47+
}
48+
49+
internal class GroupFSSpaceEventResp(int resultCode, string? retMsg, ulong totalSpace, ulong usedSpace)
50+
: GroupFSViewEventResp(resultCode, retMsg)
51+
{
52+
public ulong TotalSpace { get; } = totalSpace;
53+
54+
public ulong UsedSpace { get; } = usedSpace;
55+
}

Lagrange.Core/Internal/Logic/OperationLogic.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,42 @@ public async Task<string> GroupFSDownload(long groupUin, string fileId)
134134
return response.FileUrl;
135135
}
136136

137+
public async Task<ulong> FetchGroupFSSpace(long groupUin)
138+
{
139+
var response = await context.EventContext.SendEvent<GroupFSSpaceEventResp>(new GroupFSSpaceEventReq(groupUin));
140+
if (response.ResultCode != 0) throw new OperationException(response.ResultCode, response.RetMsg);
141+
142+
return response.TotalSpace - response.UsedSpace;
143+
}
144+
145+
public async Task<uint> FetchGroupFSCount(long groupUin)
146+
{
147+
var response = await context.EventContext.SendEvent<GroupFSCountEventResp>(new GroupFSCountEventReq(groupUin));
148+
if (response.ResultCode != 0) throw new OperationException(response.ResultCode, response.RetMsg);
149+
150+
return response.FileCount;
151+
}
152+
153+
public async Task<List<IBotFSEntry>> FetchGroupFSList(long groupUin, string targetDirectory)
154+
{
155+
const uint fileCount = 20;
156+
uint startIndex = 0;
157+
var entries = new List<IBotFSEntry>();
158+
159+
while (true)
160+
{
161+
var response = await context.EventContext.SendEvent<GroupFSListEventResp>(new GroupFSListEventReq(groupUin, targetDirectory, startIndex, fileCount));
162+
163+
if (response.ResultCode != 0) throw new OperationException(response.ResultCode, response.RetMsg);
164+
165+
entries.AddRange(response.FileEntries);
166+
if (response.IsEnd) break;
167+
startIndex += fileCount;
168+
}
169+
170+
return entries;
171+
}
172+
137173
public async Task GroupFSMove(long groupUin, string fileId, string parentDirectory, string targetDirectory) => await context.EventContext.SendEvent<GroupFSMoveEventResp>(new GroupFSMoveEventReq(groupUin, fileId, parentDirectory, targetDirectory));
138174

139175
public async Task GroupFSDelete(long groupUin, string fileId) => await context.EventContext.SendEvent<GroupFSDeleteEventResp>(new GroupFSDeleteEventReq(groupUin, fileId));

0 commit comments

Comments
 (0)