From dd6cae369c6f85845d888c490ff580445b054c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Mon, 19 May 2025 12:53:58 +0800 Subject: [PATCH 1/2] feat: poke target_id --- .../Common/Interface/Api/GroupExt.cs | 4 +- .../Common/Interface/Api/OperationExt.cs | 8 ++-- .../Logic/Implementation/OperationLogic.cs | 16 ++----- .../Internal/Event/Message/FriendPokeEvent.cs | 17 ------- .../Internal/Event/Message/GroupPokeEvent.cs | 15 ------ .../Internal/Event/Message/PokeEvent.cs | 20 ++++++++ .../Internal/Service/Message/PokeService.cs | 48 ++++++------------- .../Core/Entity/Action/OneBotSendPoke.cs | 4 +- .../Operation/Message/FriendPokeOperation.cs | 21 +------- .../Operation/Message/GroupPokeOperation.cs | 21 +------- .../Operation/Message/SendPokeOperation.cs | 5 +- 11 files changed, 54 insertions(+), 125 deletions(-) delete mode 100644 Lagrange.Core/Internal/Event/Message/FriendPokeEvent.cs delete mode 100644 Lagrange.Core/Internal/Event/Message/GroupPokeEvent.cs create mode 100644 Lagrange.Core/Internal/Event/Message/PokeEvent.cs diff --git a/Lagrange.Core/Common/Interface/Api/GroupExt.cs b/Lagrange.Core/Common/Interface/Api/GroupExt.cs index e8b9a9a88..d962c56c1 100644 --- a/Lagrange.Core/Common/Interface/Api/GroupExt.cs +++ b/Lagrange.Core/Common/Interface/Api/GroupExt.cs @@ -96,8 +96,8 @@ public static Task SetGroupFilteredRequest(this BotContext bot, BotGroupRe public static Task SetFriendRequest(this BotContext bot, BotFriendRequest request, bool accept = true) => bot.ContextCollection.Business.OperationLogic.SetFriendRequest(request.SourceUid, accept); - public static Task GroupPoke(this BotContext bot, uint groupUin, uint friendUin) - => bot.ContextCollection.Business.OperationLogic.GroupPoke(groupUin, friendUin); + public static Task GroupPoke(this BotContext bot, uint peerUin, uint targetUin) + => bot.ContextCollection.Business.OperationLogic.SendPoke(true, peerUin, targetUin); public static Task SetEssenceMessage(this BotContext bot, MessageChain chain) => bot.ContextCollection.Business.OperationLogic.SetEssenceMessage(chain.GroupUin ?? 0, chain.Sequence, (uint)(chain.MessageId & 0xFFFFFFFF)); diff --git a/Lagrange.Core/Common/Interface/Api/OperationExt.cs b/Lagrange.Core/Common/Interface/Api/OperationExt.cs index a581b98b7..cf3cefcbd 100644 --- a/Lagrange.Core/Common/Interface/Api/OperationExt.cs +++ b/Lagrange.Core/Common/Interface/Api/OperationExt.cs @@ -233,9 +233,8 @@ public static async Task UploadFriendFile(this BotContext bot, uint target public static Task> UploadFriendFileWithResult(this BotContext bot, uint targetUin, FileEntity fileEntity) => bot.ContextCollection.Business.OperationLogic.UploadFriendFileWithResult(targetUin, fileEntity); - - public static Task FriendPoke(this BotContext bot, uint friendUin) - => bot.ContextCollection.Business.OperationLogic.FriendPoke(friendUin); + public static Task FriendPoke(this BotContext bot, uint peerUin, uint? targetUin = null) + => bot.ContextCollection.Business.OperationLogic.SendPoke(false, peerUin, targetUin); /// /// Send a special window shake to friend @@ -311,4 +310,7 @@ public static Task FetchPrivateFSDownload(this BotContext bot, string fi public static Task<(int Code, string Message, string Url)> GetMediaUrl(this BotContext bot, string fileId) => bot.ContextCollection.Business.OperationLogic.GetMediaUrl(fileId); + + public static Task SendPoke(this BotContext bot, bool isGroup, uint peerUin, uint? targetUin = null) + => bot.ContextCollection.Business.OperationLogic.SendPoke(isGroup, peerUin, targetUin); } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs index 00a4a3931..d98b29cc3 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs @@ -607,19 +607,11 @@ public async Task MarkAsRead(uint groupUin, string? targetUid, uint startS var results = await Collection.Business.SendEvent(markAsReadEvent); return results.Count != 0 && ((MarkReadedEvent)results[0]).ResultCode == 0; } - - public async Task FriendPoke(uint friendUin) + public async Task SendPoke(bool isGroup, uint peerUin, uint? targetUin = null) { - var friendPokeEvent = FriendPokeEvent.Create(friendUin); - var results = await Collection.Business.SendEvent(friendPokeEvent); - return results.Count != 0 && ((FriendPokeEvent)results[0]).ResultCode == 0; - } - - public async Task GroupPoke(uint groupUin, uint friendUin) - { - var friendPokeEvent = GroupPokeEvent.Create(friendUin, groupUin); - var results = await Collection.Business.SendEvent(friendPokeEvent); - return results.Count != 0 && ((FriendPokeEvent)results[0]).ResultCode == 0; + var pokeEvent = PokeEvent.Create(isGroup, peerUin, targetUin); + var results = await Collection.Business.SendEvent(pokeEvent); + return results.Count != 0 && results[0].ResultCode == 0; } public async Task SetEssenceMessage(uint groupUin, uint sequence, uint random) diff --git a/Lagrange.Core/Internal/Event/Message/FriendPokeEvent.cs b/Lagrange.Core/Internal/Event/Message/FriendPokeEvent.cs deleted file mode 100644 index 8b748cce9..000000000 --- a/Lagrange.Core/Internal/Event/Message/FriendPokeEvent.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Lagrange.Core.Internal.Event.Message; - -internal class FriendPokeEvent : ProtocolEvent -{ - public uint FriendUin { get; } - - protected FriendPokeEvent(uint friendUin) : base(true) - { - FriendUin = friendUin; - } - - protected FriendPokeEvent(int resultCode) : base(resultCode) { } - - public static FriendPokeEvent Create(uint friendUin) => new(friendUin); - - public static FriendPokeEvent Result(int resultCode) => new(resultCode); -} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Event/Message/GroupPokeEvent.cs b/Lagrange.Core/Internal/Event/Message/GroupPokeEvent.cs deleted file mode 100644 index eefed1477..000000000 --- a/Lagrange.Core/Internal/Event/Message/GroupPokeEvent.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Lagrange.Core.Internal.Event.Message; - -internal class GroupPokeEvent : FriendPokeEvent -{ - public uint GroupUin { get; } - - private GroupPokeEvent(uint friendUin, uint groupUin) : base(friendUin) - { - GroupUin = groupUin; - } - - private GroupPokeEvent(int resultCode) : base(resultCode) { } - - public static GroupPokeEvent Create(uint friendUin, uint groupUin) => new(friendUin, groupUin); -} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Event/Message/PokeEvent.cs b/Lagrange.Core/Internal/Event/Message/PokeEvent.cs new file mode 100644 index 000000000..98f98b069 --- /dev/null +++ b/Lagrange.Core/Internal/Event/Message/PokeEvent.cs @@ -0,0 +1,20 @@ +namespace Lagrange.Core.Internal.Event.Message; + +internal class PokeEvent : ProtocolEvent +{ + public uint PeerUin { get; } + public uint? TargetUin { get; } + public bool IsGroup { get; } + + protected PokeEvent(bool isGroup, uint peerUin, uint? targetUin) : base(true) + { + PeerUin = peerUin; + TargetUin = targetUin; + IsGroup = isGroup; + } + + protected PokeEvent(int resultCode) : base(resultCode) { } + public static PokeEvent Create(bool isGroup, uint peerUin, uint? targetUin) => new(isGroup, peerUin, targetUin); + + public static PokeEvent Result(int resultCode) => new(resultCode); +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Service/Message/PokeService.cs b/Lagrange.Core/Internal/Service/Message/PokeService.cs index bb465859a..f6d40d01e 100644 --- a/Lagrange.Core/Internal/Service/Message/PokeService.cs +++ b/Lagrange.Core/Internal/Service/Message/PokeService.cs @@ -8,51 +8,31 @@ namespace Lagrange.Core.Internal.Service.Message; -[EventSubscribe(typeof(FriendPokeEvent))] -[EventSubscribe(typeof(GroupPokeEvent))] +[EventSubscribe(typeof(PokeEvent))] [Service("OidbSvcTrpcTcp.0xed3_1")] -internal class PokeService : BaseService +internal class PokeService : BaseService { - protected override bool Build(FriendPokeEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, + protected override bool Build(PokeEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out Span output, out List>? extraPackets) { - switch (input) + var packet = new OidbSvcTrpcTcp0xED3_1 { - case GroupPokeEvent group: - { - var packet = new OidbSvcTrpcTcpBase(new OidbSvcTrpcTcp0xED3_1 - { - Uin = group.FriendUin, - GroupUin = group.GroupUin, - Ext = 0 - }); - output = packet.Serialize(); - break; - } - case { } friend: - { - var packet = new OidbSvcTrpcTcpBase(new OidbSvcTrpcTcp0xED3_1 - { - Uin = friend.FriendUin, - FriendUin = friend.FriendUin, - Ext = 0 - }); - output = packet.Serialize(); - break; - } - default: throw new InvalidDataException(); - } - + Uin = input.TargetUin ?? keystore.Uin, + GroupUin = input.IsGroup ? input.PeerUin : 0, + FriendUin = input.IsGroup ? 0 : input.PeerUin, + Ext = 0 + }; + output = packet.Serialize(); extraPackets = null; return true; } - protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, - out FriendPokeEvent output, out List? extraEvents) + protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, + out PokeEvent output, out List? extraEvents) { var payload = Serializer.Deserialize>(input); - - output = FriendPokeEvent.Result((int)payload.ErrorCode); + + output = PokeEvent.Result((int)payload.ErrorCode); extraEvents = null; return true; } diff --git a/Lagrange.OneBot/Core/Entity/Action/OneBotSendPoke.cs b/Lagrange.OneBot/Core/Entity/Action/OneBotSendPoke.cs index f017e1b3e..bdd9a8964 100644 --- a/Lagrange.OneBot/Core/Entity/Action/OneBotSendPoke.cs +++ b/Lagrange.OneBot/Core/Entity/Action/OneBotSendPoke.cs @@ -6,6 +6,8 @@ namespace Lagrange.OneBot.Core.Entity.Action; public class OneBotSendPoke { [JsonPropertyName("user_id")] public uint UserId { get; set; } - + [JsonPropertyName("group_id")] public uint? GroupId { get; set; } + + [JsonPropertyName("target_id")] public uint? TargetId { get; set; } } \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Operation/Message/FriendPokeOperation.cs b/Lagrange.OneBot/Core/Operation/Message/FriendPokeOperation.cs index 10822dcd9..34c92ae6d 100644 --- a/Lagrange.OneBot/Core/Operation/Message/FriendPokeOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/FriendPokeOperation.cs @@ -1,23 +1,4 @@ -using System.Text.Json; -using System.Text.Json.Nodes; -using Lagrange.Core; -using Lagrange.Core.Common.Interface.Api; -using Lagrange.OneBot.Core.Entity.Action; -using Lagrange.OneBot.Core.Operation.Converters; - namespace Lagrange.OneBot.Core.Operation.Message; [Operation("friend_poke")] -public class FriendPokeOperation : IOperation -{ - public async Task HandleOperation(BotContext context, JsonNode? payload) - { - if (payload.Deserialize(SerializerOptions.DefaultOptions) is { } poke) - { - bool result = await context.FriendPoke(poke.UserId); - return new OneBotResult(null, result ? 0 : 1, result ? "ok" : "failed"); - } - - throw new Exception(); - } -} \ No newline at end of file +public class FriendPokeOperation : SendPokeOperation { } \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Operation/Message/GroupPokeOperation.cs b/Lagrange.OneBot/Core/Operation/Message/GroupPokeOperation.cs index 79dc5ad49..f72c2e73c 100644 --- a/Lagrange.OneBot/Core/Operation/Message/GroupPokeOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/GroupPokeOperation.cs @@ -1,23 +1,4 @@ -using System.Text.Json; -using System.Text.Json.Nodes; -using Lagrange.Core; -using Lagrange.Core.Common.Interface.Api; -using Lagrange.OneBot.Core.Entity.Action; -using Lagrange.OneBot.Core.Operation.Converters; - namespace Lagrange.OneBot.Core.Operation.Message; [Operation("group_poke")] -public class GroupPokeOperation : IOperation -{ - public async Task HandleOperation(BotContext context, JsonNode? payload) - { - if (payload.Deserialize(SerializerOptions.DefaultOptions) is { } poke) - { - bool result = await context.GroupPoke(poke.GroupId, poke.UserId); - return new OneBotResult(null, result ? 0 : 1, result ? "ok" : "failed"); - } - - throw new Exception(); - } -} \ No newline at end of file +public class GroupPokeOperation : SendPokeOperation { } \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Operation/Message/SendPokeOperation.cs b/Lagrange.OneBot/Core/Operation/Message/SendPokeOperation.cs index e6fb9b5ff..af55ecf33 100644 --- a/Lagrange.OneBot/Core/Operation/Message/SendPokeOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/SendPokeOperation.cs @@ -14,7 +14,10 @@ public async Task HandleOperation(BotContext context, JsonNode? pa { if (payload.Deserialize(SerializerOptions.DefaultOptions) is { } poke) { - bool result = poke.GroupId.HasValue ? await context.GroupPoke(poke.GroupId.Value, poke.UserId) : await context.FriendPoke(poke.UserId); + bool isGroup = poke.GroupId.HasValue; + uint targetId = poke.TargetId ?? poke.UserId; + uint peerUin = poke.GroupId ?? poke.UserId; + bool result = await context.SendPoke(isGroup, peerUin, targetId); return new OneBotResult(null, result ? 0 : -1, result ? "ok" : "failed"); } From 0623d3181310e2e7a5dc75e0579893aecc24c23f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Mon, 19 May 2025 13:04:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/Entity/Action/OneBotFriendPoke.cs | 9 --------- Lagrange.OneBot/Core/Entity/Action/OneBotGroupPoke.cs | 11 ----------- 2 files changed, 20 deletions(-) delete mode 100644 Lagrange.OneBot/Core/Entity/Action/OneBotFriendPoke.cs delete mode 100644 Lagrange.OneBot/Core/Entity/Action/OneBotGroupPoke.cs diff --git a/Lagrange.OneBot/Core/Entity/Action/OneBotFriendPoke.cs b/Lagrange.OneBot/Core/Entity/Action/OneBotFriendPoke.cs deleted file mode 100644 index 1cff8a7c1..000000000 --- a/Lagrange.OneBot/Core/Entity/Action/OneBotFriendPoke.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Lagrange.OneBot.Core.Entity.Action; - -[Serializable] -public class OneBotFriendPoke -{ - [JsonPropertyName("user_id")] public uint UserId { get; set; } -} \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Entity/Action/OneBotGroupPoke.cs b/Lagrange.OneBot/Core/Entity/Action/OneBotGroupPoke.cs deleted file mode 100644 index 3ec4ae065..000000000 --- a/Lagrange.OneBot/Core/Entity/Action/OneBotGroupPoke.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Lagrange.OneBot.Core.Entity.Action; - -[Serializable] -public class OneBotGroupPoke -{ - [JsonPropertyName("user_id")] public uint UserId { get; set; } - - [JsonPropertyName("group_id")] public uint GroupId { get; set; } -} \ No newline at end of file