diff --git a/Lagrange.Core/Common/Interface/Api/GroupExt.cs b/Lagrange.Core/Common/Interface/Api/GroupExt.cs index e6ae9492a..07879a95e 100644 --- a/Lagrange.Core/Common/Interface/Api/GroupExt.cs +++ b/Lagrange.Core/Common/Interface/Api/GroupExt.cs @@ -74,6 +74,9 @@ public static Task RemoveEssenceMessage(this BotContext bot, MessageChain public static Task GroupSetSpecialTitle(this BotContext bot, uint groupUin, uint targetUin, string title) => bot.ContextCollection.Business.OperationLogic.GroupSetSpecialTitle(groupUin, targetUin, title); + + public static Task GroupSetMessageReaction(this BotContext bot, uint groupUin, uint sequence, string code) + => bot.ContextCollection.Business.OperationLogic.SetMessageReaction(groupUin, sequence, code); #region Group File System diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs index 9ee7fa7f5..3cac106d2 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs @@ -407,4 +407,11 @@ public async Task GroupSetSpecialTitle(uint groupUin, uint targetUin, stri var events = await Collection.Business.SendEvent(fetchUserInfoEvent); return events.Count != 0 ? ((FetchUserInfoEvent)events[0]).UserInfo : null; } + + public async Task SetMessageReaction(uint groupUin, uint sequence, string code) + { + var setReactionEvent = GroupSetReactionEvent.Create(groupUin, sequence, code); + var results = await Collection.Business.SendEvent(setReactionEvent); + return results.Count != 0 && results[0].ResultCode == 0; + } } diff --git a/Lagrange.Core/Internal/Event/Action/GroupSetReactionEvent.cs b/Lagrange.Core/Internal/Event/Action/GroupSetReactionEvent.cs new file mode 100644 index 000000000..33a49c057 --- /dev/null +++ b/Lagrange.Core/Internal/Event/Action/GroupSetReactionEvent.cs @@ -0,0 +1,24 @@ +namespace Lagrange.Core.Internal.Event.Action; + +internal class GroupSetReactionEvent : ProtocolEvent +{ + public uint GroupUin { get; } + + public uint Sequence { get; } + + public string Code { get; } = string.Empty; + + private GroupSetReactionEvent(uint groupUin, uint sequence, string code) : base(true) + { + GroupUin = groupUin; + Sequence = sequence; + Code = code; + } + + private GroupSetReactionEvent(int resultCode) : base(resultCode) { } + + public static GroupSetReactionEvent Create(uint groupUin, uint sequence, string code) + => new(groupUin, sequence, code); + + public static GroupSetReactionEvent Result(int resultCode) => new(resultCode); +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Service/Action/GroupSetReactionService.cs b/Lagrange.Core/Internal/Service/Action/GroupSetReactionService.cs new file mode 100644 index 000000000..4325c4384 --- /dev/null +++ b/Lagrange.Core/Internal/Service/Action/GroupSetReactionService.cs @@ -0,0 +1,43 @@ +using Lagrange.Core.Common; +using Lagrange.Core.Internal.Event; +using Lagrange.Core.Internal.Event.Action; +using Lagrange.Core.Internal.Packets.Service.Oidb; +using Lagrange.Core.Internal.Packets.Service.Oidb.Request; +using Lagrange.Core.Utility.Binary; +using Lagrange.Core.Utility.Extension; +using ProtoBuf; + +namespace Lagrange.Core.Internal.Service.Action; + +[EventSubscribe(typeof(GroupSetReactionEvent))] +[Service("OidbSvcTrpcTcp.0x9082_1")] +internal class GroupSetReactionService : BaseService +{ + protected override bool Build(GroupSetReactionEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, + out BinaryPacket output, out List? extraPackets) + { + var packet = new OidbSvcTrpcTcpBase(new OidbSvcTrpcTcp0x9082_1 + { + GroupUin = input.GroupUin, + Sequence = input.Sequence, + Code = input.Code, + Field5 = true, + Field6 = false, + Field7 = false + }, false, true); + + output = packet.Serialize(); + extraPackets = null; + return true; + } + + protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, + out GroupSetReactionEvent output, out List? extraEvents) + { + var payload = Serializer.Deserialize>(input); + + output = GroupSetReactionEvent.Result((int)payload.ErrorCode); + extraEvents = null; + return true; + } +} \ No newline at end of file