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

Commit 297389f

Browse files
authored
[Core] [OneBot] feat: poke target_id (#836)
* feat: poke target_id * fix: 删除多余定义
1 parent ddfda36 commit 297389f

13 files changed

Lines changed: 54 additions & 145 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public static Task<bool> SetGroupFilteredRequest(this BotContext bot, BotGroupRe
9696
public static Task<bool> SetFriendRequest(this BotContext bot, BotFriendRequest request, bool accept = true)
9797
=> bot.ContextCollection.Business.OperationLogic.SetFriendRequest(request.SourceUid, accept);
9898

99-
public static Task<bool> GroupPoke(this BotContext bot, uint groupUin, uint friendUin)
100-
=> bot.ContextCollection.Business.OperationLogic.GroupPoke(groupUin, friendUin);
99+
public static Task<bool> GroupPoke(this BotContext bot, uint peerUin, uint targetUin)
100+
=> bot.ContextCollection.Business.OperationLogic.SendPoke(true, peerUin, targetUin);
101101

102102
public static Task<bool> SetEssenceMessage(this BotContext bot, MessageChain chain)
103103
=> bot.ContextCollection.Business.OperationLogic.SetEssenceMessage(chain.GroupUin ?? 0, chain.Sequence, (uint)(chain.MessageId & 0xFFFFFFFF));

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,8 @@ public static async Task<bool> UploadFriendFile(this BotContext bot, uint target
233233

234234
public static Task<OperationResult<object>> UploadFriendFileWithResult(this BotContext bot, uint targetUin, FileEntity fileEntity)
235235
=> bot.ContextCollection.Business.OperationLogic.UploadFriendFileWithResult(targetUin, fileEntity);
236-
237-
public static Task<bool> FriendPoke(this BotContext bot, uint friendUin)
238-
=> bot.ContextCollection.Business.OperationLogic.FriendPoke(friendUin);
236+
public static Task<bool> FriendPoke(this BotContext bot, uint peerUin, uint? targetUin = null)
237+
=> bot.ContextCollection.Business.OperationLogic.SendPoke(false, peerUin, targetUin);
239238

240239
/// <summary>
241240
/// Send a special window shake to friend
@@ -311,4 +310,7 @@ public static Task<string> FetchPrivateFSDownload(this BotContext bot, string fi
311310

312311
public static Task<(int Code, string Message, string Url)> GetMediaUrl(this BotContext bot, string fileId)
313312
=> bot.ContextCollection.Business.OperationLogic.GetMediaUrl(fileId);
313+
314+
public static Task<bool> SendPoke(this BotContext bot, bool isGroup, uint peerUin, uint? targetUin = null)
315+
=> bot.ContextCollection.Business.OperationLogic.SendPoke(isGroup, peerUin, targetUin);
314316
}

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -607,19 +607,11 @@ public async Task<bool> MarkAsRead(uint groupUin, string? targetUid, uint startS
607607
var results = await Collection.Business.SendEvent(markAsReadEvent);
608608
return results.Count != 0 && ((MarkReadedEvent)results[0]).ResultCode == 0;
609609
}
610-
611-
public async Task<bool> FriendPoke(uint friendUin)
610+
public async Task<bool> SendPoke(bool isGroup, uint peerUin, uint? targetUin = null)
612611
{
613-
var friendPokeEvent = FriendPokeEvent.Create(friendUin);
614-
var results = await Collection.Business.SendEvent(friendPokeEvent);
615-
return results.Count != 0 && ((FriendPokeEvent)results[0]).ResultCode == 0;
616-
}
617-
618-
public async Task<bool> GroupPoke(uint groupUin, uint friendUin)
619-
{
620-
var friendPokeEvent = GroupPokeEvent.Create(friendUin, groupUin);
621-
var results = await Collection.Business.SendEvent(friendPokeEvent);
622-
return results.Count != 0 && ((FriendPokeEvent)results[0]).ResultCode == 0;
612+
var pokeEvent = PokeEvent.Create(isGroup, peerUin, targetUin);
613+
var results = await Collection.Business.SendEvent(pokeEvent);
614+
return results.Count != 0 && results[0].ResultCode == 0;
623615
}
624616

625617
public async Task<bool> SetEssenceMessage(uint groupUin, uint sequence, uint random)

Lagrange.Core/Internal/Event/Message/FriendPokeEvent.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

Lagrange.Core/Internal/Event/Message/GroupPokeEvent.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Lagrange.Core.Internal.Event.Message;
2+
3+
internal class PokeEvent : ProtocolEvent
4+
{
5+
public uint PeerUin { get; }
6+
public uint? TargetUin { get; }
7+
public bool IsGroup { get; }
8+
9+
protected PokeEvent(bool isGroup, uint peerUin, uint? targetUin) : base(true)
10+
{
11+
PeerUin = peerUin;
12+
TargetUin = targetUin;
13+
IsGroup = isGroup;
14+
}
15+
16+
protected PokeEvent(int resultCode) : base(resultCode) { }
17+
public static PokeEvent Create(bool isGroup, uint peerUin, uint? targetUin) => new(isGroup, peerUin, targetUin);
18+
19+
public static PokeEvent Result(int resultCode) => new(resultCode);
20+
}

Lagrange.Core/Internal/Service/Message/PokeService.cs

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,31 @@
88

99
namespace Lagrange.Core.Internal.Service.Message;
1010

11-
[EventSubscribe(typeof(FriendPokeEvent))]
12-
[EventSubscribe(typeof(GroupPokeEvent))]
11+
[EventSubscribe(typeof(PokeEvent))]
1312
[Service("OidbSvcTrpcTcp.0xed3_1")]
14-
internal class PokeService : BaseService<FriendPokeEvent>
13+
internal class PokeService : BaseService<PokeEvent>
1514
{
16-
protected override bool Build(FriendPokeEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
15+
protected override bool Build(PokeEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
1716
out Span<byte> output, out List<Memory<byte>>? extraPackets)
1817
{
19-
switch (input)
18+
var packet = new OidbSvcTrpcTcp0xED3_1
2019
{
21-
case GroupPokeEvent group:
22-
{
23-
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0xED3_1>(new OidbSvcTrpcTcp0xED3_1
24-
{
25-
Uin = group.FriendUin,
26-
GroupUin = group.GroupUin,
27-
Ext = 0
28-
});
29-
output = packet.Serialize();
30-
break;
31-
}
32-
case { } friend:
33-
{
34-
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0xED3_1>(new OidbSvcTrpcTcp0xED3_1
35-
{
36-
Uin = friend.FriendUin,
37-
FriendUin = friend.FriendUin,
38-
Ext = 0
39-
});
40-
output = packet.Serialize();
41-
break;
42-
}
43-
default: throw new InvalidDataException();
44-
}
45-
20+
Uin = input.TargetUin ?? keystore.Uin,
21+
GroupUin = input.IsGroup ? input.PeerUin : 0,
22+
FriendUin = input.IsGroup ? 0 : input.PeerUin,
23+
Ext = 0
24+
};
25+
output = packet.Serialize();
4626
extraPackets = null;
4727
return true;
4828
}
4929

50-
protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
51-
out FriendPokeEvent output, out List<ProtocolEvent>? extraEvents)
30+
protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
31+
out PokeEvent output, out List<ProtocolEvent>? extraEvents)
5232
{
5333
var payload = Serializer.Deserialize<OidbSvcTrpcTcpBase<byte[]>>(input);
54-
55-
output = FriendPokeEvent.Result((int)payload.ErrorCode);
34+
35+
output = PokeEvent.Result((int)payload.ErrorCode);
5636
extraEvents = null;
5737
return true;
5838
}

Lagrange.OneBot/Core/Entity/Action/OneBotFriendPoke.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

Lagrange.OneBot/Core/Entity/Action/OneBotGroupPoke.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

Lagrange.OneBot/Core/Entity/Action/OneBotSendPoke.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace Lagrange.OneBot.Core.Entity.Action;
66
public class OneBotSendPoke
77
{
88
[JsonPropertyName("user_id")] public uint UserId { get; set; }
9-
9+
1010
[JsonPropertyName("group_id")] public uint? GroupId { get; set; }
11+
12+
[JsonPropertyName("target_id")] public uint? TargetId { get; set; }
1113
}

0 commit comments

Comments
 (0)