Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复超级表情发送 #638

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
55 changes: 44 additions & 11 deletions Lagrange.Core/Message/Entity/FaceEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ 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)
{
FaceId = faceId;
IsLargeFace = isLargeFace;
}

IEnumerable<Elem> 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
Expand All @@ -46,12 +46,12 @@ IEnumerable<Elem> IMessageEntity.PackElement()
{
ServiceType = 37,
PbElem = stream.ToArray(),
BusinessType = 1
BusinessType = FaceId==114?(uint)2:1,
}
}
};
}

return new Elem[] { new() { Face = new Face { Index = FaceId } } };
}

Expand All @@ -63,10 +63,10 @@ IEnumerable<Elem> 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<QFaceExtra>(common.PbElem.AsSpan());

ushort? faceId = (ushort?)qFace.FaceId;
if (faceId != null) return new FaceEntity((ushort)faceId, true);
}
Expand All @@ -76,9 +76,42 @@ IEnumerable<Elem> IMessageEntity.PackElement()
var qSmallFace = Serializer.Deserialize<QSmallFaceExtra>(append.PbElem.AsSpan());
return new FaceEntity((ushort)qSmallFace.FaceId, false);
}

return null;
}

public string ToPreviewString() => $"[Face][{(IsLargeFace ? "Large" : "Small")}]: {FaceId}";

private static Dictionary<int, string> _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" },
};
}
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<int?>() ?? 0, null)),
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
17 changes: 9 additions & 8 deletions Lagrange.OneBot/Message/Entity/FaceSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}