Skip to content

Commit 839e9bd

Browse files
committed
[Core] Implemented GetGroupMessage
1 parent fed29c0 commit 839e9bd

5 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lagrange.Core/Common/Interface/MessageExt.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public static Task<BotMessage> SendFriendMessage(this BotContext context, long f
1010

1111
public static Task<BotMessage> SendGroupMessage(this BotContext context, long groupUin, MessageChain chain)
1212
=> context.EventContext.GetLogic<MessagingLogic>().SendGroupMessage(groupUin, chain);
13+
14+
public static Task<List<BotMessage>> GetGroupMessage(this BotContext context, long groupUin, int startSequence, int endSequence)
15+
=> context.EventContext.GetLogic<MessagingLogic>().GetGroupMessage(groupUin, startSequence, endSequence);
1316

1417
public static Task<bool> SendFriendFile(this BotContext context, long targetUin, Stream fileStream, string? fileName = null)
1518
=> context.EventContext.GetLogic<OperationLogic>().SendFriendFile(targetUin, fileStream, fileName);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Lagrange.Core.Internal.Packets.Message;
2+
3+
namespace Lagrange.Core.Internal.Events.Message;
4+
5+
internal class GetGroupMessageEventReq(long groupUin, int startSequence, int endSequence) : ProtocolEvent
6+
{
7+
public long GroupUin { get; } = groupUin;
8+
9+
public int StartSequence { get; } = startSequence;
10+
11+
public int EndSequence { get; } = endSequence;
12+
}
13+
14+
internal class GetGroupMessageEventResp(List<CommonMessage> chains) : ProtocolEvent
15+
{
16+
public List<CommonMessage> Chains { get; } = chains;
17+
}

Lagrange.Core/Internal/Logic/MessagingLogic.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ internal class MessagingLogic(BotContext context) : ILogic
1414

1515
public Task<CommonMessage> BuildFake(BotMessage msg) => _packer.BuildFake(msg);
1616

17+
public async Task<List<BotMessage>> GetGroupMessage(long groupUin, int startSequence, int endSequence)
18+
{
19+
var result = await context.EventContext.SendEvent<GetGroupMessageEventResp>(new GetGroupMessageEventReq(groupUin, startSequence, endSequence));
20+
var messages = new List<BotMessage>(result.Chains.Count);
21+
foreach (var chain in result.Chains) messages.Add(await Parse(chain));
22+
return messages;
23+
}
24+
1725
public async Task<BotMessage> SendFriendMessage(long friendUin, MessageChain chain)
1826
{
1927
var friend = await context.CacheContext.ResolveFriend(friendUin) ?? throw new InvalidTargetException(friendUin);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Lagrange.Proto;
2+
3+
namespace Lagrange.Core.Internal.Packets.Message;
4+
5+
#pragma warning disable CS8618
6+
7+
/// <summary>
8+
/// trpc.msg.register_proxy.RegisterProxy.SsoGetGroupMsg
9+
/// </summary>
10+
[ProtoPackable]
11+
internal partial class SsoGetGroupMsg
12+
{
13+
[ProtoMember(1)] public SsoGetGroupMsgInfo Info { get; set; }
14+
15+
[ProtoMember(2)] public bool Direction { get; set; }
16+
}
17+
18+
[ProtoPackable]
19+
internal partial class SsoGetGroupMsgInfo
20+
{
21+
[ProtoMember(1)] public long GroupUin { get; set; }
22+
23+
[ProtoMember(2)] public int StartSequence { get; set; }
24+
25+
[ProtoMember(3)] public int EndSequence { get; set; }
26+
}
27+
28+
[ProtoPackable]
29+
internal partial class SsoGetGroupMsgRsp
30+
{
31+
[ProtoMember(1)] public uint RetCode { get; set; }
32+
33+
[ProtoMember(2)] public string ErrorMsg { get; set; }
34+
35+
[ProtoMember(3)] public SsoGetGroupMsgRspBody Body { get; set; }
36+
}
37+
38+
[ProtoPackable]
39+
internal partial class SsoGetGroupMsgRspBody
40+
{
41+
[ProtoMember(1)] public uint Retcode { get; set; }
42+
43+
[ProtoMember(2)] public string Message { get; set; }
44+
45+
[ProtoMember(3)] public uint GroupUin { get; set; }
46+
47+
[ProtoMember(4)] public uint StartSequence { get; set; }
48+
49+
[ProtoMember(5)] public uint EndSequence { get; set; }
50+
51+
[ProtoMember(6)] public List<CommonMessage>? Messages { get; set; }
52+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Lagrange.Core.Common;
2+
using Lagrange.Core.Internal.Events;
3+
using Lagrange.Core.Internal.Events.Message;
4+
using Lagrange.Core.Internal.Packets.Message;
5+
using Lagrange.Core.Utility;
6+
7+
namespace Lagrange.Core.Internal.Services.Message;
8+
9+
[EventSubscribe<GetGroupMessageEventReq>(Protocols.All)]
10+
[Service("trpc.msg.register_proxy.RegisterProxy.SsoGetGroupMsg")]
11+
internal class GetGroupMessageService : BaseService<GetGroupMessageEventReq, GetGroupMessageEventResp>
12+
{
13+
protected override ValueTask<ReadOnlyMemory<byte>> Build(GetGroupMessageEventReq input, BotContext context)
14+
{
15+
var packet = new SsoGetGroupMsg
16+
{
17+
Info = new SsoGetGroupMsgInfo
18+
{
19+
GroupUin = input.GroupUin,
20+
StartSequence = input.StartSequence,
21+
EndSequence = input.EndSequence
22+
},
23+
Direction = true
24+
};
25+
return ValueTask.FromResult(ProtoHelper.Serialize(packet));
26+
}
27+
28+
protected override ValueTask<GetGroupMessageEventResp> Parse(ReadOnlyMemory<byte> input, BotContext context)
29+
{
30+
var packet = ProtoHelper.Deserialize<SsoGetGroupMsgRsp>(input.Span);
31+
return ValueTask.FromResult(new GetGroupMessageEventResp(packet.Body.Messages ?? []));
32+
}
33+
}

0 commit comments

Comments
 (0)