diff --git a/Lagrange.Core/Common/Interface/Api/OperationExt.cs b/Lagrange.Core/Common/Interface/Api/OperationExt.cs index fb5c27cd9..0affba519 100644 --- a/Lagrange.Core/Common/Interface/Api/OperationExt.cs +++ b/Lagrange.Core/Common/Interface/Api/OperationExt.cs @@ -89,7 +89,7 @@ public static Task RecallGroupMessage(this BotContext bot, uint groupUin, /// Successfully recalled or not public static Task RecallFriendMessage(this BotContext bot, uint friendUin, MessageResult result) => bot.ContextCollection.Business.OperationLogic.RecallFriendMessage(friendUin, result); - + /// /// Recall the group message by /// @@ -98,7 +98,7 @@ public static Task RecallFriendMessage(this BotContext bot, uint friendUin /// Successfully recalled or not public static Task RecallFriendMessage(this BotContext bot, MessageChain chain) => bot.ContextCollection.Business.OperationLogic.RecallFriendMessage(chain); - + /// /// Fetch Notifications and requests such as friend requests and Group Join Requests /// @@ -186,6 +186,11 @@ public static Task Like(this BotContext bot, uint targetUin, uint count = return bot.ContextCollection.Business.OperationLogic.GetC2cMessage(friendUin, startSequence, endSequence); } + public static Task<(int code, List? chains)> GetMessagesByResId(this BotContext bot, string resId) + { + return bot.ContextCollection.Business.OperationLogic.GetMessagesByResId(resId); + } + /// /// Do group clock in (群打卡) /// diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs index eb52c0a2a..f9b75e381 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs @@ -453,6 +453,17 @@ public async Task SetFriendRequest(string targetUid, bool accept) return results.Count != 0 ? ((GetC2cMessageEvent)results[0]).Chains : null; } + public async Task<(int code, List? chains)> GetMessagesByResId(string resId) + { + var @event = MultiMsgDownloadEvent.Create(Collection.Keystore.Uid ?? "", resId); + var results = await Collection.Business.SendEvent(@event); + + if (results.Count == 0) return (-9999, null); + var result = (MultiMsgDownloadEvent)results[0]; + + return (result.ResultCode, result.Chains); + } + public async Task?> FetchCustomFace() { var fetchCustomFaceEvent = FetchCustomFaceEvent.Create(); diff --git a/Lagrange.OneBot/Core/Operation/Message/GetForwardMsgOperation.cs b/Lagrange.OneBot/Core/Operation/Message/GetForwardMsgOperation.cs index b2f710333..a0b6554f5 100644 --- a/Lagrange.OneBot/Core/Operation/Message/GetForwardMsgOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/GetForwardMsgOperation.cs @@ -1,6 +1,7 @@ using System.Text.Json; using System.Text.Json.Nodes; using Lagrange.Core; +using Lagrange.Core.Common.Interface.Api; using Lagrange.Core.Internal.Event.Message; using Lagrange.OneBot.Core.Entity.Action; using Lagrange.OneBot.Core.Entity.Action.Response; @@ -17,11 +18,14 @@ public async Task HandleOperation(BotContext context, JsonNode? pa { if (payload.Deserialize(SerializerOptions.DefaultOptions) is { } forwardMsg) { + var (code, chains) = await context.GetMessagesByResId(forwardMsg.Id); + + if (code != 0) return new OneBotResult(null, code, "failed"); + var nodes = new List(); + if (chains == null) return new OneBotResult(new OneBotGetForwardMsgResponse(nodes), 0, "ok"); - var @event = MultiMsgDownloadEvent.Create(context.ContextCollection.Keystore.Uid ?? "", forwardMsg.Id); - var results = await context.ContextCollection.Business.SendEvent(@event); - foreach (var chain in ((MultiMsgDownloadEvent)results[0]).Chains ?? throw new Exception()) + foreach (var chain in chains) { var parsed = service.Convert(chain); var nickname = string.IsNullOrEmpty(chain.FriendInfo?.Nickname)