-
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.
[Core] Support sending with group reaction (#659)
Co-authored-by: Decrabbityyy <[email protected]>
- Loading branch information
1 parent
b5857eb
commit 7815fc8
Showing
3 changed files
with
128 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Lagrange.Core.Common.Entity; | ||
|
||
public class BotGroupReaction | ||
{ | ||
public string FaceId { get; set; } | ||
|
||
public uint Type { get; set; } | ||
|
||
public uint Count { get; set; } | ||
|
||
public bool IsAdded { get; set; } | ||
|
||
public BotGroupReaction(string faceId, uint type, uint count, bool isAdded) | ||
{ | ||
FaceId = faceId; | ||
Type = type; | ||
Count = count; | ||
IsAdded = isAdded; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
Lagrange.Core/Internal/Packets/Message/Element/Implementation/Extra/GroupReactionExtra.cs
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,41 @@ | ||
#pragma warning disable CS8618 | ||
|
||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Packets.Message.Element.Implementation.Extra; | ||
|
||
[ProtoContract] | ||
internal class GroupReactionExtra | ||
{ | ||
[ProtoMember(1)] public GroupReactionExtraBody Body { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class GroupReactionExtraBody | ||
{ | ||
[ProtoMember(1)] public GroupReactionExtraBodyField1 Field1 { get; set; } | ||
|
||
[ProtoMember(2)] public GroupReactionExtraFaceInfo[] FaceInfos { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class GroupReactionExtraBodyField1 | ||
{ | ||
[ProtoMember(1)] public uint Field1 { get; set; } | ||
|
||
[ProtoMember(2)] public uint Field2 { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class GroupReactionExtraFaceInfo | ||
{ | ||
// See Lagrange.Core/Internal/Service/System/FetchFullSysFacesService.cs | ||
[ProtoMember(1)] public string FaceId { get; set; } | ||
|
||
// See Lagrange.Core/Internal/Service/System/FetchFullSysFacesService.cs | ||
[ProtoMember(2)] public uint Type { get; set; } | ||
|
||
[ProtoMember(3)] public uint Count { get; set; } | ||
|
||
[ProtoMember(4)] public uint IsAdded { get; set; } | ||
} |
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,67 @@ | ||
using Lagrange.Core.Common.Entity; | ||
using Lagrange.Core.Internal.Packets.Message.Element; | ||
using Lagrange.Core.Internal.Packets.Message.Element.Implementation; | ||
using Lagrange.Core.Internal.Packets.Message.Element.Implementation.Extra; | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Message.Entity; | ||
|
||
[MessageElement(typeof(CommonElem))] | ||
public class GroupReactionEntity : IMessageEntity | ||
{ | ||
private readonly IEnumerable<BotGroupReaction> _reactions; | ||
|
||
public GroupReactionEntity() { _reactions = Array.Empty<BotGroupReaction>(); } | ||
|
||
public GroupReactionEntity(IEnumerable<BotGroupReaction> reactions) | ||
{ | ||
_reactions = reactions; | ||
} | ||
|
||
IEnumerable<Elem> IMessageEntity.PackElement() | ||
{ | ||
var infos = _reactions | ||
.Select(reaction => new GroupReactionExtraFaceInfo() | ||
{ | ||
FaceId = reaction.FaceId, | ||
Type = reaction.Type, | ||
Count = reaction.Count, | ||
IsAdded = reaction.IsAdded ? 1u : 0u, | ||
}) | ||
.ToArray(); | ||
|
||
var extra = new GroupReactionExtra | ||
{ | ||
Body = new() | ||
{ | ||
Field1 = new() | ||
{ | ||
Field1 = 0, | ||
Field2 = 7240 | ||
}, | ||
FaceInfos = infos, | ||
} | ||
}; | ||
using var stream = new MemoryStream(); | ||
Serializer.Serialize(stream, extra); | ||
|
||
return new Elem[] { | ||
new() { CommonElem = new() { | ||
ServiceType = 38, | ||
PbElem = stream.ToArray(), | ||
BusinessType = 1 | ||
} } | ||
}; | ||
} | ||
|
||
string IMessageEntity.ToPreviewString() | ||
{ | ||
return ""; | ||
} | ||
|
||
IMessageEntity? IMessageEntity.UnpackElement(Elem elem) | ||
{ | ||
// TODO Parase | ||
return null; | ||
} | ||
} |