Skip to content
This repository was archived by the owner on Oct 12, 2025. It is now read-only.

Commit a42456a

Browse files
authored
[All] Various fixes (#801)
1. In some cases, @ALL cannot be successfully parsed as MentionEntity 2. @ALL qq is not all 3. BounceFaceEntity's ToPreviewString is incorrectly written
1 parent 908683e commit a42456a

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using ProtoBuf;
22

3+
#pragma warning disable CS8618
4+
35
namespace Lagrange.Core.Internal.Packets.Message.Element.Implementation.Extra;
46

57
/// <summary>
@@ -8,11 +10,11 @@ namespace Lagrange.Core.Internal.Packets.Message.Element.Implementation.Extra;
810
[ProtoContract]
911
internal class MentionExtra
1012
{
11-
[ProtoMember(3)] public int? Type { get; set; } // 1 for All Member, 2 for Specific Member
12-
13-
[ProtoMember(4)] public uint? Uin { get; set; }
14-
15-
[ProtoMember(5)] public int? Field5 { get; set; } // Const Zero
16-
17-
[ProtoMember(9)] public string? Uid { get; set; } // set this string to "all" to mention everyone in the Group
13+
[ProtoMember(3)] public int Type { get; set; } // 2
14+
15+
[ProtoMember(4)] public uint Uin { get; set; }
16+
17+
[ProtoMember(5)] public int Field5 { get; set; } // Const Zero
18+
19+
[ProtoMember(9)] public string Uid { get; set; } // set this string to "all" to mention everyone in the Group
1820
}

Lagrange.Core/Message/Entity/BounceFaceEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ IEnumerable<Elem> IMessageEntity.PackElement()
104104
return new BounceFaceEntity(extra.Face.FaceId, extra.Count, extra.Name);
105105
}
106106

107-
public string ToPreviewString() => "$[BounceFace | Name: {Name}({FaceId}) | Count: {Count}]";
107+
public string ToPreviewString() => $"[BounceFace | Name: {Name}({FaceId}) | Count: {Count}]";
108108

109109
public string ToPreviewText() => $"[{Name}]x{Count}";
110110
}

Lagrange.Core/Message/Entity/MentionEntity.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ namespace Lagrange.Core.Message.Entity;
1010
public class MentionEntity : IMessageEntity
1111
{
1212
public uint Uin { get; set; }
13-
13+
1414
public string Uid { get; set; }
15-
15+
1616
public string? Name { get; set; }
17-
17+
1818
public MentionEntity()
1919
{
2020
Uin = 0;
2121
Uid = "";
2222
Name = "";
2323
}
24-
24+
2525
/// <summary>
2626
/// Set target to 0 to mention everyone
2727
/// </summary>
@@ -43,7 +43,7 @@ IEnumerable<Elem> IMessageEntity.PackElement()
4343
};
4444
using var stream = new MemoryStream();
4545
Serializer.Serialize(stream, reserve);
46-
46+
4747
return new Elem[]
4848
{
4949
new()
@@ -56,15 +56,18 @@ IEnumerable<Elem> IMessageEntity.PackElement()
5656
}
5757
};
5858
}
59-
59+
6060
IMessageEntity? IMessageEntity.UnpackElement(Elem elems)
6161
{
62-
if (elems.Text is { Str: not null, Attr6Buf: { Length: >= 11 } attr })
62+
if (elems.Text is { Str: not null, PbReserve: { Length: > 0 } extra })
6363
{
64+
MentionExtra info = Serializer.Deserialize<MentionExtra>(extra.AsSpan());
65+
if (info.Type != 2) return null;
66+
6467
return new MentionEntity
6568
{
6669
Name = elems.Text.Str,
67-
Uin = BitConverter.ToUInt32(attr.AsSpan()[7..11], false),
70+
Uin = info.Uin,
6871
Uid = ""
6972
};
7073
}

Lagrange.OneBot/Message/Entity/AtSegment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public AtSegment() : this(0, null) { }
1111

1212
public AtSegment(uint at) : this(at, null) { }
1313

14-
[JsonPropertyName("qq")] [CQProperty] public string At { get; set; } = at.ToString();
14+
[JsonPropertyName("qq")] [CQProperty] public string At { get; set; } = at == 0 ? "all" : at.ToString();
1515

1616
[JsonPropertyName("name")] [CQProperty] public string? Name { get; set; } = name;
1717
}

0 commit comments

Comments
 (0)