Skip to content

Commit c7db17c

Browse files
committed
[Core & Milky] Implement Core's RecallGroupMessage and Milky's recall_group_message
1 parent 11e11e3 commit c7db17c

7 files changed

Lines changed: 128 additions & 7 deletions

File tree

Lagrange.Core/Common/Interface/MessageExt.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ 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-
13+
1414
public static Task<List<BotMessage>> GetGroupMessage(this BotContext context, long groupUin, ulong startSequence, ulong endSequence)
1515
=> context.EventContext.GetLogic<MessagingLogic>().GetGroupMessage(groupUin, startSequence, endSequence);
16-
16+
1717
public static Task<List<BotMessage>> GetRoamMessage(this BotContext context, long friendUin, uint timestamp, uint count)
1818
=> context.EventContext.GetLogic<MessagingLogic>().GetRoamMessage(friendUin, timestamp, count);
19-
19+
2020
public static Task<List<BotMessage>> GetRoamMessage(this BotContext context, BotMessage target, uint count)
2121
{
2222
uint timestamp = (uint)new DateTimeOffset(target.Time).ToUnixTimeSeconds();
2323
return context.EventContext.GetLogic<MessagingLogic>().GetRoamMessage(target.Contact.Uin, timestamp, count);
2424
}
25-
25+
2626
public static Task<List<BotMessage>> GetC2CMessage(this BotContext context, long peerUin, ulong startSequence, ulong endSequence)
2727
=> context.EventContext.GetLogic<MessagingLogic>().GetC2CMessage(peerUin, startSequence, endSequence);
2828

@@ -32,6 +32,9 @@ public static Task<List<BotMessage>> GetC2CMessage(this BotContext context, long
3232
public static Task<string> SendGroupFile(this BotContext context, long groupUin, Stream fileStream, string? fileName = null, string parentDirectory = "/")
3333
=> context.EventContext.GetLogic<OperationLogic>().SendGroupFile(groupUin, fileStream, fileName, parentDirectory);
3434

35+
public static Task RecallGroupMessage(this BotContext context, long groupUin, ulong sequence)
36+
=> context.EventContext.GetLogic<MessagingLogic>().RecallGroupMessage(groupUin, sequence);
37+
3538
public static Task<string> GroupFSDownload(this BotContext context, long groupUin, string fileId)
3639
=> context.EventContext.GetLogic<OperationLogic>().GroupFSDownload(groupUin, fileId);
3740

@@ -49,13 +52,13 @@ public static Task SendGroupNudge(this BotContext context, long peerUin, long ta
4952

5053
public static Task GroupSetSpecialTitle(this BotContext context, long groupUin, long targetUin, string title)
5154
=> context.EventContext.GetLogic<OperationLogic>().GroupSetSpecialTitle(groupUin, targetUin, title);
52-
55+
5356
public static Task GroupMemberRename(this BotContext context, long groupUin, long targetUin, string name)
5457
=> context.EventContext.GetLogic<OperationLogic>().GroupMemberRename(groupUin, targetUin, name);
5558

5659
public static Task GroupRename(this BotContext context, long groupUin, string name)
5760
=> context.EventContext.GetLogic<OperationLogic>().GroupRename(groupUin, name);
58-
61+
5962
public static Task GroupQuit(this BotContext context, long groupUin)
6063
=> context.EventContext.GetLogic<OperationLogic>().GroupQuit(groupUin);
6164
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Lagrange.Core.Internal.Packets.Message;
2+
3+
namespace Lagrange.Core.Internal.Events.Message;
4+
5+
internal class GroupRecallMsgEventReq(long groupUin, ulong sequence) : ProtocolEvent
6+
{
7+
public long GroupUin { get; } = groupUin;
8+
9+
public ulong Sequence { get; } = sequence;
10+
}
11+
12+
internal class GroupRecallMsgEventResp : ProtocolEvent;

Lagrange.Core/Internal/Logic/MessagingLogic.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public async Task<List<BotMessage>> GetRoamMessage(long peerUin, uint time, uint
3030
foreach (var chain in result.Chains) messages.Add(await Parse(chain));
3131
return messages;
3232
}
33-
33+
3434
public async Task<List<BotMessage>> GetC2CMessage(long peerUin, ulong startSequence, ulong endSequence)
3535
{
3636
string peerUid = context.CacheContext.ResolveCachedUid(peerUin) ?? throw new InvalidTargetException(peerUin);
@@ -71,6 +71,11 @@ public async Task<BotMessage> SendGroupMessage(long groupUin, MessageChain chain
7171
return message;
7272
}
7373

74+
public Task RecallGroupMessage(long groupUin, ulong sequence)
75+
{
76+
return context.EventContext.SendEvent<GroupRecallMsgEventResp>(new GroupRecallMsgEventReq(groupUin, sequence)).AsTask();
77+
}
78+
7479
private async Task<BotMessage> BuildMessage(MessageChain chain, BotContact contact, BotContact receiver)
7580
{
7681
uint random = (uint)Random.Shared.Next();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma warning disable CS8618
2+
3+
using Lagrange.Proto;
4+
5+
namespace Lagrange.Core.Internal.Packets.Message;
6+
7+
/// <summary>
8+
/// trpc.msg.msg_svc.MsgService.SsoGroupRecallMsg
9+
/// </summary>
10+
[ProtoPackable]
11+
internal partial class SsoGroupRecallMsgReq
12+
{
13+
[ProtoMember(1)] public uint Type { get; set; } // 1
14+
15+
[ProtoMember(2)] public long GroupUin { get; set; }
16+
17+
[ProtoMember(3)] public SsoGroupRecallMsgReqField3 Field3 { get; set; }
18+
19+
[ProtoMember(4)] public SsoGroupRecallMsgReqField4 Field4 { get; set; }
20+
}
21+
22+
[ProtoPackable]
23+
internal partial class SsoGroupRecallMsgReqField3
24+
{
25+
[ProtoMember(1)] public ulong Sequence { get; set; }
26+
27+
[ProtoMember(2)] public uint Random { get; set; }
28+
29+
[ProtoMember(3)] public uint Field3 { get; set; } // 0
30+
}
31+
32+
[ProtoPackable]
33+
internal partial class SsoGroupRecallMsgReqField4
34+
{
35+
[ProtoMember(1)] public uint Field1 { get; set; } // 0
36+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Lagrange.Core.Common;
2+
using Lagrange.Core.Exceptions;
3+
using Lagrange.Core.Internal.Events;
4+
using Lagrange.Core.Internal.Events.Message;
5+
using Lagrange.Core.Internal.Packets.Message;
6+
using Lagrange.Core.Utility;
7+
8+
namespace Lagrange.Core.Internal.Services.Message;
9+
10+
[Service("trpc.msg.msg_svc.MsgService.SsoGroupRecallMsg")]
11+
[EventSubscribe<GroupRecallMsgEventReq>(Protocols.All)]
12+
internal class SsoGroupRecallMsgService : BaseService<GroupRecallMsgEventReq, GroupRecallMsgEventResp>
13+
{
14+
protected override ValueTask<ReadOnlyMemory<byte>> Build(GroupRecallMsgEventReq input, BotContext context)
15+
{
16+
var request = new SsoGroupRecallMsgReq
17+
{
18+
Type = 1,
19+
GroupUin = input.GroupUin,
20+
Field3 = new SsoGroupRecallMsgReqField3
21+
{
22+
Sequence = input.Sequence,
23+
Field3 = 0
24+
},
25+
Field4 = new SsoGroupRecallMsgReqField4 { Field1 = 0 }
26+
};
27+
28+
return ValueTask.FromResult(ProtoHelper.Serialize(request));
29+
}
30+
31+
protected override ValueTask<GroupRecallMsgEventResp> Parse(ReadOnlyMemory<byte> input, BotContext context)
32+
{
33+
return ValueTask.FromResult(new GroupRecallMsgEventResp());
34+
}
35+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
using System.Text.Json.Serialization;
3+
using Lagrange.Core;
4+
using Lagrange.Core.Common.Interface;
5+
6+
namespace Lagrange.Milky.Api.Handler.Message;
7+
8+
[Api("recall_group_message")]
9+
public class RecallGroupMessageHandler(BotContext bot) : IEmptyResultApiHandler<RecallGroupMessageParameter>
10+
{
11+
private readonly BotContext _bot = bot;
12+
13+
public Task HandleAsync(RecallGroupMessageParameter parameter, CancellationToken token)
14+
{
15+
return _bot.RecallGroupMessage(parameter.GroupId, (ulong)parameter.MessageSeq);
16+
}
17+
}
18+
19+
public class RecallGroupMessageParameter(long groupId, long messageSeq)
20+
{
21+
[JsonRequired]
22+
[JsonPropertyName("group_id")]
23+
public long GroupId { get; init; } = groupId;
24+
25+
[JsonRequired]
26+
[JsonPropertyName("message_seq")]
27+
public long MessageSeq { get; init; } = messageSeq;
28+
}

Lagrange.Milky/Utility/JsonUtility.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public static partial class JsonUtility
7878
// get_resource_temp_url
7979
[JsonSerializable(typeof(GetResourceTempUrlParameter))]
8080
[JsonSerializable(typeof(GetResourceTempUrlResult))]
81+
// recall_group_message
82+
[JsonSerializable(typeof(RecallGroupMessageParameter))]
8183
// == friend ==
8284
// send_friend_nudge
8385
[JsonSerializable(typeof(SendFriendNudgeParameter))]

0 commit comments

Comments
 (0)