Skip to content
This repository was archived by the owner on Oct 12, 2025. It is now read-only.

Commit 946f845

Browse files
authored
[Core] Add FetchStrangerGroupInfo API (#804)
1 parent 0f3b9ca commit 946f845

8 files changed

Lines changed: 130 additions & 11 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Lagrange.Core.Common.Entity;
2+
3+
public class BotStrangerGroupInfo
4+
{
5+
public ulong CreateTime { get; set; }
6+
7+
public ulong MaxMemberCount { get; set; }
8+
9+
public ulong MemberCount { get; set; }
10+
11+
public string Name { get; set; } = string.Empty;
12+
13+
public ulong Uin { get; set; }
14+
}

Lagrange.Core/Common/Interface/Api/OperationExt.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ public static Task<BotGroupClockInResult> GroupClockIn(this BotContext bot, uint
212212
public static Task<(int code, string? message, BotGroupInfo info)> FetchGroupInfo(this BotContext bot, ulong uin)
213213
=> bot.ContextCollection.Business.OperationLogic.FetchGroupInfo(uin);
214214

215+
public static Task<(int code, string? message, BotStrangerGroupInfo info)> FetchStrangerGroupInfo(this BotContext bot, ulong uin)
216+
=> bot.ContextCollection.Business.OperationLogic.FetchStrangerGroupInfo(uin);
217+
215218
public static Task<List<string>?> FetchCustomFace(this BotContext bot)
216219
=> bot.ContextCollection.Business.OperationLogic.FetchCustomFace();
217220

Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,14 @@ public async Task<bool> GroupSetSpecialTitle(uint groupUin, uint targetUin, stri
659659
return (@event.ResultCode, @event.Message, @event.Info);
660660
}
661661

662+
public async Task<(int code, string? message, BotStrangerGroupInfo info)> FetchStrangerGroupInfo(ulong uin)
663+
{
664+
var events = await Collection.Business.SendEvent(GetStrangerGroupInfoEvent.Create(uin));
665+
if (events.Count == 0) return (-1, "No Result", new());
666+
var @event = (GetStrangerGroupInfoEvent)events[0];
667+
return (@event.ResultCode, @event.Message, @event.Info);
668+
}
669+
662670
public async Task<bool> SetMessageReaction(uint groupUin, uint sequence, string code, bool isAdd)
663671
{
664672
if (isAdd)

Lagrange.Core/Internal/Event/Message/GetLatestGroupMessageEvent.cs renamed to Lagrange.Core/Internal/Event/Message/GetGroupInfoEvent.cs

File renamed without changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Lagrange.Core.Common.Entity;
2+
3+
namespace Lagrange.Core.Internal.Event.Message;
4+
5+
internal class GetStrangerGroupInfoEvent : ProtocolEvent
6+
{
7+
public ulong Uin { get; }
8+
9+
public string? Message { get; }
10+
11+
public BotStrangerGroupInfo Info { get; }
12+
13+
protected GetStrangerGroupInfoEvent(ulong uin) : base(true)
14+
{
15+
Uin = uin;
16+
Info = new();
17+
}
18+
19+
protected GetStrangerGroupInfoEvent(int code, string? message, BotStrangerGroupInfo info) : base(code)
20+
{
21+
Message = message;
22+
Info = info;
23+
}
24+
25+
public static GetStrangerGroupInfoEvent Create(ulong uin) => new(uin);
26+
27+
public static GetStrangerGroupInfoEvent Result(int code, string? message, BotStrangerGroupInfo info)
28+
{
29+
return new(code, message, info);
30+
}
31+
}

Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x88D_0.cs renamed to Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x88D.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,27 @@ namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;
99
/// Get Cookie
1010
/// </summary>
1111
[ProtoContract]
12-
[OidbSvcTrpcTcp(0x88D, 0)]
13-
internal class OidbSvcTrpcTcp0x88D_0
12+
internal class OidbSvcTrpcTcp0x88D
1413
{
1514
[ProtoMember(1)]
1615
public uint Field1 { get; set; }
1716

1817
[ProtoMember(2)]
19-
public OidbSvcTrpcTcp0x88D_0Config Config { get; set; }
18+
public OidbSvcTrpcTcp0x88DConfig Config { get; set; }
2019
}
2120

2221
[ProtoContract]
23-
internal class OidbSvcTrpcTcp0x88D_0Config
22+
internal class OidbSvcTrpcTcp0x88DConfig
2423
{
2524
[ProtoMember(1)]
2625
public ulong Uin { get; set; }
2726

2827
[ProtoMember(2)]
29-
public OidbSvcTrpcTcp0x88D_0Flags Flags { get; set; }
28+
public OidbSvcTrpcTcp0x88DFlags Flags { get; set; }
3029
}
3130

3231
[ProtoContract]
33-
internal class OidbSvcTrpcTcp0x88D_0Flags
32+
internal class OidbSvcTrpcTcp0x88DFlags
3433
{
3534
[ProtoMember(1)]
3635
public bool? OwnerUid { get; set; }

Lagrange.Core/Internal/Service/Message/GetLatestGroupMessageService.cs renamed to Lagrange.Core/Internal/Service/Message/GetGroupInfoService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ internal class GetGroupInfoService : BaseService<GetGroupInfoEvent>
1616
protected override bool Build(GetGroupInfoEvent input, BotKeystore keystore, BotAppInfo appInfo,
1717
BotDeviceInfo device, out Span<byte> output, out List<Memory<byte>>? extraPackets)
1818
{
19-
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x88D_0>(new OidbSvcTrpcTcp0x88D_0
19+
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x88D>(new OidbSvcTrpcTcp0x88D
2020
{
21-
Field1 = 537099973,
22-
Config = new OidbSvcTrpcTcp0x88D_0Config
21+
Field1 = (uint)Random.Shared.NextInt64(),
22+
Config = new OidbSvcTrpcTcp0x88DConfig
2323
{
2424
Uin = input.Uin,
25-
Flags = new OidbSvcTrpcTcp0x88D_0Flags
25+
Flags = new OidbSvcTrpcTcp0x88DFlags
2626
{
2727
OwnerUid = true,
2828
CreateTime = true,
@@ -39,7 +39,7 @@ protected override bool Build(GetGroupInfoEvent input, BotKeystore keystore, Bot
3939
MaxAdminCount = "",
4040
}
4141
}
42-
});
42+
}, 0x88d, 0);
4343

4444
output = packet.Serialize();
4545
extraPackets = null;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using Lagrange.Core.Common;
2+
using Lagrange.Core.Common.Entity;
3+
using Lagrange.Core.Internal.Event;
4+
using Lagrange.Core.Internal.Event.Message;
5+
using Lagrange.Core.Internal.Packets.Service.Oidb;
6+
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
7+
using Lagrange.Core.Utility.Extension;
8+
using ProtoBuf;
9+
10+
namespace Lagrange.Core.Internal.Service.Message;
11+
12+
[EventSubscribe(typeof(GetStrangerGroupInfoEvent))]
13+
[Service("OidbSvcTrpcTcp.0x88d_110")]
14+
internal class GetStrangerGroupInfoService : BaseService<GetStrangerGroupInfoEvent>
15+
{
16+
protected override bool Build(GetStrangerGroupInfoEvent input, BotKeystore keystore, BotAppInfo appInfo,
17+
BotDeviceInfo device, out Span<byte> output, out List<Memory<byte>>? extraPackets)
18+
{
19+
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x88D>(new OidbSvcTrpcTcp0x88D
20+
{
21+
Field1 = (uint)Random.Shared.NextInt64(),
22+
Config = new OidbSvcTrpcTcp0x88DConfig
23+
{
24+
Uin = input.Uin,
25+
Flags = new OidbSvcTrpcTcp0x88DFlags
26+
{
27+
CreateTime = true,
28+
MaxMemberCount = true,
29+
MemberCount = true,
30+
Name = "",
31+
Uin = true,
32+
}
33+
}
34+
}, 0x88d, 110);
35+
36+
output = packet.Serialize();
37+
extraPackets = null;
38+
return true;
39+
}
40+
41+
protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
42+
out GetStrangerGroupInfoEvent output, out List<ProtocolEvent>? extraEvents)
43+
{
44+
var payload = Serializer.Deserialize<OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x88D_0Response>>(input);
45+
46+
if (payload.ErrorCode == 0)
47+
{
48+
output = GetStrangerGroupInfoEvent.Result(0, null, new BotStrangerGroupInfo
49+
{
50+
CreateTime = payload.Body.GroupInfo.Results.CreateTime,
51+
MaxMemberCount = payload.Body.GroupInfo.Results.MaxMemberCount,
52+
MemberCount = payload.Body.GroupInfo.Results.MemberCount,
53+
Name = payload.Body.GroupInfo.Results.Name,
54+
Uin = payload.Body.GroupInfo.Results.Uin,
55+
});
56+
}
57+
else
58+
{
59+
output = GetStrangerGroupInfoEvent.Result((int)payload.ErrorCode, payload.ErrorMsg, new());
60+
}
61+
extraEvents = null;
62+
return true;
63+
}
64+
}

0 commit comments

Comments
 (0)