From ef62e571b09ed7d9d2328096dbc24f78c476620b Mon Sep 17 00:00:00 2001 From: pk5ls20 Date: Wed, 28 Aug 2024 21:46:01 +0800 Subject: [PATCH 01/12] [Core] Fix #565 (#566) --- Lagrange.Core/Internal/Service/Message/GroupFSUploadService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lagrange.Core/Internal/Service/Message/GroupFSUploadService.cs b/Lagrange.Core/Internal/Service/Message/GroupFSUploadService.cs index 5fe775fe1..a4a88411f 100644 --- a/Lagrange.Core/Internal/Service/Message/GroupFSUploadService.cs +++ b/Lagrange.Core/Internal/Service/Message/GroupFSUploadService.cs @@ -26,7 +26,7 @@ protected override bool Build(GroupFSUploadEvent input, BotKeystore keystore, Bo AppId = 7, BusId = 102, Entrance = 6, - TargetDirectory = "/", + TargetDirectory = input.TargetDirectory, FileName = input.Entity.FileName, LocalDirectory = $"/{input.Entity.FileName}", FileSize = input.Entity.FileSize, From 50a5653644f6c96821f321da8fb41665aec7dd1c Mon Sep 17 00:00:00 2001 From: CwkDark <177549718+CwkDark@users.noreply.github.com> Date: Thu, 29 Aug 2024 13:44:52 +0800 Subject: [PATCH 02/12] [All] FriendRecallEvent add tip (#556) --- .../Event/EventArg/FriendRecallEvent.cs | 9 ++++-- .../Logic/Implementation/MessagingLogic.cs | 2 +- .../Event/Notify/FriendSysRecallEvent.cs | 17 ++++++----- .../Packets/Message/Notify/FriendRecall.cs | 30 ++++++++++++------- .../Service/Message/PushMessageService.cs | 8 ++++- .../Core/Entity/Notify/OneBotFriendRecall.cs | 2 ++ Lagrange.OneBot/Core/Notify/NotifyService.cs | 1 + 7 files changed, 46 insertions(+), 23 deletions(-) diff --git a/Lagrange.Core/Event/EventArg/FriendRecallEvent.cs b/Lagrange.Core/Event/EventArg/FriendRecallEvent.cs index d8ecfd24e..e5a991d94 100644 --- a/Lagrange.Core/Event/EventArg/FriendRecallEvent.cs +++ b/Lagrange.Core/Event/EventArg/FriendRecallEvent.cs @@ -10,13 +10,16 @@ public class FriendRecallEvent : EventBase public uint Random { get; } - public FriendRecallEvent(uint friendUin, uint sequence, uint time, uint random) + public string Tip { get; } + + public FriendRecallEvent(uint friendUin, uint sequence, uint time, uint random, string tip) { FriendUin = friendUin; Sequence = sequence; Time = time; Random = random; - - EventMessage = $"{nameof(FriendRecallEvent)}: {FriendUin} | ({Sequence} | {Time} | {Random})"; + Tip = tip; + + EventMessage = $"{nameof(FriendRecallEvent)}: {FriendUin} | ({Sequence} | {Time} | {Random} | {Tip})"; } } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs index 976a8f81c..b5bffce80 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs @@ -194,7 +194,7 @@ public override async Task Incoming(ProtocolEvent e) case FriendSysRecallEvent recall: { uint fromUin = await Collection.Business.CachingLogic.ResolveUin(null, recall.FromUid) ?? 0; - var recallArgs = new FriendRecallEvent(fromUin, recall.Sequence, recall.Time, recall.Random); + var recallArgs = new FriendRecallEvent(fromUin, recall.Sequence, recall.Time, recall.Random, recall.Tip); Collection.Invoker.PostEvent(recallArgs); break; } diff --git a/Lagrange.Core/Internal/Event/Notify/FriendSysRecallEvent.cs b/Lagrange.Core/Internal/Event/Notify/FriendSysRecallEvent.cs index 1e4170f0a..0c28be1dc 100644 --- a/Lagrange.Core/Internal/Event/Notify/FriendSysRecallEvent.cs +++ b/Lagrange.Core/Internal/Event/Notify/FriendSysRecallEvent.cs @@ -3,21 +3,24 @@ namespace Lagrange.Core.Internal.Event.Notify; internal class FriendSysRecallEvent : ProtocolEvent { public string FromUid { get; } - + public uint Sequence { get; } - + public uint Time { get; } - + public uint Random { get; } - - private FriendSysRecallEvent(string fromUid, uint sequence, uint time, uint random) : base(0) + + public string Tip { get; } + + private FriendSysRecallEvent(string fromUid, uint sequence, uint time, uint random, string tip) : base(0) { FromUid = fromUid; Sequence = sequence; Time = time; Random = random; + Tip = tip; } - public static FriendSysRecallEvent Result(string fromUid, uint sequence, uint time, uint random) - => new(fromUid, sequence, time, random); + public static FriendSysRecallEvent Result(string fromUid, uint sequence, uint time, uint random, string tip) + => new(fromUid, sequence, time, random, tip); } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/Message/Notify/FriendRecall.cs b/Lagrange.Core/Internal/Packets/Message/Notify/FriendRecall.cs index 9cdc4a6c2..10466e59e 100644 --- a/Lagrange.Core/Internal/Packets/Message/Notify/FriendRecall.cs +++ b/Lagrange.Core/Internal/Packets/Message/Notify/FriendRecall.cs @@ -8,13 +8,13 @@ namespace Lagrange.Core.Internal.Packets.Message.Notify; internal class FriendRecall { [ProtoMember(1)] public FriendRecallInfo Info { get; set; } - + [ProtoMember(2)] public uint InstId { get; set; } - + [ProtoMember(3)] public uint AppId { get; set; } - + [ProtoMember(4)] public uint LongMessageFlag { get; set; } - + [ProtoMember(5)] public byte[] Reserved { get; set; } } @@ -22,20 +22,28 @@ internal class FriendRecall internal class FriendRecallInfo { [ProtoMember(1)] public string FromUid { get; set; } - + [ProtoMember(2)] public string ToUid { get; set; } - + [ProtoMember(3)] public uint Sequence { get; set; } - + [ProtoMember(4)] public ulong NewId { get; set; } - + [ProtoMember(5)] public uint Time { get; set; } [ProtoMember(6)] public uint Random { get; set; } - + [ProtoMember(7)] public uint PkgNum { get; set; } - + [ProtoMember(8)] public uint PkgIndex { get; set; } - + [ProtoMember(9)] public uint DivSeq { get; set; } + + [ProtoMember(13)] public TipInfo TipInfo { get; set; } +} + +[ProtoContract] +internal class TipInfo +{ + [ProtoMember(2)] public string? Tip { get; set; } } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Service/Message/PushMessageService.cs b/Lagrange.Core/Internal/Service/Message/PushMessageService.cs index 97bcdffad..127156768 100644 --- a/Lagrange.Core/Internal/Service/Message/PushMessageService.cs +++ b/Lagrange.Core/Internal/Service/Message/PushMessageService.cs @@ -242,7 +242,13 @@ private static void ProcessEvent0x210(Span payload, PushMsg msg, List(content.AsSpan()); - var recallEvent = FriendSysRecallEvent.Result(recall.Info.FromUid, recall.Info.Sequence, recall.Info.Time, recall.Info.Random); + var recallEvent = FriendSysRecallEvent.Result( + recall.Info.FromUid, + recall.Info.Sequence, + recall.Info.Time, + recall.Info.Random, + recall.Info.TipInfo.Tip ?? "" + ); extraEvents.Add(recallEvent); break; } diff --git a/Lagrange.OneBot/Core/Entity/Notify/OneBotFriendRecall.cs b/Lagrange.OneBot/Core/Entity/Notify/OneBotFriendRecall.cs index 5d2180a22..c30950e54 100644 --- a/Lagrange.OneBot/Core/Entity/Notify/OneBotFriendRecall.cs +++ b/Lagrange.OneBot/Core/Entity/Notify/OneBotFriendRecall.cs @@ -8,4 +8,6 @@ public class OneBotFriendRecall(uint selfId) : OneBotNotify(selfId, "friend_reca [JsonPropertyName("user_id")] public uint UserId { get; set; } [JsonPropertyName("message_id")] public int MessageId { get; set; } + + [JsonPropertyName("tip")] public string Tip { get; set; } = string.Empty; } \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Notify/NotifyService.cs b/Lagrange.OneBot/Core/Notify/NotifyService.cs index 329506e14..43200c49a 100644 --- a/Lagrange.OneBot/Core/Notify/NotifyService.cs +++ b/Lagrange.OneBot/Core/Notify/NotifyService.cs @@ -148,6 +148,7 @@ await service.SendJsonAsync(new OneBotFriendRecall(bot.BotUin) { UserId = @event.FriendUin, MessageId = MessageRecord.CalcMessageHash(@event.Random, @event.Sequence), + Tip = @event.Tip }); }; From 8bbcc19e9f88ab62b205f684cdd3cb8e0b2efc23 Mon Sep 17 00:00:00 2001 From: CwkDark <177549718+CwkDark@users.noreply.github.com> Date: Thu, 29 Aug 2024 13:45:17 +0800 Subject: [PATCH 03/12] [All] GroupRecallEvent add tip (#557) --- .../Event/EventArg/GroupRecallEvent.cs | 19 ++++++++------- .../Logic/Implementation/MessagingLogic.cs | 2 +- .../Event/Notify/GroupSysRecallEvent.cs | 19 ++++++++------- .../Packets/Message/Notify/GroupRecall.cs | 24 ++++++++++++------- .../Service/Message/PushMessageService.cs | 12 ++++++++-- .../Core/Entity/Notify/OneBotGroupRecall.cs | 2 ++ Lagrange.OneBot/Core/Notify/NotifyService.cs | 3 ++- 7 files changed, 53 insertions(+), 28 deletions(-) diff --git a/Lagrange.Core/Event/EventArg/GroupRecallEvent.cs b/Lagrange.Core/Event/EventArg/GroupRecallEvent.cs index 64361a0dd..401521a40 100644 --- a/Lagrange.Core/Event/EventArg/GroupRecallEvent.cs +++ b/Lagrange.Core/Event/EventArg/GroupRecallEvent.cs @@ -3,18 +3,20 @@ namespace Lagrange.Core.Event.EventArg; public class GroupRecallEvent : EventBase { public uint GroupUin { get; } - + public uint AuthorUin { get; } - + public uint OperatorUin { get; } - + public uint Sequence { get; } - + public uint Time { get; } - + public uint Random { get; } - public GroupRecallEvent(uint groupUin, uint authorUin, uint operatorUin, uint sequence, uint time, uint random) + public string Tip { get; } + + public GroupRecallEvent(uint groupUin, uint authorUin, uint operatorUin, uint sequence, uint time, uint random, string tip) { GroupUin = groupUin; AuthorUin = authorUin; @@ -22,7 +24,8 @@ public GroupRecallEvent(uint groupUin, uint authorUin, uint operatorUin, uint se Sequence = sequence; Time = time; Random = random; - - EventMessage = $"{nameof(GroupRecallEvent)}: {GroupUin} | {AuthorUin} | {OperatorUin} | ({Sequence} | {Time} | {Random})"; + Tip = tip; + + EventMessage = $"{nameof(GroupRecallEvent)}: {GroupUin} | {AuthorUin} | {OperatorUin} | ({Sequence} | {Time} | {Random} | {Tip})"; } } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs index b5bffce80..98839d1c0 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs @@ -165,7 +165,7 @@ public override async Task Incoming(ProtocolEvent e) uint authorUin = await Collection.Business.CachingLogic.ResolveUin(recall.GroupUin, recall.AuthorUid) ?? 0; uint operatorUin = 0; if (recall.OperatorUid != null) operatorUin = await Collection.Business.CachingLogic.ResolveUin(recall.GroupUin, recall.OperatorUid) ?? 0; - var recallArgs = new GroupRecallEvent(recall.GroupUin, authorUin, operatorUin, recall.Sequence, recall.Time, recall.Random); + var recallArgs = new GroupRecallEvent(recall.GroupUin, authorUin, operatorUin, recall.Sequence, recall.Time, recall.Random, recall.Tip); Collection.Invoker.PostEvent(recallArgs); break; } diff --git a/Lagrange.Core/Internal/Event/Notify/GroupSysRecallEvent.cs b/Lagrange.Core/Internal/Event/Notify/GroupSysRecallEvent.cs index f5cad16cb..4c612452c 100644 --- a/Lagrange.Core/Internal/Event/Notify/GroupSysRecallEvent.cs +++ b/Lagrange.Core/Internal/Event/Notify/GroupSysRecallEvent.cs @@ -3,18 +3,20 @@ namespace Lagrange.Core.Internal.Event.Notify; internal class GroupSysRecallEvent : ProtocolEvent { public uint GroupUin { get; } - + public string AuthorUid { get; } - + public string? OperatorUid { get; } - + public uint Sequence { get; } - + public uint Time { get; } - + public uint Random { get; } - private GroupSysRecallEvent(uint groupUin, string authorUid, string? operatorUid, uint sequence, uint time, uint random) : base(0) + public string Tip { get; } + + private GroupSysRecallEvent(uint groupUin, string authorUid, string? operatorUid, uint sequence, uint time, uint random, string tip) : base(0) { GroupUin = groupUin; AuthorUid = authorUid; @@ -22,8 +24,9 @@ private GroupSysRecallEvent(uint groupUin, string authorUid, string? operatorUid Sequence = sequence; Time = time; Random = random; + Tip = tip; } - public static GroupSysRecallEvent Result(uint groupUin, string authorUid, string? operatorUid, uint sequence, uint time, uint random) - => new(groupUin, authorUid, operatorUid, sequence, time, random); + public static GroupSysRecallEvent Result(uint groupUin, string authorUid, string? operatorUid, uint sequence, uint time, uint random, string tip) + => new(groupUin, authorUid, operatorUid, sequence, time, random, tip); } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/Message/Notify/GroupRecall.cs b/Lagrange.Core/Internal/Packets/Message/Notify/GroupRecall.cs index a17110531..fb7550aa1 100644 --- a/Lagrange.Core/Internal/Packets/Message/Notify/GroupRecall.cs +++ b/Lagrange.Core/Internal/Packets/Message/Notify/GroupRecall.cs @@ -8,28 +8,36 @@ namespace Lagrange.Core.Internal.Packets.Message.Notify; internal class GroupRecall { [ProtoMember(1)] public string? OperatorUid { get; set; } - + [ProtoMember(3)] public List RecallMessages { get; set; } - + [ProtoMember(5)] public byte[] UserDef { get; set; } - + [ProtoMember(6)] public int GroupType { get; set; } - + [ProtoMember(7)] public int OpType { get; set; } + + [ProtoMember(9)] public TipInfo? TipInfo { get; set; } } [ProtoContract] internal class RecallMessage { [ProtoMember(1)] public uint Sequence { get; set; } - + [ProtoMember(2)] public uint Time { get; set; } - + [ProtoMember(3)] public uint Random { get; set; } - + [ProtoMember(4)] public uint Type { get; set; } [ProtoMember(5)] public uint Flag { get; set; } - + [ProtoMember(6)] public string AuthorUid { get; set; } +} + +[ProtoContract] +internal class TipInfo +{ + [ProtoMember(2)] public string Tip { get; set; } } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Service/Message/PushMessageService.cs b/Lagrange.Core/Internal/Service/Message/PushMessageService.cs index 127156768..8b5f0bbd4 100644 --- a/Lagrange.Core/Internal/Service/Message/PushMessageService.cs +++ b/Lagrange.Core/Internal/Service/Message/PushMessageService.cs @@ -155,7 +155,15 @@ private static void ProcessEvent0x2DC(Span payload, PushMsg msg, List(proto); var meta = recall.Recall.RecallMessages[0]; - var groupRecallEvent = GroupSysRecallEvent.Result(recall.GroupUin, meta.AuthorUid, recall.Recall.OperatorUid, meta.Sequence, meta.Time, meta.Random); + var groupRecallEvent = GroupSysRecallEvent.Result( + recall.GroupUin, + meta.AuthorUid, + recall.Recall.OperatorUid, + meta.Sequence, + meta.Time, + meta.Random, + recall?.Recall.TipInfo?.Tip ?? "" + ); extraEvents.Add(groupRecallEvent); break; } @@ -204,7 +212,7 @@ private static void ProcessEvent0x2DC(Span payload, PushMsg msg, List Date: Thu, 29 Aug 2024 13:55:10 +0800 Subject: [PATCH 04/12] [Core] fix recall info class name duplicate (#569) --- Lagrange.Core/Internal/Packets/Message/Notify/FriendRecall.cs | 4 ++-- Lagrange.Core/Internal/Packets/Message/Notify/GroupRecall.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lagrange.Core/Internal/Packets/Message/Notify/FriendRecall.cs b/Lagrange.Core/Internal/Packets/Message/Notify/FriendRecall.cs index 10466e59e..07a202114 100644 --- a/Lagrange.Core/Internal/Packets/Message/Notify/FriendRecall.cs +++ b/Lagrange.Core/Internal/Packets/Message/Notify/FriendRecall.cs @@ -39,11 +39,11 @@ internal class FriendRecallInfo [ProtoMember(9)] public uint DivSeq { get; set; } - [ProtoMember(13)] public TipInfo TipInfo { get; set; } + [ProtoMember(13)] public FriendRecallTipInfo TipInfo { get; set; } } [ProtoContract] -internal class TipInfo +internal class FriendRecallTipInfo { [ProtoMember(2)] public string? Tip { get; set; } } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/Message/Notify/GroupRecall.cs b/Lagrange.Core/Internal/Packets/Message/Notify/GroupRecall.cs index fb7550aa1..76c8da3ef 100644 --- a/Lagrange.Core/Internal/Packets/Message/Notify/GroupRecall.cs +++ b/Lagrange.Core/Internal/Packets/Message/Notify/GroupRecall.cs @@ -17,7 +17,7 @@ internal class GroupRecall [ProtoMember(7)] public int OpType { get; set; } - [ProtoMember(9)] public TipInfo? TipInfo { get; set; } + [ProtoMember(9)] public GroupRecallTipInfo? TipInfo { get; set; } } [ProtoContract] @@ -37,7 +37,7 @@ internal class RecallMessage } [ProtoContract] -internal class TipInfo +internal class GroupRecallTipInfo { [ProtoMember(2)] public string Tip { get; set; } } \ No newline at end of file From 2e1f19c1cc2293b5a40c6300d55bb857ff920d32 Mon Sep 17 00:00:00 2001 From: CwkDark <177549718+CwkDark@users.noreply.github.com> Date: Sat, 31 Aug 2024 06:07:42 +0800 Subject: [PATCH 05/12] [Core] ImageEntity add image md5 (#553) * [Core] ImageEntity add image hash * rename to md5 * Use byte[] instead of string --- Lagrange.Core/Message/Entity/ImageEntity.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Lagrange.Core/Message/Entity/ImageEntity.cs b/Lagrange.Core/Message/Entity/ImageEntity.cs index 350217e34..bf0c7ab4e 100644 --- a/Lagrange.Core/Message/Entity/ImageEntity.cs +++ b/Lagrange.Core/Message/Entity/ImageEntity.cs @@ -22,6 +22,8 @@ public class ImageEntity : IMessageEntity public string FilePath { get; set; } = string.Empty; + public byte[] ImageMd5 { get; set; } = Array.Empty(); + public uint ImageSize { get; set; } public string ImageUrl { get; set; } = string.Empty; @@ -55,7 +57,7 @@ public ImageEntity(byte[] file) FilePath = ""; ImageStream = new Lazy(() => new MemoryStream(file)); } - + public ImageEntity(Stream stream) { FilePath = ""; @@ -97,12 +99,13 @@ IEnumerable IMessageEntity.PackElement() { PictureSize = new Vector2(index.Info.Width, index.Info.Height), FilePath = index.Info.FileName, + ImageMd5 = index.Info.FileHash.UnHex(), ImageSize = index.Info.FileSize, MsgInfo = extra, SubType = (int)extra.ExtBizInfo.Pic.BizType, }; } - + if (elems.NotOnlineImage is { } image) { if (image.OrigUrl.Contains("&fileid=")) // NTQQ's shit @@ -111,18 +114,19 @@ IEnumerable IMessageEntity.PackElement() { PictureSize = new Vector2(image.PicWidth, image.PicHeight), FilePath = image.FilePath, + ImageMd5 = image.PicMd5, ImageSize = image.FileLen, ImageUrl = $"{BaseUrl}{image.OrigUrl}", Summary = image.PbRes.Summary, SubType = image.PbRes.SubType }; - } return new ImageEntity { PictureSize = new Vector2(image.PicWidth, image.PicHeight), FilePath = image.FilePath, + ImageMd5 = image.PicMd5, ImageSize = image.FileLen, ImageUrl = $"{LegacyBaseUrl}{image.OrigUrl}", Summary = image.PbRes.Summary, @@ -159,7 +163,7 @@ IEnumerable IMessageEntity.PackElement() return null; } - + private static int GetImageTypeFromFaceOldData(CustomFace face) { if (face.OldData == null || face.OldData.Length < 5) From 188086e31eb843290f8026e618d29a5fd6c152d6 Mon Sep 17 00:00:00 2001 From: CwkDark <177549718+CwkDark@users.noreply.github.com> Date: Sat, 31 Aug 2024 06:08:08 +0800 Subject: [PATCH 06/12] [Core] Fix image in the forward does not have a url (#568) * [Core] Fix image in the forward does not have a url * remove some thing --- .../Context/Logic/Implementation/MessagingLogic.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs index 98839d1c0..a33dca7e5 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs @@ -35,6 +35,7 @@ namespace Lagrange.Core.Internal.Context.Logic.Implementation; [EventSubscribe(typeof(FriendSysRequestEvent))] [EventSubscribe(typeof(FriendSysPokeEvent))] [EventSubscribe(typeof(LoginNotifyEvent))] +[EventSubscribe(typeof(MultiMsgDownloadEvent))] [BusinessLogic("MessagingLogic", "Manage the receiving and sending of messages and notifications")] internal class MessagingLogic : LogicBase { @@ -210,6 +211,18 @@ public override async Task Incoming(ProtocolEvent e) Collection.Invoker.PostEvent(deviceArgs); break; } + case MultiMsgDownloadEvent multi: + { + if (multi.Chains != null) + { + foreach (var chain in multi.Chains) + { + if (chain.Count == 0) return; + await ResolveIncomingChain(chain); + } + } + break; + } } } From b1a3f786cfb76fe2597c5f525f4258838b56d7cf Mon Sep 17 00:00:00 2001 From: CwkDark <177549718+CwkDark@users.noreply.github.com> Date: Sat, 31 Aug 2024 06:10:13 +0800 Subject: [PATCH 07/12] [Core] RecordEntity add audio md5 (#555) * [Core] RecordEntity add audio md5 * for legacy ptt * Use byte[] instead of string * sorry --- Lagrange.Core/Message/Entity/RecordEntity.cs | 10 ++-- Lagrange.Core/Message/MessagePacker.cs | 48 ++++++++++---------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Lagrange.Core/Message/Entity/RecordEntity.cs b/Lagrange.Core/Message/Entity/RecordEntity.cs index 521c4cf0c..19add127b 100644 --- a/Lagrange.Core/Message/Entity/RecordEntity.cs +++ b/Lagrange.Core/Message/Entity/RecordEntity.cs @@ -15,6 +15,8 @@ public class RecordEntity : IMessageEntity public string FilePath { get; set; } = string.Empty; + public byte[] AudioMd5 { get; set; } = Array.Empty(); + public string AudioName { get; set; } = string.Empty; public int AudioSize { get; } @@ -50,16 +52,18 @@ public RecordEntity(byte[] file, int audioLength = 0) FilePath = string.Empty; AudioStream = new Lazy(() => new MemoryStream(file)); AudioLength = audioLength; - if (file == null) { + if (file == null) + { throw new ArgumentNullException(nameof(file)); } AudioSize = file.Length; } - internal RecordEntity(string audioUuid, string audioName) + internal RecordEntity(string audioUuid, string audioName, byte[] audioMd5) { AudioUuid = audioUuid; AudioName = audioName; + AudioMd5 = audioMd5; } IEnumerable IMessageEntity.PackElement() @@ -87,7 +91,7 @@ IEnumerable IMessageEntity.PackElement() var extra = Serializer.Deserialize(common.PbElem.AsSpan()); var index = extra.MsgInfoBody[0].Index; - return new RecordEntity(index.FileUuid, index.Info.FileName) + return new RecordEntity(index.FileUuid, index.Info.FileName, index.Info.FileHash.UnHex()) { AudioLength = (int)index.Info.Time, FileSha1 = index.Info.FileSha1, diff --git a/Lagrange.Core/Message/MessagePacker.cs b/Lagrange.Core/Message/MessagePacker.cs index f9b818fa1..d0f9e9072 100644 --- a/Lagrange.Core/Message/MessagePacker.cs +++ b/Lagrange.Core/Message/MessagePacker.cs @@ -25,7 +25,7 @@ internal static class MessagePacker { private static readonly Dictionary> EntityToElem; private static readonly Dictionary Factory; - + static MessagePacker() { EntityToElem = new Dictionary>(); @@ -34,7 +34,7 @@ static MessagePacker() var assembly = Assembly.GetExecutingAssembly(); var types = assembly.GetTypeWithMultipleAttributes(out var attributeArrays); var elemType = typeof(Elem); - + for (int i = 0; i < types.Count; i++) { var type = types[i]; @@ -73,12 +73,12 @@ public static Internal.Packets.Message.Message Build(MessageChain chain, string message.Body.MsgContent = stream.ToArray(); } } - + BuildAdditional(chain, message); return message; } - + public static PushMsgBody BuildFake(MessageChain chain, string selfUid) { var message = BuildFakePacketBase(chain, selfUid); @@ -87,7 +87,7 @@ public static PushMsgBody BuildFake(MessageChain chain, string selfUid) { entity.SetSelfUid(selfUid); message.Body?.RichText?.Elems.AddRange(entity.PackElement()); - + if (message.Body != null) { if (entity.PackMessageContent() is not { } content) continue; @@ -104,7 +104,7 @@ public static PushMsgBody BuildFake(MessageChain chain, string selfUid) private static void BuildAdditional(MessageChain chain, Internal.Packets.Message.Message message) { if (message.Body?.RichText == null) return; - + foreach (var entity in chain) { switch (entity) @@ -118,12 +118,12 @@ private static void BuildAdditional(MessageChain chain, Internal.Packets.Message } } } - + public static MessageChain Parse(PushMsgBody message, bool isFake = false) { var chain = isFake ? ParseFakeChain(message) : ParseChain(message); - if (message.Body?.RichText is { Elems: { } elements}) // 怎么Body还能是null的 + if (message.Body?.RichText is { Elems: { } elements }) // 怎么Body还能是null的 { foreach (var element in elements) { @@ -131,7 +131,7 @@ public static MessageChain Parse(PushMsgBody message, bool isFake = false) { foreach (var expectElem in expectElems) { - if (expectElem.GetValueByExpr(element) is not null && + if (expectElem.GetValueByExpr(element) is not null && Factory[entityType].UnpackElement(element) is { } entity) { chain.Add(entity); @@ -144,12 +144,12 @@ public static MessageChain Parse(PushMsgBody message, bool isFake = false) switch (message.Body?.RichText?.Ptt) { - case { } groupPtt when chain.IsGroup && groupPtt.FileId != 0: // for legacy ptt - chain.Add(new RecordEntity(groupPtt.GroupFileKey, groupPtt.FileName)); + case { } groupPtt when chain.IsGroup && groupPtt.FileId != 0: // for legacy ptt + chain.Add(new RecordEntity(groupPtt.GroupFileKey, groupPtt.FileName, groupPtt.FileMd5)); break; - case { } privatePtt when !chain.IsGroup: - if (chain.OfType().FirstOrDefault(x => x.AudioName == privatePtt.FileName) == null) - chain.Add(new RecordEntity(privatePtt.FileUuid, privatePtt.FileName)); + case { } privatePtt when !chain.IsGroup: + if (chain.OfType().FirstOrDefault(x => x.AudioName == privatePtt.FileName) == null) + chain.Add(new RecordEntity(privatePtt.FileUuid, privatePtt.FileName, privatePtt.FileMd5)); break; } @@ -159,13 +159,13 @@ public static MessageChain Parse(PushMsgBody message, bool isFake = false) public static MessageChain ParsePrivateFile(PushMsgBody message) { if (message.Body?.MsgContent == null) throw new Exception(); - + var chain = ParseChain(message); var extra = Serializer.Deserialize(message.Body.MsgContent.AsSpan()); var file = extra.File; - if ( file is { FileSize: not null, FileName: not null, FileMd5: not null, FileUuid: not null, FileHash: not null }) + if (file is { FileSize: not null, FileName: not null, FileMd5: not null, FileUuid: not null, FileHash: not null }) { chain.Add(new FileEntity((long)file.FileSize, file.FileName, file.FileMd5, file.FileUuid, file.FileHash)); return chain; @@ -243,29 +243,29 @@ public static MessageChain ParsePrivateFile(PushMsgBody message) }, Body = new MessageBody { RichText = new RichText { Elems = new List() } } }; - + private static MessageChain ParseChain(PushMsgBody message) { var chain = message.ResponseHead.Grp == null ? new MessageChain( message.ResponseHead.FromUin, - message.ResponseHead.ToUid ?? string.Empty , - message.ResponseHead.FromUid ?? string.Empty, + message.ResponseHead.ToUid ?? string.Empty, + message.ResponseHead.FromUid ?? string.Empty, message.ResponseHead.ToUin, message.ContentHead.Sequence ?? 0, message.ContentHead.NewId ?? 0, message.ContentHead.Type == 141 ? MessageChain.MessageType.Temp : MessageChain.MessageType.Friend) - + : new MessageChain( - message.ResponseHead.Grp.GroupUin, - message.ResponseHead.FromUin, + message.ResponseHead.Grp.GroupUin, + message.ResponseHead.FromUin, message.ContentHead.Sequence ?? 0, message.ContentHead.NewId ?? 0); if (message.Body?.RichText?.Elems is { } elems) chain.Elements.AddRange(elems); chain.Time = DateTimeOffset.FromUnixTimeSeconds(message.ContentHead.Timestamp ?? 0).LocalDateTime; - + return chain; } @@ -286,7 +286,7 @@ private static MessageChain ParseFakeChain(PushMsgBody message) { @base.FriendInfo = new BotFriend(0, message.ResponseHead.FromUid ?? string.Empty, message.ResponseHead.Forward?.FriendName ?? string.Empty, string.Empty, string.Empty, string.Empty); } - + return @base; } From dd1a7c2f0db5651b51512826863e9c69af88de55 Mon Sep 17 00:00:00 2001 From: Linwenxuan04 Date: Tue, 3 Sep 2024 08:42:08 -0400 Subject: [PATCH 08/12] [All] Refactor by remove using statements --- Lagrange.Core/Internal/Context/Uploader/FileUploader.cs | 1 - Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs | 2 -- Lagrange.Core/Internal/Context/Uploader/PttUploader.cs | 3 --- Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs | 1 - Lagrange.Core/Internal/Event/Message/ImageUploadEvent.cs | 1 - Lagrange.Core/Internal/Event/Message/VideoUploadEvent.cs | 1 - .../Login/NTLogin/Plain/Body/SsoNTLoginPasswordLogin.cs | 1 - .../Packets/Message/Element/Implementation/CustomFace.cs | 1 - .../Service/Oidb/Response/OidbSvcTrpcTcp0xFE5_2Response.cs | 1 - .../Internal/Service/Action/GroupMuteGlobalService.cs | 1 - Lagrange.Core/Internal/Service/BaseService.cs | 1 - Lagrange.Core/Internal/Service/Message/PushMessageService.cs | 2 -- Lagrange.Core/Message/Entity/ImageEntity.cs | 2 -- Lagrange.Core/Message/Entity/MentionEntity.cs | 1 - Lagrange.Core/Message/Entity/RecordEntity.cs | 1 - Lagrange.Core/Message/MessagePacker.cs | 1 - Lagrange.Core/Utility/Binary/Compression/ZCompression.cs | 1 - Lagrange.Core/Utility/Crypto/TeaImpl.cs | 1 - Lagrange.Core/Utility/Extension/StringExtension.cs | 2 -- .../Core/Operation/Generic/FetchMFaceKeyOperation.cs | 1 - .../Core/Operation/Generic/GetCredentialsOperation.cs | 1 - Lagrange.OneBot/Core/Operation/Generic/SendPacketOperation.cs | 1 - .../Core/Operation/Info/GetStrangerInfoOperation.cs | 1 - .../Core/Operation/Message/SendGroupMessageOperation.cs | 1 - Lagrange.OneBot/Message/Entity/MusicSegment.cs | 1 - Lagrange.OneBot/Utility/AudioHelper.cs | 3 --- Lagrange.OneBot/Utility/MusicSigner.cs | 1 - 27 files changed, 35 deletions(-) diff --git a/Lagrange.Core/Internal/Context/Uploader/FileUploader.cs b/Lagrange.Core/Internal/Context/Uploader/FileUploader.cs index 5262be42b..abad6c619 100644 --- a/Lagrange.Core/Internal/Context/Uploader/FileUploader.cs +++ b/Lagrange.Core/Internal/Context/Uploader/FileUploader.cs @@ -1,5 +1,4 @@ using Lagrange.Core.Internal.Event.Message; -using Lagrange.Core.Internal.Event.System; using Lagrange.Core.Internal.Packets.Service.Highway; using Lagrange.Core.Message; using Lagrange.Core.Message.Entity; diff --git a/Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs b/Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs index ce222e84c..14b0d7221 100644 --- a/Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs +++ b/Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs @@ -1,6 +1,4 @@ using Lagrange.Core.Internal.Event.Message; -using Lagrange.Core.Internal.Event.System; -using Lagrange.Core.Internal.Packets.Service.Highway; using Lagrange.Core.Message; using Lagrange.Core.Message.Entity; using Lagrange.Core.Utility.Extension; diff --git a/Lagrange.Core/Internal/Context/Uploader/PttUploader.cs b/Lagrange.Core/Internal/Context/Uploader/PttUploader.cs index 27bc3ff0a..f2bd489a1 100644 --- a/Lagrange.Core/Internal/Context/Uploader/PttUploader.cs +++ b/Lagrange.Core/Internal/Context/Uploader/PttUploader.cs @@ -1,7 +1,4 @@ using Lagrange.Core.Internal.Event.Message; -using Lagrange.Core.Internal.Event.System; -using Lagrange.Core.Internal.Packets.Service.Highway; -using Lagrange.Core.Internal.Packets.Service.Oidb.Common; using Lagrange.Core.Message; using Lagrange.Core.Message.Entity; using Lagrange.Core.Utility.Extension; diff --git a/Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs b/Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs index 4ba18985d..5e5df607a 100644 --- a/Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs +++ b/Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs @@ -1,5 +1,4 @@ using Lagrange.Core.Internal.Event.Message; -using Lagrange.Core.Internal.Packets.Service.Highway; using Lagrange.Core.Message; using Lagrange.Core.Message.Entity; using Lagrange.Core.Utility.Extension; diff --git a/Lagrange.Core/Internal/Event/Message/ImageUploadEvent.cs b/Lagrange.Core/Internal/Event/Message/ImageUploadEvent.cs index 7c4012acc..805b8b0ee 100644 --- a/Lagrange.Core/Internal/Event/Message/ImageUploadEvent.cs +++ b/Lagrange.Core/Internal/Event/Message/ImageUploadEvent.cs @@ -1,4 +1,3 @@ -using Lagrange.Core.Internal.Packets.Message.Component; using Lagrange.Core.Internal.Packets.Message.Element.Implementation; using Lagrange.Core.Internal.Packets.Service.Oidb.Common; using Lagrange.Core.Message.Entity; diff --git a/Lagrange.Core/Internal/Event/Message/VideoUploadEvent.cs b/Lagrange.Core/Internal/Event/Message/VideoUploadEvent.cs index cf4fe391b..70f256a2e 100644 --- a/Lagrange.Core/Internal/Event/Message/VideoUploadEvent.cs +++ b/Lagrange.Core/Internal/Event/Message/VideoUploadEvent.cs @@ -1,4 +1,3 @@ -using Lagrange.Core.Internal.Packets.Message.Component; using Lagrange.Core.Internal.Packets.Message.Element.Implementation; using Lagrange.Core.Internal.Packets.Service.Oidb.Common; using Lagrange.Core.Message.Entity; diff --git a/Lagrange.Core/Internal/Packets/Login/NTLogin/Plain/Body/SsoNTLoginPasswordLogin.cs b/Lagrange.Core/Internal/Packets/Login/NTLogin/Plain/Body/SsoNTLoginPasswordLogin.cs index aa09852ee..43f8def1d 100644 --- a/Lagrange.Core/Internal/Packets/Login/NTLogin/Plain/Body/SsoNTLoginPasswordLogin.cs +++ b/Lagrange.Core/Internal/Packets/Login/NTLogin/Plain/Body/SsoNTLoginPasswordLogin.cs @@ -1,5 +1,4 @@ using Lagrange.Core.Utility.Binary; -using static Lagrange.Core.Utility.Binary.BinaryPacket; namespace Lagrange.Core.Internal.Packets.Login.NTLogin.Plain.Body; diff --git a/Lagrange.Core/Internal/Packets/Message/Element/Implementation/CustomFace.cs b/Lagrange.Core/Internal/Packets/Message/Element/Implementation/CustomFace.cs index 34b6d6792..a0d95b214 100644 --- a/Lagrange.Core/Internal/Packets/Message/Element/Implementation/CustomFace.cs +++ b/Lagrange.Core/Internal/Packets/Message/Element/Implementation/CustomFace.cs @@ -1,4 +1,3 @@ -using Lagrange.Core.Internal.Packets.Message.Element.Implementation.Extra; using ProtoBuf; // ReSharper disable InconsistentNaming diff --git a/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0xFE5_2Response.cs b/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0xFE5_2Response.cs index 1522e3e3a..3de7a4040 100644 --- a/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0xFE5_2Response.cs +++ b/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0xFE5_2Response.cs @@ -1,4 +1,3 @@ -using Lagrange.Core.Internal.Packets.Service.Oidb.Common; using ProtoBuf; namespace Lagrange.Core.Internal.Packets.Service.Oidb.Response; diff --git a/Lagrange.Core/Internal/Service/Action/GroupMuteGlobalService.cs b/Lagrange.Core/Internal/Service/Action/GroupMuteGlobalService.cs index 09e632a75..f75c00a53 100644 --- a/Lagrange.Core/Internal/Service/Action/GroupMuteGlobalService.cs +++ b/Lagrange.Core/Internal/Service/Action/GroupMuteGlobalService.cs @@ -4,7 +4,6 @@ using Lagrange.Core.Internal.Packets.Service.Oidb; using Lagrange.Core.Internal.Packets.Service.Oidb.Request; using Lagrange.Core.Internal.Packets.Service.Oidb.Response; -using Lagrange.Core.Utility.Binary; using ProtoBuf.Meta; namespace Lagrange.Core.Internal.Service.Action; diff --git a/Lagrange.Core/Internal/Service/BaseService.cs b/Lagrange.Core/Internal/Service/BaseService.cs index d43bfb584..ba607ab24 100644 --- a/Lagrange.Core/Internal/Service/BaseService.cs +++ b/Lagrange.Core/Internal/Service/BaseService.cs @@ -1,6 +1,5 @@ using Lagrange.Core.Common; using Lagrange.Core.Internal.Event; -using Lagrange.Core.Utility.Binary; namespace Lagrange.Core.Internal.Service; diff --git a/Lagrange.Core/Internal/Service/Message/PushMessageService.cs b/Lagrange.Core/Internal/Service/Message/PushMessageService.cs index 8b5f0bbd4..a2b25ac7e 100644 --- a/Lagrange.Core/Internal/Service/Message/PushMessageService.cs +++ b/Lagrange.Core/Internal/Service/Message/PushMessageService.cs @@ -1,11 +1,9 @@ using Lagrange.Core.Common; using Lagrange.Core.Internal.Event; -using Lagrange.Core.Internal.Event.Action; using Lagrange.Core.Internal.Event.Message; using Lagrange.Core.Internal.Event.Notify; using Lagrange.Core.Internal.Packets.Message; using Lagrange.Core.Internal.Packets.Message.Notify; -using Lagrange.Core.Internal.Service.Action; using Lagrange.Core.Message; using Lagrange.Core.Utility.Binary; using Lagrange.Core.Utility.Extension; diff --git a/Lagrange.Core/Message/Entity/ImageEntity.cs b/Lagrange.Core/Message/Entity/ImageEntity.cs index bf0c7ab4e..a45cd79d5 100644 --- a/Lagrange.Core/Message/Entity/ImageEntity.cs +++ b/Lagrange.Core/Message/Entity/ImageEntity.cs @@ -1,8 +1,6 @@ using System.Numerics; -using Lagrange.Core.Internal.Packets.Message.Component.Extra; using Lagrange.Core.Internal.Packets.Message.Element; using Lagrange.Core.Internal.Packets.Message.Element.Implementation; -using Lagrange.Core.Internal.Packets.Message.Element.Implementation.Extra; using Lagrange.Core.Internal.Packets.Service.Oidb.Common; using Lagrange.Core.Utility.Extension; using ProtoBuf; diff --git a/Lagrange.Core/Message/Entity/MentionEntity.cs b/Lagrange.Core/Message/Entity/MentionEntity.cs index 15a5f6503..28b4e238d 100644 --- a/Lagrange.Core/Message/Entity/MentionEntity.cs +++ b/Lagrange.Core/Message/Entity/MentionEntity.cs @@ -1,7 +1,6 @@ using Lagrange.Core.Internal.Packets.Message.Element; using Lagrange.Core.Internal.Packets.Message.Element.Implementation; using Lagrange.Core.Internal.Packets.Message.Element.Implementation.Extra; -using Lagrange.Core.Utility.Extension; using ProtoBuf; using BitConverter = Lagrange.Core.Utility.Binary.BitConverter; diff --git a/Lagrange.Core/Message/Entity/RecordEntity.cs b/Lagrange.Core/Message/Entity/RecordEntity.cs index 19add127b..74d563481 100644 --- a/Lagrange.Core/Message/Entity/RecordEntity.cs +++ b/Lagrange.Core/Message/Entity/RecordEntity.cs @@ -1,5 +1,4 @@ using Lagrange.Core.Internal.Packets.Message.Component; -using Lagrange.Core.Internal.Packets.Message.Component.Extra; using Lagrange.Core.Internal.Packets.Message.Element; using Lagrange.Core.Internal.Packets.Message.Element.Implementation; using Lagrange.Core.Internal.Packets.Service.Oidb.Common; diff --git a/Lagrange.Core/Message/MessagePacker.cs b/Lagrange.Core/Message/MessagePacker.cs index d0f9e9072..c17700343 100644 --- a/Lagrange.Core/Message/MessagePacker.cs +++ b/Lagrange.Core/Message/MessagePacker.cs @@ -3,7 +3,6 @@ using Lagrange.Core.Common.Entity; using Lagrange.Core.Message.Entity; using Lagrange.Core.Utility.Extension; -using Lagrange.Core.Utility.Generator; using Lagrange.Core.Internal.Packets.Message.C2C; using Lagrange.Core.Internal.Packets.Message.Component; using Lagrange.Core.Internal.Packets.Message.Component.Extra; diff --git a/Lagrange.Core/Utility/Binary/Compression/ZCompression.cs b/Lagrange.Core/Utility/Binary/Compression/ZCompression.cs index 4335dbe1a..29c7f9439 100644 --- a/Lagrange.Core/Utility/Binary/Compression/ZCompression.cs +++ b/Lagrange.Core/Utility/Binary/Compression/ZCompression.cs @@ -1,4 +1,3 @@ -using System.IO.Compression; using System.Text; namespace Lagrange.Core.Utility.Binary.Compression; diff --git a/Lagrange.Core/Utility/Crypto/TeaImpl.cs b/Lagrange.Core/Utility/Crypto/TeaImpl.cs index 9d46c0c8d..f7c9f737a 100644 --- a/Lagrange.Core/Utility/Crypto/TeaImpl.cs +++ b/Lagrange.Core/Utility/Crypto/TeaImpl.cs @@ -1,5 +1,4 @@ using Lagrange.Core.Utility.Crypto.Provider.Tea; -using Lagrange.Core.Utility.Extension; namespace Lagrange.Core.Utility.Crypto; diff --git a/Lagrange.Core/Utility/Extension/StringExtension.cs b/Lagrange.Core/Utility/Extension/StringExtension.cs index 247f4a2b8..bc9347498 100644 --- a/Lagrange.Core/Utility/Extension/StringExtension.cs +++ b/Lagrange.Core/Utility/Extension/StringExtension.cs @@ -1,5 +1,3 @@ -using System.Globalization; - namespace Lagrange.Core.Utility.Extension; internal static class StringExtension diff --git a/Lagrange.OneBot/Core/Operation/Generic/FetchMFaceKeyOperation.cs b/Lagrange.OneBot/Core/Operation/Generic/FetchMFaceKeyOperation.cs index 91e7b7ad1..558d9f218 100644 --- a/Lagrange.OneBot/Core/Operation/Generic/FetchMFaceKeyOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Generic/FetchMFaceKeyOperation.cs @@ -1,6 +1,5 @@ using System.Text.Json; using System.Text.Json.Nodes; -using System.Text.Json.Serialization; using Lagrange.Core; using Lagrange.Core.Common.Interface.Api; using Lagrange.OneBot.Core.Entity.Action; diff --git a/Lagrange.OneBot/Core/Operation/Generic/GetCredentialsOperation.cs b/Lagrange.OneBot/Core/Operation/Generic/GetCredentialsOperation.cs index 53ff2ad52..458189c3f 100644 --- a/Lagrange.OneBot/Core/Operation/Generic/GetCredentialsOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Generic/GetCredentialsOperation.cs @@ -3,7 +3,6 @@ using Lagrange.Core.Common.Interface.Api; using Lagrange.OneBot.Core.Entity.Action; using Lagrange.OneBot.Core.Notify; -using Lagrange.OneBot.Utility; namespace Lagrange.OneBot.Core.Operation.Generic; diff --git a/Lagrange.OneBot/Core/Operation/Generic/SendPacketOperation.cs b/Lagrange.OneBot/Core/Operation/Generic/SendPacketOperation.cs index 6955c7577..5cb743e21 100644 --- a/Lagrange.OneBot/Core/Operation/Generic/SendPacketOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Generic/SendPacketOperation.cs @@ -2,7 +2,6 @@ using System.Text.Json.Nodes; using Lagrange.Core; using Lagrange.Core.Internal.Packets; -using Lagrange.Core.Utility.Binary; using Lagrange.Core.Utility.Extension; using Lagrange.OneBot.Core.Entity.Action; using Lagrange.OneBot.Core.Entity.Action.Response; diff --git a/Lagrange.OneBot/Core/Operation/Info/GetStrangerInfoOperation.cs b/Lagrange.OneBot/Core/Operation/Info/GetStrangerInfoOperation.cs index b08c38dc6..ddc007db4 100644 --- a/Lagrange.OneBot/Core/Operation/Info/GetStrangerInfoOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Info/GetStrangerInfoOperation.cs @@ -1,7 +1,6 @@ using System.Text.Json; using System.Text.Json.Nodes; using Lagrange.Core; -using Lagrange.Core.Common.Entity; using Lagrange.Core.Common.Interface.Api; using Lagrange.OneBot.Core.Entity; using Lagrange.OneBot.Core.Entity.Action; diff --git a/Lagrange.OneBot/Core/Operation/Message/SendGroupMessageOperation.cs b/Lagrange.OneBot/Core/Operation/Message/SendGroupMessageOperation.cs index bac049788..79703df7a 100644 --- a/Lagrange.OneBot/Core/Operation/Message/SendGroupMessageOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/SendGroupMessageOperation.cs @@ -6,7 +6,6 @@ using Lagrange.OneBot.Core.Entity.Action.Response; using Lagrange.OneBot.Core.Operation.Converters; using Lagrange.OneBot.Database; -using LiteDB; namespace Lagrange.OneBot.Core.Operation.Message; diff --git a/Lagrange.OneBot/Message/Entity/MusicSegment.cs b/Lagrange.OneBot/Message/Entity/MusicSegment.cs index 246a5f177..84ee2f2dd 100644 --- a/Lagrange.OneBot/Message/Entity/MusicSegment.cs +++ b/Lagrange.OneBot/Message/Entity/MusicSegment.cs @@ -1,7 +1,6 @@ using Lagrange.Core.Message.Entity; using Lagrange.Core.Message; using System.Text.Json.Serialization; -using Lagrange.Core.Utility.Network; using Lagrange.OneBot.Utility; namespace Lagrange.OneBot.Message.Entity; diff --git a/Lagrange.OneBot/Utility/AudioHelper.cs b/Lagrange.OneBot/Utility/AudioHelper.cs index b76a82cd8..c681e1cb3 100644 --- a/Lagrange.OneBot/Utility/AudioHelper.cs +++ b/Lagrange.OneBot/Utility/AudioHelper.cs @@ -1,7 +1,4 @@ using System.Buffers.Binary; -using System.Runtime.InteropServices; -using Lagrange.Core.Utility.Binary; -using BitConverter = System.BitConverter; namespace Lagrange.OneBot.Utility; diff --git a/Lagrange.OneBot/Utility/MusicSigner.cs b/Lagrange.OneBot/Utility/MusicSigner.cs index d94c59b08..c7ebd8c9c 100644 --- a/Lagrange.OneBot/Utility/MusicSigner.cs +++ b/Lagrange.OneBot/Utility/MusicSigner.cs @@ -2,7 +2,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using System.Net.Http.Json; -using System.Text.Json; using System.Text.Json.Nodes; namespace Lagrange.OneBot.Utility; From 2cedb31344641d3e70f3761d9ea22a9133114e2d Mon Sep 17 00:00:00 2001 From: pk5ls20 Date: Tue, 3 Sep 2024 21:16:27 +0800 Subject: [PATCH 09/12] [All] Add MoveGroupFileOp & fix DeleteGroupFileOp (#572) * [All] Add MoveGroupFileOp & fix DeleteGroupFileOp * [OneBot] Fix format --- .../Common/Interface/Api/GroupExt.cs | 4 ++-- .../Logic/Implementation/OperationLogic.cs | 12 ++++++++---- .../Event/Action/GroupFSDeleteEvent.cs | 10 +++++++--- .../Internal/Event/Action/GroupFSMoveEvent.cs | 12 ++++++++---- .../Response/OidbSvcTrpcTcp0x6D6Response.cs | 6 ++++++ .../OidbSvcTrpcTcp0x6D6_3_4_5Response.cs | 16 ++++++++++++++++ .../Service/Action/GroupFSMoveService.cs | 5 +++-- .../Service/Message/GroupFSDeleteService.cs | 7 ++++--- .../Core/Entity/Action/OneBotMoveFile.cs | 15 +++++++++++++++ .../Core/Operation/File/GroupFSOperations.cs | 19 +++++++++++++++++-- 10 files changed, 86 insertions(+), 20 deletions(-) create mode 100644 Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D6_3_4_5Response.cs create mode 100644 Lagrange.OneBot/Core/Entity/Action/OneBotMoveFile.cs diff --git a/Lagrange.Core/Common/Interface/Api/GroupExt.cs b/Lagrange.Core/Common/Interface/Api/GroupExt.cs index 4e45d0fb9..d8798609a 100644 --- a/Lagrange.Core/Common/Interface/Api/GroupExt.cs +++ b/Lagrange.Core/Common/Interface/Api/GroupExt.cs @@ -101,10 +101,10 @@ public static Task> FetchGroupFSList(this BotContext bot, uint public static Task FetchGroupFSDownload(this BotContext bot, uint groupUin, string fileId) => bot.ContextCollection.Business.OperationLogic.FetchGroupFSDownload(groupUin, fileId); - public static Task GroupFSMove(this BotContext bot, uint groupUin, string fileId, string parentDirectory, string targetDirectory) + public static Task<(int, string)> GroupFSMove(this BotContext bot, uint groupUin, string fileId, string parentDirectory, string targetDirectory) => bot.ContextCollection.Business.OperationLogic.GroupFSMove(groupUin, fileId, parentDirectory, targetDirectory); - public static Task GroupFSDelete(this BotContext bot, uint groupUin, string fileId) + public static Task<(int, string)> GroupFSDelete(this BotContext bot, uint groupUin, string fileId) => bot.ContextCollection.Business.OperationLogic.GroupFSDelete(groupUin, fileId); public static Task<(int, string)> GroupFSCreateFolder(this BotContext bot, uint groupUin, string name) diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs index 59aa9169d..d9a917fbb 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs @@ -159,18 +159,22 @@ public async Task FetchGroupFSDownload(uint groupUin, string fileId) return $"{((GroupFSDownloadEvent)events[0]).FileUrl}{fileId}"; } - public async Task GroupFSMove(uint groupUin, string fileId, string parentDirectory, string targetDirectory) + public async Task<(int, string)> GroupFSMove(uint groupUin, string fileId, string parentDirectory, string targetDirectory) { var groupFSMoveEvent = GroupFSMoveEvent.Create(groupUin, fileId, parentDirectory, targetDirectory); var events = await Collection.Business.SendEvent(groupFSMoveEvent); - return events.Count != 0 && ((GroupFSMoveEvent)events[0]).ResultCode == 0; + var retCode = events.Count > 0 ? ((GroupFSMoveEvent)events[0]).ResultCode : -1; + var retMsg = events.Count > 0 ? ((GroupFSMoveEvent)events[0]).RetMsg : ""; + return new(retCode, retMsg); } - public async Task GroupFSDelete(uint groupUin, string fileId) + public async Task<(int, string)> GroupFSDelete(uint groupUin, string fileId) { var groupFSDeleteEvent = GroupFSDeleteEvent.Create(groupUin, fileId); var events = await Collection.Business.SendEvent(groupFSDeleteEvent); - return events.Count != 0 && ((GroupFSDeleteEvent)events[0]).ResultCode == 0; + var retCode = events.Count > 0 ? ((GroupFSDeleteEvent)events[0]).ResultCode : -1; + var retMsg = events.Count > 0 ? ((GroupFSDeleteEvent)events[0]).RetMsg : ""; + return new(retCode, retMsg); } public async Task<(int, string)> GroupFSCreateFolder(uint groupUin, string name) diff --git a/Lagrange.Core/Internal/Event/Action/GroupFSDeleteEvent.cs b/Lagrange.Core/Internal/Event/Action/GroupFSDeleteEvent.cs index 8af23feee..4039b2145 100644 --- a/Lagrange.Core/Internal/Event/Action/GroupFSDeleteEvent.cs +++ b/Lagrange.Core/Internal/Event/Action/GroupFSDeleteEvent.cs @@ -6,16 +6,20 @@ internal class GroupFSDeleteEvent : GroupFSOperationEvent { public string FileId { get; set; } + public string RetMsg { get; set; } = string.Empty; + public GroupFSDeleteEvent(uint groupUin, string fileId) : base(groupUin) { FileId = fileId; } - public GroupFSDeleteEvent(int resultCode) : base(resultCode) { } + public GroupFSDeleteEvent(int resultCode, string retMsg) : base(resultCode) + { + RetMsg = retMsg; + } public static GroupFSDeleteEvent Create(uint groupUin, string fileId) => new(groupUin, fileId); - public static GroupFSDeleteEvent Result(int resultCode) - => new(resultCode); + public static GroupFSDeleteEvent Result(int resultCode, string retMsg) => new(resultCode, retMsg); } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Event/Action/GroupFSMoveEvent.cs b/Lagrange.Core/Internal/Event/Action/GroupFSMoveEvent.cs index 882f1744f..265c07323 100644 --- a/Lagrange.Core/Internal/Event/Action/GroupFSMoveEvent.cs +++ b/Lagrange.Core/Internal/Event/Action/GroupFSMoveEvent.cs @@ -10,18 +10,22 @@ internal class GroupFSMoveEvent : GroupFSOperationEvent public string TargetDirectory { get; set; } + public string RetMsg { get; set; } = string.Empty; + private GroupFSMoveEvent(uint groupUin, string fileId, string parentDirectory, string targetDirectory) : base(groupUin) { FileId = fileId; ParentDirectory = parentDirectory; TargetDirectory = targetDirectory; } - - private GroupFSMoveEvent(int resultCode) : base(resultCode) { } + + private GroupFSMoveEvent(int resultCode, string retMsg) : base(resultCode) + { + RetMsg = retMsg; + } public static GroupFSMoveEvent Create(uint groupUin, string fileId, string parentDirectory, string targetDirectory) => new(groupUin, fileId, parentDirectory, targetDirectory); - public static GroupFSMoveEvent Result(int resultCode) - => new(resultCode); + public static GroupFSMoveEvent Result(int resultCode, string retMsg) => new(resultCode, retMsg); } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D6Response.cs b/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D6Response.cs index b9a9d56f4..f403eae9c 100644 --- a/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D6Response.cs +++ b/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D6Response.cs @@ -11,4 +11,10 @@ internal class OidbSvcTrpcTcp0x6D6Response [ProtoMember(1)] public OidbSvcTrpcTcp0x6D6_0Response Upload { get; set; } [ProtoMember(3)] public OidbSvcTrpcTcp0x6D6_2Response Download { get; set; } + + [ProtoMember(4)] public OidbSvcTrpcTcp0x6D6_3_4_5Response Delete { get; set; } + + [ProtoMember(5)] public OidbSvcTrpcTcp0x6D6_3_4_5Response Rename { get; set; } + + [ProtoMember(6)] public OidbSvcTrpcTcp0x6D6_3_4_5Response Move { get; set; } } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D6_3_4_5Response.cs b/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D6_3_4_5Response.cs new file mode 100644 index 000000000..ac64f35d0 --- /dev/null +++ b/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D6_3_4_5Response.cs @@ -0,0 +1,16 @@ +using ProtoBuf; + +namespace Lagrange.Core.Internal.Packets.Service.Oidb.Response; + +#pragma warning disable CS8618 +// ReSharper disable InconsistentNaming + +[ProtoContract] +internal class OidbSvcTrpcTcp0x6D6_3_4_5Response +{ + [ProtoMember(1)] public int RetCode { get; set; } + + [ProtoMember(2)] public string RetMsg { get; set; } + + [ProtoMember(3)] public string ClientWording { get; set; } +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Service/Action/GroupFSMoveService.cs b/Lagrange.Core/Internal/Service/Action/GroupFSMoveService.cs index dececd134..c7af45b51 100644 --- a/Lagrange.Core/Internal/Service/Action/GroupFSMoveService.cs +++ b/Lagrange.Core/Internal/Service/Action/GroupFSMoveService.cs @@ -3,6 +3,7 @@ using Lagrange.Core.Internal.Event.Action; using Lagrange.Core.Internal.Packets.Service.Oidb; using Lagrange.Core.Internal.Packets.Service.Oidb.Request; +using Lagrange.Core.Internal.Packets.Service.Oidb.Response; using Lagrange.Core.Utility.Extension; using ProtoBuf; @@ -36,9 +37,9 @@ protected override bool Build(GroupFSMoveEvent input, BotKeystore keystore, BotA protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out GroupFSMoveEvent output, out List? extraEvents) { - var packet = Serializer.Deserialize>(input); + var packet = Serializer.Deserialize>(input); - output = GroupFSMoveEvent.Result((int)packet.ErrorCode); + output = GroupFSMoveEvent.Result(packet.Body.Move.RetCode, packet.Body.Move.ClientWording); extraEvents = null; return true; } diff --git a/Lagrange.Core/Internal/Service/Message/GroupFSDeleteService.cs b/Lagrange.Core/Internal/Service/Message/GroupFSDeleteService.cs index cbab7a1a2..b3ff6dfbe 100644 --- a/Lagrange.Core/Internal/Service/Message/GroupFSDeleteService.cs +++ b/Lagrange.Core/Internal/Service/Message/GroupFSDeleteService.cs @@ -3,6 +3,7 @@ using Lagrange.Core.Internal.Event.Action; using Lagrange.Core.Internal.Packets.Service.Oidb; using Lagrange.Core.Internal.Packets.Service.Oidb.Request; +using Lagrange.Core.Internal.Packets.Service.Oidb.Response; using Lagrange.Core.Utility.Extension; using ProtoBuf; @@ -23,7 +24,7 @@ protected override bool Build(GroupFSDeleteEvent input, BotKeystore keystore, Bo BusId = 102, FileId = input.FileId } - }); + }, 0x6D6, 3, false, true); output = packet.Serialize(); extraPackets = null; @@ -33,9 +34,9 @@ protected override bool Build(GroupFSDeleteEvent input, BotKeystore keystore, Bo protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out GroupFSDeleteEvent output, out List? extraEvents) { - var packet = Serializer.Deserialize>(input); + var packet = Serializer.Deserialize>(input); - output = GroupFSDeleteEvent.Result((int)packet.ErrorCode); + output = GroupFSDeleteEvent.Result(packet.Body.Delete.RetCode, packet.Body.Delete.ClientWording); extraEvents = null; return true; } diff --git a/Lagrange.OneBot/Core/Entity/Action/OneBotMoveFile.cs b/Lagrange.OneBot/Core/Entity/Action/OneBotMoveFile.cs new file mode 100644 index 000000000..48738ef71 --- /dev/null +++ b/Lagrange.OneBot/Core/Entity/Action/OneBotMoveFile.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; + +namespace Lagrange.OneBot.Core.Entity.Action; + +[Serializable] +public class OneBotMoveFile +{ + [JsonPropertyName("group_id")] public uint GroupId { get; set; } + + [JsonPropertyName("file_id")] public string FileId { get; set; } = string.Empty; + + [JsonPropertyName("parent_directory")] public string ParentDirectory { get; set; } = string.Empty; + + [JsonPropertyName("target_directory")] public string TargetDirectory { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Operation/File/GroupFSOperations.cs b/Lagrange.OneBot/Core/Operation/File/GroupFSOperations.cs index e95531af8..3137b08c7 100644 --- a/Lagrange.OneBot/Core/Operation/File/GroupFSOperations.cs +++ b/Lagrange.OneBot/Core/Operation/File/GroupFSOperations.cs @@ -88,6 +88,21 @@ public async Task HandleOperation(BotContext context, JsonNode? pa } } +[Operation("move_group_file")] +public class MoveGroupFileOperation : IOperation +{ + public async Task HandleOperation(BotContext context, JsonNode? payload) + { + if (payload.Deserialize(SerializerOptions.DefaultOptions) is { } file) + { + var res = await context.GroupFSMove(file.GroupId, file.FileId, file.ParentDirectory, file.TargetDirectory); + return new OneBotResult(new JsonObject { { "msg", res.Item2 } }, res.Item1, res.Item1 == 0 ? "ok" : "failed"); + } + + throw new Exception(); + } +} + [Operation("delete_group_file")] public class DeleteGroupFileOperation : IOperation { @@ -95,8 +110,8 @@ public async Task HandleOperation(BotContext context, JsonNode? pa { if (payload.Deserialize(SerializerOptions.DefaultOptions) is { } file) { - await context.GroupFSDelete(file.GroupId, file.FileId); - return new OneBotResult(null, 0, "ok"); + var res = await context.GroupFSDelete(file.GroupId, file.FileId); + return new OneBotResult(new JsonObject { { "msg", res.Item2 } }, res.Item1, res.Item1 == 0 ? "ok" : "failed"); } throw new Exception(); From a5bf350deb4a7cb3c86fa87fbb645945fce7184e Mon Sep 17 00:00:00 2001 From: Linwenxuan04 Date: Tue, 3 Sep 2024 09:30:00 -0400 Subject: [PATCH 10/12] [Core] Refactor --- .../Internal/Service/Message/PushMessageService.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Lagrange.Core/Internal/Service/Message/PushMessageService.cs b/Lagrange.Core/Internal/Service/Message/PushMessageService.cs index a2b25ac7e..7a6c44ae9 100644 --- a/Lagrange.Core/Internal/Service/Message/PushMessageService.cs +++ b/Lagrange.Core/Internal/Service/Message/PushMessageService.cs @@ -268,12 +268,9 @@ private static void ProcessEvent0x210(Span payload, PushMsg msg, List(content.AsSpan()); var templates = greyTip.MsgTemplParam.ToDictionary(x => x.Name, x => x.Value); - if (!templates.TryGetValue("action_str", out var actionStr) || actionStr == null) + if (!templates.TryGetValue("action_str", out var actionStr) && !templates.TryGetValue("alt_str1", out actionStr)) { - if (!templates.TryGetValue("alt_str1", out actionStr) || actionStr == null) - { - actionStr = string.Empty; - } + actionStr = string.Empty; } if (greyTip.BusiType == 12) // poke From 2b8014d984c4f0eb20439d1e3ee8e6b852a5b55d Mon Sep 17 00:00:00 2001 From: Linwenxuan04 Date: Tue, 3 Sep 2024 11:05:01 -0400 Subject: [PATCH 11/12] =?UTF-8?q?[Core]=20=E6=B2=A1=E6=94=B9=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Internal/Service/Message/PushMessageService.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Lagrange.Core/Internal/Service/Message/PushMessageService.cs b/Lagrange.Core/Internal/Service/Message/PushMessageService.cs index 7a6c44ae9..5f0ad2f23 100644 --- a/Lagrange.Core/Internal/Service/Message/PushMessageService.cs +++ b/Lagrange.Core/Internal/Service/Message/PushMessageService.cs @@ -203,12 +203,9 @@ private static void ProcessEvent0x2DC(Span payload, PushMsg msg, List x.Name, x => x.Value); - if (!templates.TryGetValue("action_str", out var actionStr) || actionStr == null) + if (!templates.TryGetValue("action_str", out var actionStr) && !templates.TryGetValue("alt_str1", out actionStr)) { - if (!templates.TryGetValue("alt_str1", out actionStr) || actionStr == null) - { - actionStr = string.Empty; - } + actionStr = string.Empty; } if (greyTip.GeneralGrayTip.BusiType == 12) // poke From afd3b177b8dc54633e2aa325ffb91f6a17fd8a67 Mon Sep 17 00:00:00 2001 From: pk5ls20 Date: Wed, 4 Sep 2024 21:42:07 +0800 Subject: [PATCH 12/12] [Core] Fetch the filtered requests simultaneously in FetchGroupRequests (#571) --- .../Logic/Implementation/OperationLogic.cs | 2 +- .../Oidb/Request/OidbSvcTrpcTcp0x10C0_2.cs | 17 ++++++ ...nse.cs => OidbSvcTrpcTcp0x10C0Response.cs} | 18 +++---- .../FetchFilteredGroupRequestsService.cs | 52 +++++++++++++++++++ .../System/FetchGroupRequestsService.cs | 6 +-- 5 files changed, 82 insertions(+), 13 deletions(-) create mode 100644 Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x10C0_2.cs rename Lagrange.Core/Internal/Packets/Service/Oidb/Response/{OidbSvcTrpcTcp0x10C0_1Response.cs => OidbSvcTrpcTcp0x10C0Response.cs} (66%) create mode 100644 Lagrange.Core/Internal/Service/System/FetchFilteredGroupRequestsService.cs diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs index d9a917fbb..05f9771ca 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs @@ -255,7 +255,7 @@ public async Task RecallGroupMessage(MessageChain chain) var events = await Collection.Business.SendEvent(fetchRequestsEvent); if (events.Count == 0) return null; - var resolved = ((FetchGroupRequestsEvent)events[0]).Events; + var resolved = events.Cast().SelectMany(e => e.Events).ToList(); var results = new List(); foreach (var result in resolved) diff --git a/Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x10C0_2.cs b/Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x10C0_2.cs new file mode 100644 index 000000000..20e5afef7 --- /dev/null +++ b/Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x10C0_2.cs @@ -0,0 +1,17 @@ +using ProtoBuf; + +namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request; + +// ReSharper disable InconsistentNaming + +/// +/// Fetch Friends & Group Notification filtered List +/// +[ProtoContract] +[OidbSvcTrpcTcp(0x10c0, 2)] +internal class OidbSvcTrpcTcp0x10C0_2 +{ + [ProtoMember(1)] public uint Count { get; set; } // 20 + + [ProtoMember(2)] public uint Field2 { get; set; } // 0 +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x10C0_1Response.cs b/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x10C0Response.cs similarity index 66% rename from Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x10C0_1Response.cs rename to Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x10C0Response.cs index e89084aad..da2e7542b 100644 --- a/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x10C0_1Response.cs +++ b/Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x10C0Response.cs @@ -6,9 +6,9 @@ namespace Lagrange.Core.Internal.Packets.Service.Oidb.Response; #pragma warning disable CS8618 [ProtoContract] -internal class OidbSvcTrpcTcp0x10C0_1Response +internal class OidbSvcTrpcTcp0x10C0Response { - [ProtoMember(1)] public List Requests { get; set; } + [ProtoMember(1)] public List? Requests { get; set; } [ProtoMember(2)] public ulong Field2 { get; set; } @@ -22,7 +22,7 @@ internal class OidbSvcTrpcTcp0x10C0_1Response } [ProtoContract] -internal class OidbSvcTrpcTcp0x10C0_1ResponseRequests +internal class OidbSvcTrpcTcp0x10C0ResponseRequests { [ProtoMember(1)] public ulong Sequence { get; set; } @@ -30,13 +30,13 @@ internal class OidbSvcTrpcTcp0x10C0_1ResponseRequests [ProtoMember(3)] public uint State { get; set; } // 2 for Join, 1 for waiting for action - [ProtoMember(4)] public OidbSvcTrpcTcp0x10C0_1ResponseGroup Group { get; set; } + [ProtoMember(4)] public OidbSvcTrpcTcp0x10C0ResponseGroup Group { get; set; } - [ProtoMember(5)] public OidbSvcTrpcTcp0x10C0_1ResponseUser Target { get; set; } + [ProtoMember(5)] public OidbSvcTrpcTcp0x10C0ResponseUser Target { get; set; } - [ProtoMember(6)] public OidbSvcTrpcTcp0x10C0_1ResponseUser? Invitor { get; set; } + [ProtoMember(6)] public OidbSvcTrpcTcp0x10C0ResponseUser? Invitor { get; set; } - [ProtoMember(7)] public OidbSvcTrpcTcp0x10C0_1ResponseUser? Operator { get; set; } + [ProtoMember(7)] public OidbSvcTrpcTcp0x10C0ResponseUser? Operator { get; set; } [ProtoMember(9)] public string Field9 { get; set; } @@ -44,7 +44,7 @@ internal class OidbSvcTrpcTcp0x10C0_1ResponseRequests } [ProtoContract] -internal class OidbSvcTrpcTcp0x10C0_1ResponseGroup +internal class OidbSvcTrpcTcp0x10C0ResponseGroup { [ProtoMember(1)] public uint GroupUin { get; set; } @@ -52,7 +52,7 @@ internal class OidbSvcTrpcTcp0x10C0_1ResponseGroup } [ProtoContract] -internal class OidbSvcTrpcTcp0x10C0_1ResponseUser +internal class OidbSvcTrpcTcp0x10C0ResponseUser { [ProtoMember(1)] public string Uid { get; set; } diff --git a/Lagrange.Core/Internal/Service/System/FetchFilteredGroupRequestsService.cs b/Lagrange.Core/Internal/Service/System/FetchFilteredGroupRequestsService.cs new file mode 100644 index 000000000..b25ec4b0b --- /dev/null +++ b/Lagrange.Core/Internal/Service/System/FetchFilteredGroupRequestsService.cs @@ -0,0 +1,52 @@ +using Lagrange.Core.Common; +using Lagrange.Core.Internal.Event; +using Lagrange.Core.Internal.Event.System; +using Lagrange.Core.Internal.Packets.Service.Oidb; +using Lagrange.Core.Internal.Packets.Service.Oidb.Request; +using Lagrange.Core.Internal.Packets.Service.Oidb.Response; +using Lagrange.Core.Utility.Extension; +using ProtoBuf; + +namespace Lagrange.Core.Internal.Service.System; + +[EventSubscribe(typeof(FetchGroupRequestsEvent))] +[Service("OidbSvcTrpcTcp.0x10c0_2")] +internal class FetchFilteredGroupRequestsService : BaseService +{ + protected override bool Build(FetchGroupRequestsEvent input, BotKeystore keystore, BotAppInfo appInfo, + BotDeviceInfo device, out Span output, out List>? extraPackets) + { + var packet = new OidbSvcTrpcTcpBase(new OidbSvcTrpcTcp0x10C0_2 + { + Count = 20, + Field2 = 0 + }); + + output = packet.Serialize(); + extraPackets = null; + return true; + } + + protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out FetchGroupRequestsEvent output, + out List? extraEvents) + { + var payload = Serializer.Deserialize>(input); + var events = payload.Body.Requests?.Select(x => new FetchGroupRequestsEvent.RawEvent( + x.Group.GroupUin, + x.Invitor?.Uid, + x.Invitor?.Name, + x.Target.Uid, + x.Target.Name, + x.Operator?.Uid, + x.Operator?.Name, + x.Sequence, + x.State, + x.EventType, + x.Comment + )).ToList() ?? new List(); + + output = FetchGroupRequestsEvent.Result((int)payload.ErrorCode, events); + extraEvents = null; + return true; + } +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Service/System/FetchGroupRequestsService.cs b/Lagrange.Core/Internal/Service/System/FetchGroupRequestsService.cs index 86a9060fe..02552c32c 100644 --- a/Lagrange.Core/Internal/Service/System/FetchGroupRequestsService.cs +++ b/Lagrange.Core/Internal/Service/System/FetchGroupRequestsService.cs @@ -30,8 +30,8 @@ protected override bool Build(FetchGroupRequestsEvent input, BotKeystore keystor protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out FetchGroupRequestsEvent output, out List? extraEvents) { - var payload = Serializer.Deserialize>(input); - var events = payload.Body.Requests.Select(x => new FetchGroupRequestsEvent.RawEvent( + var payload = Serializer.Deserialize>(input); + var events = payload.Body.Requests?.Select(x => new FetchGroupRequestsEvent.RawEvent( x.Group.GroupUin, x.Invitor?.Uid, x.Invitor?.Name, @@ -43,7 +43,7 @@ protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo x.State, x.EventType, x.Comment - )).ToList(); + )).ToList() ?? new List(); output = FetchGroupRequestsEvent.Result((int)payload.ErrorCode, events); extraEvents = null;