From ff5b9645b70cd2f203e2c15e6eabd44145fa60d6 Mon Sep 17 00:00:00 2001 From: Fripine Date: Mon, 14 Oct 2024 12:04:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E8=B6=85=E7=BA=A7=E8=A1=A8=E6=83=85?= =?UTF-8?q?=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lagrange.Core/Message/Entity/FaceEntity.cs | 55 +++++++++++++++---- .../Message/GetEssenceMessageListOperation.cs | 2 +- Lagrange.OneBot/Message/Entity/FaceSegment.cs | 17 +++--- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/Lagrange.Core/Message/Entity/FaceEntity.cs b/Lagrange.Core/Message/Entity/FaceEntity.cs index c149e3569..c9112e084 100644 --- a/Lagrange.Core/Message/Entity/FaceEntity.cs +++ b/Lagrange.Core/Message/Entity/FaceEntity.cs @@ -9,9 +9,9 @@ namespace Lagrange.Core.Message.Entity; public class FaceEntity : IMessageEntity { public ushort FaceId { get; } - + public bool IsLargeFace { get; } - + public FaceEntity() { } public FaceEntity(ushort faceId, bool isLargeFace) @@ -19,18 +19,18 @@ public FaceEntity(ushort faceId, bool isLargeFace) FaceId = faceId; IsLargeFace = isLargeFace; } - + IEnumerable IMessageEntity.PackElement() { if (IsLargeFace) { var qFace = new QFaceExtra { - Field1 = "1", - Field2 = "8", + AniStickerPackId = "1", + AniStickerId = _stickerIds.ContainsKey(FaceId) ? _stickerIds[FaceId] : "8", FaceId = FaceId, Field4 = 1, - Field5 = 1, + AniStickerType = FaceId == 114 ? 2 : 1, Field6 = "", Preview = "", Field9 = 1 @@ -46,12 +46,12 @@ IEnumerable IMessageEntity.PackElement() { ServiceType = 37, PbElem = stream.ToArray(), - BusinessType = 1 + BusinessType = FaceId==114?(uint)2:1, } } }; } - + return new Elem[] { new() { Face = new Face { Index = FaceId } } }; } @@ -63,10 +63,10 @@ IEnumerable IMessageEntity.PackElement() if (faceId != null) return new FaceEntity((ushort)faceId, false); } - if (elems.CommonElem is { ServiceType:37, PbElem: not null } common) + if (elems.CommonElem is { ServiceType: 37, PbElem: not null } common) { var qFace = Serializer.Deserialize(common.PbElem.AsSpan()); - + ushort? faceId = (ushort?)qFace.FaceId; if (faceId != null) return new FaceEntity((ushort)faceId, true); } @@ -76,9 +76,42 @@ IEnumerable IMessageEntity.PackElement() var qSmallFace = Serializer.Deserialize(append.PbElem.AsSpan()); return new FaceEntity((ushort)qSmallFace.FaceId, false); } - + return null; } public string ToPreviewString() => $"[Face][{(IsLargeFace ? "Large" : "Small")}]: {FaceId}"; + + private static Dictionary _stickerIds = new() + { + { 5, "16" }, + { 53, "17" }, + { 114, "13" }, + { 137, "18" }, + { 311, "1" }, + { 312, "2" }, + { 313, "3" }, + { 314, "4" }, + { 315, "5" }, + { 316, "6" }, + { 317, "7" }, + { 318, "8" }, + { 319, "9" }, + { 320, "10" }, + { 321, "11" }, + { 324, "12" }, + { 325, "14" }, + { 326, "15" }, + { 333, "19" }, + { 337, "22" }, + { 338, "20" }, + { 339, "21" }, + { 340, "23" }, + { 341, "24" }, + { 342, "26" }, + { 343, "27" }, + { 344, "28" }, + { 345, "29" }, + { 346, "25" }, + }; } \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Operation/Message/GetEssenceMessageListOperation.cs b/Lagrange.OneBot/Core/Operation/Message/GetEssenceMessageListOperation.cs index 2b2acf122..b7750f40f 100644 --- a/Lagrange.OneBot/Core/Operation/Message/GetEssenceMessageListOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/GetEssenceMessageListOperation.cs @@ -67,7 +67,7 @@ private static List ConvertToSegment(IEnumerable elem var segment = type switch { 1 => new OneBotSegment("text", new TextSegment(msg["text"]?.GetValue() ?? "")), - 2 => new OneBotSegment("face", new FaceSegment(msg["face_index"]?.GetValue() ?? 0)), + 2 => new OneBotSegment("face", new FaceSegment(msg["face_index"]?.GetValue() ?? 0, null)), 3 => new OneBotSegment("image", new ImageSegment(msg["image_url"]?.GetValue() ?? "", "")), 4 => new OneBotSegment("video", new VideoSegment(msg["file_thumbnail_url"]?.GetValue() ?? "")), _ => throw new InvalidDataException("Unknown type found in essence msg") diff --git a/Lagrange.OneBot/Message/Entity/FaceSegment.cs b/Lagrange.OneBot/Message/Entity/FaceSegment.cs index 3e2f5d2cc..74c05f199 100644 --- a/Lagrange.OneBot/Message/Entity/FaceSegment.cs +++ b/Lagrange.OneBot/Message/Entity/FaceSegment.cs @@ -5,26 +5,27 @@ namespace Lagrange.OneBot.Message.Entity; [Serializable] -public partial class FaceSegment(int id) +public partial class FaceSegment(int id, string? type) { - public FaceSegment() : this(0) { } - - [JsonPropertyName("id")] [CQProperty] public string Id { get; set; } = id.ToString(); + public FaceSegment() : this(0, null) { } + + [JsonPropertyName("id")][CQProperty] public string Id { get; set; } = id.ToString(); + [JsonPropertyName("type")][CQProperty] public string? Type { get; set; } = type; } [SegmentSubscriber(typeof(FaceEntity), "face")] public partial class FaceSegment : SegmentBase { private static readonly ushort[] Excluded = [358, 359]; - + public override void Build(MessageBuilder builder, SegmentBase segment) { - if (segment is FaceSegment faceSegment) builder.Face(ushort.Parse(faceSegment.Id)); + if (segment is FaceSegment faceSegment) builder.Face(ushort.Parse(faceSegment.Id), faceSegment.Type == "sticker" || false); } - + public override SegmentBase? FromEntity(MessageChain chain, IMessageEntity entity) { if (entity is not FaceEntity faceEntity) throw new ArgumentException("Invalid entity type."); - return Excluded.Contains(faceEntity.FaceId) ? null : new FaceSegment(faceEntity.FaceId); + return Excluded.Contains(faceEntity.FaceId) ? null : new FaceSegment(faceEntity.FaceId, faceEntity.IsLargeFace ? "sticker" : null); } } \ No newline at end of file From 47390e7f059ad8e8fcda32ceac74dd33a1ad55c8 Mon Sep 17 00:00:00 2001 From: Fripine Date: Mon, 14 Oct 2024 12:12:55 +0800 Subject: [PATCH 2/2] chore --- .../Message/Element/Implementation/Extra/QFaceExtra.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lagrange.Core/Internal/Packets/Message/Element/Implementation/Extra/QFaceExtra.cs b/Lagrange.Core/Internal/Packets/Message/Element/Implementation/Extra/QFaceExtra.cs index 49c4d4a12..48bee67de 100644 --- a/Lagrange.Core/Internal/Packets/Message/Element/Implementation/Extra/QFaceExtra.cs +++ b/Lagrange.Core/Internal/Packets/Message/Element/Implementation/Extra/QFaceExtra.cs @@ -8,15 +8,15 @@ namespace Lagrange.Core.Internal.Packets.Message.Element.Implementation.Extra; [ProtoContract] internal class QFaceExtra { - [ProtoMember(1)] public string? Field1 { get; set; } + [ProtoMember(1)] public string? AniStickerPackId { get; set; } - [ProtoMember(2)] public string? Field2 { get; set; } + [ProtoMember(2)] public string? AniStickerId { get; set; } [ProtoMember(3)] public int? FaceId { get; set; } // 318 [ProtoMember(4)] public int? Field4 { get; set; } - [ProtoMember(5)] public int? Field5 { get; set; } + [ProtoMember(5)] public int? AniStickerType { get; set; } [ProtoMember(6)] public string? Field6 { get; set; }