Skip to content

Commit

Permalink
[Core] Support sending with group reaction (#659)
Browse files Browse the repository at this point in the history
Co-authored-by: Decrabbityyy <[email protected]>
  • Loading branch information
DarkRRb and Decrabbityyy authored Oct 27, 2024
1 parent b5857eb commit 7815fc8
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Lagrange.Core/Common/Entity/BotGroupReaction.cs
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;
}
}
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; }
}
67 changes: 67 additions & 0 deletions Lagrange.Core/Message/Entity/GroupReactionEntity.cs
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;
}
}

0 comments on commit 7815fc8

Please sign in to comment.