diff --git a/Lagrange.Core/Internal/Packets/Message/Component/Extra/GreyTipExtra.cs b/Lagrange.Core/Internal/Packets/Message/Component/Extra/GreyTipExtra.cs new file mode 100644 index 000000000..8985e4a28 --- /dev/null +++ b/Lagrange.Core/Internal/Packets/Message/Component/Extra/GreyTipExtra.cs @@ -0,0 +1,23 @@ +using ProtoBuf; + +namespace Lagrange.Core.Internal.Packets.Message.Component.Extra; + +[ProtoContract] +internal class GreyTipExtra +{ + [ProtoMember(101)] public GreyTipExtraLayer1? Layer1 { get; set; } +} + +[ProtoContract] +internal class GreyTipExtraLayer1 +{ + [ProtoMember(1)] public GreyTipExtraInfo? Info { get; set; } +} + +[ProtoContract] +internal class GreyTipExtraInfo +{ + [ProtoMember(1)] public uint Type { get; set; } // 1 + + [ProtoMember(2)] public string Content { get; set; } = string.Empty; // "{\"gray_tip\":\"谨防兼职刷单、游戏交易、投资荐股、色情招嫖、仿冒公检法及客服人员的网络骗局,如有资金往来请谨慎操作。 \",\"object_type\":3,\"sub_type\":2,\"type\":4}" +} \ No newline at end of file diff --git a/Lagrange.Core/Message/Entity/GreyTipEntity.cs b/Lagrange.Core/Message/Entity/GreyTipEntity.cs new file mode 100644 index 000000000..ee9c4c7fe --- /dev/null +++ b/Lagrange.Core/Message/Entity/GreyTipEntity.cs @@ -0,0 +1,68 @@ +using System.Text.Json; +using System.Text.Json.Serialization; +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.Utility.Extension; + +namespace Lagrange.Core.Message.Entity; + +public class GreyTipEntity : IMessageEntity +{ + public string GreyTip { get; } + + public GreyTipEntity(string greyTip) => GreyTip = greyTip; + + public GreyTipEntity() => GreyTip = string.Empty; + + IEnumerable IMessageEntity.PackElement() + { + var content = new GreyTipContent + { + GrayTip = GreyTip, + ObjectType = 3, + SubType = 2, + Type = 4 + }; + + var extra = new GreyTipExtra + { + Layer1 = new GreyTipExtraLayer1 + { + Info = new GreyTipExtraInfo { Content = JsonSerializer.Serialize(content), Type = 1 } + } + }; + + return new Elem[] + { + new() + { + GeneralFlags = new GeneralFlags + { + PbReserve = extra.Serialize().ToArray(), + } + } + }; + } + + IMessageEntity? IMessageEntity.UnpackElement(Elem elem) + { + throw new NotImplementedException(); + } + + public string ToPreviewString() + { + throw new NotImplementedException(); + } + + private class GreyTipContent + { + [JsonPropertyName("gray_tip")] public string GrayTip { get; set; } = string.Empty; + + [JsonPropertyName("object_type")] public uint ObjectType { get; set; } + + [JsonPropertyName("sub_type")] public uint SubType { get; set; } + + [JsonPropertyName("type")] public uint Type { get; set; } + } +} \ No newline at end of file diff --git a/Lagrange.Core/Message/MessageBuilder.cs b/Lagrange.Core/Message/MessageBuilder.cs index 4120ce0d8..971af07ba 100644 --- a/Lagrange.Core/Message/MessageBuilder.cs +++ b/Lagrange.Core/Message/MessageBuilder.cs @@ -353,6 +353,14 @@ public MessageBuilder MarketFace(string faceId, int tabId, string key, string su return this; } + public MessageBuilder GeryTip(string greyTip) + { + var greyTipEntity = new GreyTipEntity(greyTip); + _chain.Add(greyTipEntity); + + return this; + } + public MessageBuilder Add(IMessageEntity entity) { _chain.Add(entity);