Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
sisi0318 committed Nov 22, 2024
2 parents b90a714 + 606f376 commit d4df713
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
20 changes: 7 additions & 13 deletions Lagrange.Core/Message/Entity/XmlEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@ public class XmlEntity : IMessageEntity
{
public string Xml { get; set; }

public int ServiceId {get;set;}
public int ServiceId { get; set; } = 35;

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

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

public XmlEntity(string xml) => Xml = xml;

public XmlEntity(string xml, int serviceId) => (Xml, ServiceId) = (xml, serviceId);

IEnumerable<Elem> IMessageEntity.PackElement()
{
Expand All @@ -37,7 +31,7 @@ IEnumerable<Elem> IMessageEntity.PackElement()
}
}
};
}
}

IMessageEntity? IMessageEntity.UnpackElement(Elem elems)
{
Expand Down
9 changes: 5 additions & 4 deletions Lagrange.Core/Message/MessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,15 @@ public MessageBuilder MultiMsg(params MessageChain[] chains)

return this;
}

/// <summary>
/// Add a xml entity to the message chain (card message)
/// Add a xml entity (with custom serviceId) to the message chain (card message)
/// </summary>
/// <param name="xml">The xml to be sent</param>
public MessageBuilder Xml(string xml,int serviceid = 35)
/// <param name="serviceId">The service id of the xml</param>
public MessageBuilder Xml(string xml, int serviceId)
{
var xmlEntity = new XmlEntity(xml,serviceid);
var xmlEntity = new XmlEntity(xml, serviceId);
_chain.Add(xmlEntity);

return this;
Expand Down
8 changes: 4 additions & 4 deletions Lagrange.OneBot/Message/Entity/XmlSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ public partial class XmlSegment(string xml, int serviceid)
{
public XmlSegment() : this("", 35) { }

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

[JsonPropertyName("service_id")][CQProperty] public int ServiceId { get; set; } = serviceid;
[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);
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);
return new XmlSegment(xmlEntity.Xml, xmlEntity.ServiceId);
}
}

0 comments on commit d4df713

Please sign in to comment.