-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[All] Expanded XmlEntity and XmlSegment (#689)
Co-authored-by: 思思 <[email protected]>
- Loading branch information
Showing
3 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |