Skip to content

Commit

Permalink
[Core] Implemented GroupSetMessageReaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan04 committed Apr 15, 2024
1 parent c7c676e commit fdb1ca8
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lagrange.Core/Common/Interface/Api/GroupExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public static Task<bool> RemoveEssenceMessage(this BotContext bot, MessageChain

public static Task<bool> GroupSetSpecialTitle(this BotContext bot, uint groupUin, uint targetUin, string title)
=> bot.ContextCollection.Business.OperationLogic.GroupSetSpecialTitle(groupUin, targetUin, title);

public static Task<bool> GroupSetMessageReaction(this BotContext bot, uint groupUin, uint sequence, string code)
=> bot.ContextCollection.Business.OperationLogic.SetMessageReaction(groupUin, sequence, code);

#region Group File System

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,11 @@ public async Task<bool> 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<bool> 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;
}
}
24 changes: 24 additions & 0 deletions Lagrange.Core/Internal/Event/Action/GroupSetReactionEvent.cs
Original file line number Diff line number Diff line change
@@ -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);
}
43 changes: 43 additions & 0 deletions Lagrange.Core/Internal/Service/Action/GroupSetReactionService.cs
Original file line number Diff line number Diff line change
@@ -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<GroupSetReactionEvent>
{
protected override bool Build(GroupSetReactionEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out BinaryPacket output, out List<BinaryPacket>? extraPackets)
{
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x9082_1>(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<byte> input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out GroupSetReactionEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = Serializer.Deserialize<OidbSvcTrpcTcpBase<byte[]>>(input);

output = GroupSetReactionEvent.Result((int)payload.ErrorCode);
extraEvents = null;
return true;
}
}

0 comments on commit fdb1ca8

Please sign in to comment.