Skip to content

Commit

Permalink
扩大表情id范围
Browse files Browse the repository at this point in the history
  • Loading branch information
sisi0318 committed Nov 11, 2024
1 parent 1cf0527 commit e4427ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static List<OneBotSegment> ConvertToSegment(IEnumerable<JsonObject> elem
var segment = type switch
{
1 => new OneBotSegment("text", new TextSegment(msg["text"]?.GetValue<string>() ?? "")),
2 => new OneBotSegment("face", new FaceSegment(msg["face_index"]?.GetValue<int?>() ?? 0)),
2 => new OneBotSegment("face", new FaceSegment(msg["face_index"]?.GetValue<uint?>() ?? 0)),
3 => new OneBotSegment("image", new ImageSegment(msg["image_url"]?.GetValue<string>() ?? "", "")),
4 => new OneBotSegment("video", new VideoSegment(msg["file_thumbnail_url"]?.GetValue<string>() ?? "")),
_ => throw new InvalidDataException("Unknown type found in essence msg")
Expand Down
20 changes: 15 additions & 5 deletions Lagrange.OneBot/Message/Entity/FaceSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Lagrange.OneBot.Message.Entity;

[Serializable]
public partial class FaceSegment(int id)
public partial class FaceSegment(uint id)
{
public FaceSegment() : this(0) { }

Expand All @@ -18,13 +18,23 @@ public FaceSegment() : this(0) { }
[SegmentSubscriber(typeof(FaceEntity), "face")]
public partial class FaceSegment : SegmentBase
{
private static readonly ushort[] Excluded = [358, 359];
private static readonly uint[] Excluded = { 358, 359 };

public override void Build(MessageBuilder builder, SegmentBase segment)
{
if (segment is FaceSegment faceSegment) builder.Face(ushort.Parse(faceSegment.Id), faceSegment.IsLarge ?? false);
if (segment is FaceSegment faceSegment)
{
if (uint.TryParse(faceSegment.Id, out uint faceId))
{
builder.Face(faceId, faceSegment.IsLarge ?? false);
}
else
{
throw new ArgumentException($"Invalid Face ID: {faceSegment.Id}");
}
}
}

public override SegmentBase? FromEntity(MessageChain chain, IMessageEntity entity)
{
if (entity is not FaceEntity faceEntity) throw new ArgumentException("Invalid entity type.");
Expand Down

0 comments on commit e4427ea

Please sign in to comment.