Skip to content

Commit 0341a0e

Browse files
committed
[Core] Implement Fetch Group Extra
1 parent 7b03075 commit 0341a0e

6 files changed

Lines changed: 125 additions & 4 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Lagrange.Core.Common.Entity;
2+
3+
public class BotGroupExtra
4+
{
5+
public required long LatestMessageSequence { get; set; }
6+
}

Lagrange.Core/Common/Interface/OperationExt.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public static Task<List<BotFriend>> FetchFriends(this BotContext context, bool r
2424
public static Task<List<BotGroup>> FetchGroups(this BotContext context, bool refresh = false) =>
2525
context.CacheContext.GetGroupList(refresh);
2626

27+
public static Task<BotGroupExtra> FetchGroupExtra(this BotContext context, long groupUin) =>
28+
context.EventContext.GetLogic<OperationLogic>().FetchGroupExtra(groupUin);
29+
2730
public static Task<List<BotGroupMember>> FetchMembers(this BotContext context, long groupUin, bool refresh = false) =>
2831
context.CacheContext.GetMemberList(groupUin, refresh);
2932

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Lagrange.Core.Common.Entity;
2+
3+
namespace Lagrange.Core.Internal.Events.System;
4+
5+
internal class FetchGroupExtraEventReq(long groupUin) : ProtocolEvent
6+
{
7+
public long GroupUin { get; } = groupUin;
8+
}
9+
10+
internal class FetchGroupExtraEventResp(BotGroupExtra extra) : ProtocolEvent
11+
{
12+
public BotGroupExtra Extra { get; } = extra;
13+
}

Lagrange.Core/Internal/Logic/OperationLogic.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal class OperationLogic(BotContext context) : ILogic
2222
private const string Tag = nameof(OperationLogic);
2323

2424
public async Task<Dictionary<string, string>> FetchCookies(List<string> domains) => (await context.EventContext.SendEvent<FetchCookiesEventResp>(new FetchCookiesEventReq(domains))).Cookies;
25-
25+
2626
public ValueTask<BotSsoPacket> SendPacket(BotSsoPacket packet, RequestType requestType, EncryptType encryptType)
2727
{
2828
int sequence = packet.Sequence != 0 ? packet.Sequence : context.ServiceContext.GetNewSequence();
@@ -88,17 +88,17 @@ public async Task<string> GroupFSDownload(long groupUin, string fileId)
8888
fileName = ResolveFileName(fileStream, fileName);
8989

9090
var friend = await context.CacheContext.ResolveFriend(targetUin) ?? throw new InvalidTargetException(targetUin);
91-
91+
9292
var buffer = ArrayPool<byte>.Shared.Rent(10002432);
9393
int payload = await fileStream.ReadAsync(buffer.AsMemory(0, 10002432));
9494
var md510m = MD5.HashData(buffer[..payload]);
9595
ArrayPool<byte>.Shared.Return(buffer);
9696
fileStream.Seek(0, SeekOrigin.Begin);
97-
97+
9898
var request = new FileUploadEventReq(friend.Uid, fileStream, fileName, md510m);
9999
var result = await context.EventContext.SendEvent<FileUploadEventResp>(request);
100100

101-
101+
102102
if (!result.IsExist)
103103
{
104104
var ext = new FileUploadExt
@@ -241,6 +241,13 @@ public async Task<string> SendGroupFile(long groupUin, Stream fileStream, string
241241
return uploadResp.FileId;
242242
}
243243

244+
public async Task<BotGroupExtra> FetchGroupExtra(long groupUin)
245+
{
246+
var req = new FetchGroupExtraEventReq(groupUin);
247+
var resp = await context.EventContext.SendEvent<FetchGroupExtraEventResp>(req);
248+
return resp.Extra;
249+
}
250+
244251
public async Task<List<BotGroupNotificationBase>> FetchGroupNotifications(ulong count, ulong start)
245252
{
246253
var req = new FetchGroupNotificationsEventReq(count, start);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Lagrange.Proto;
2+
3+
namespace Lagrange.Core.Internal.Packets.Service;
4+
5+
#pragma warning disable CS8618
6+
7+
[ProtoPackable]
8+
internal partial class FetchGroupExtraRequest
9+
{
10+
[ProtoMember(1)]
11+
public long Random { get; set; }
12+
13+
[ProtoMember(2)]
14+
public FetchGroupExtraRequestConfig Config { get; set; }
15+
}
16+
17+
[ProtoPackable]
18+
internal partial class FetchGroupExtraRequestConfig
19+
{
20+
[ProtoMember(1)]
21+
public long GroupUin { get; set; }
22+
23+
[ProtoMember(2)]
24+
public FetchGroupExtraRequestConfigFlags Flags { get; set; }
25+
}
26+
27+
[ProtoPackable]
28+
internal partial class FetchGroupExtraRequestConfigFlags
29+
{
30+
[ProtoMember(22)]
31+
public bool LatestMessageSequence { get; set; }
32+
}
33+
34+
[ProtoPackable]
35+
internal partial class FetchGroupExtraResponse
36+
{
37+
[ProtoMember(1)]
38+
public FetchGroupExtraResponseInfo Info { get; set; }
39+
}
40+
41+
[ProtoPackable]
42+
internal partial class FetchGroupExtraResponseInfo
43+
{
44+
[ProtoMember(1)]
45+
public long GroupUin { get; set; }
46+
47+
[ProtoMember(3)]
48+
public FetchGroupExtraResponseInfoResult Result { get; set; }
49+
}
50+
51+
[ProtoPackable]
52+
internal partial class FetchGroupExtraResponseInfoResult
53+
{
54+
[ProtoMember(22)]
55+
public long LatestMessageSequence { get; set; }
56+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Lagrange.Core.Common;
2+
using Lagrange.Core.Common.Entity;
3+
using Lagrange.Core.Internal.Events;
4+
using Lagrange.Core.Internal.Events.System;
5+
using Lagrange.Core.Internal.Packets.Service;
6+
7+
namespace Lagrange.Core.Internal.Services.System;
8+
9+
[EventSubscribe<FetchGroupExtraEventReq>(Protocols.All)]
10+
[Service("OidbSvcTrpcTcp.0x88d_0")]
11+
internal class FetchGroupExtraService : OidbService<FetchGroupExtraEventReq, FetchGroupExtraEventResp, FetchGroupExtraRequest, FetchGroupExtraResponse>
12+
{
13+
private protected override uint Command => 0x88d;
14+
15+
private protected override uint Service => 0;
16+
17+
private protected override Task<FetchGroupExtraRequest> ProcessRequest(FetchGroupExtraEventReq request, BotContext context)
18+
=> Task.FromResult(new FetchGroupExtraRequest
19+
{
20+
Random = Random.Shared.NextInt64(),
21+
Config = new FetchGroupExtraRequestConfig
22+
{
23+
GroupUin = request.GroupUin,
24+
Flags = new FetchGroupExtraRequestConfigFlags
25+
{
26+
LatestMessageSequence = true,
27+
}
28+
}
29+
});
30+
31+
private protected override Task<FetchGroupExtraEventResp> ProcessResponse(FetchGroupExtraResponse response, BotContext context)
32+
=> Task.FromResult(new FetchGroupExtraEventResp(new BotGroupExtra
33+
{
34+
LatestMessageSequence = response.Info.Result.LatestMessageSequence
35+
}));
36+
}

0 commit comments

Comments
 (0)