Skip to content

Commit

Permalink
[Core] Add Build-only Grey
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan04 committed Oct 7, 2024
1 parent 65ba880 commit ef74c5f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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}"
}
68 changes: 68 additions & 0 deletions Lagrange.Core/Message/Entity/GreyTipEntity.cs
Original file line number Diff line number Diff line change
@@ -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<Elem> 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; }
}
}
8 changes: 8 additions & 0 deletions Lagrange.Core/Message/MessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ef74c5f

Please sign in to comment.