Skip to content

Commit

Permalink
ob xml
Browse files Browse the repository at this point in the history
  • Loading branch information
sisi0318 committed Nov 21, 2024
1 parent 21ac9b2 commit b90a714
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
16 changes: 13 additions & 3 deletions Lagrange.Core/Message/Entity/XmlEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ namespace Lagrange.Core.Message.Entity;
public class XmlEntity : IMessageEntity
{
public string Xml { get; set; }

public int ServiceId {get;set;}

public XmlEntity() => Xml = "";
public XmlEntity()
{
Xml = "";
ServiceId = 35;
}

public XmlEntity(string xml) => Xml = xml;
public XmlEntity(string xml,int serviceid = 35)
{
Xml = xml;
ServiceId = serviceid;
}

IEnumerable<Elem> IMessageEntity.PackElement()
{
Expand All @@ -22,7 +32,7 @@ IEnumerable<Elem> IMessageEntity.PackElement()
{
RichMsg = new RichMsg
{
ServiceId = 35,
ServiceId = ServiceId,
Template1 = ZCompression.ZCompress(Xml, new byte[] { 0x01 }),
}
}
Expand Down
4 changes: 2 additions & 2 deletions Lagrange.Core/Message/MessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ public MessageBuilder MultiMsg(params MessageChain[] chains)
/// Add a xml entity to the message chain (card message)
/// </summary>
/// <param name="xml">The xml to be sent</param>
public MessageBuilder Xml(string xml)
public MessageBuilder Xml(string xml,int serviceid = 35)
{
var xmlEntity = new XmlEntity(xml);
var xmlEntity = new XmlEntity(xml,serviceid);
_chain.Add(xmlEntity);

return this;
Expand Down
31 changes: 31 additions & 0 deletions Lagrange.OneBot/Message/Entity/XmlSegment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Text.Json.Serialization;
using Lagrange.Core.Message;
using Lagrange.Core.Message.Entity;

namespace Lagrange.OneBot.Message.Entity;

[Serializable]
public partial class XmlSegment(string xml, int serviceid)
{
public XmlSegment() : this("", 35) { }

[JsonPropertyName("data")][CQProperty] public string Xml { get; set; } = xml;

[JsonPropertyName("service_id")][CQProperty] public int ServiceId { get; set; } = serviceid;
}

[SegmentSubscriber(typeof(XmlEntity), "xml")]
public partial class XmlSegment : SegmentBase
{
public override void Build(MessageBuilder builder, SegmentBase segment)
{
if (segment is XmlSegment xml) builder.Xml(xml.Xml,xml.ServiceId);
}

public override SegmentBase FromEntity(MessageChain chain, IMessageEntity entity)
{
if (entity is not XmlEntity xmlEntity) throw new ArgumentException("Invalid entity type.");

return new XmlSegment(xmlEntity.Xml,xmlEntity.ServiceId);
}
}

0 comments on commit b90a714

Please sign in to comment.