Skip to content

Commit

Permalink
[Core] Rename and Fix SetGroupRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan04 committed Feb 26, 2024
1 parent 94dc542 commit 6edf192
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 43 deletions.
25 changes: 22 additions & 3 deletions Lagrange.Core/Common/Entity/BotGroupRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ internal BotGroupRequest(
uint? operatorUin,
string? operatorName,
uint state,
ulong sequence)
ulong sequence,
uint type)
{
GroupUin = groupUin;
InvitorMemberUin = invitorMemberUin;
Expand All @@ -20,8 +21,9 @@ internal BotGroupRequest(
TargetMemberCard = targetMemberCard;
OperatorUin = operatorUin;
OperatorName = operatorName;
State = state;
EventState = (State)state;
Sequence = sequence;
EventType = (Type)type;
}

public uint GroupUin { get; set; }
Expand All @@ -38,7 +40,24 @@ internal BotGroupRequest(

public string? OperatorName { get; set; }

public uint State { get; set; }
public Type EventType { get; set; }

public State EventState { get; set; }

internal ulong Sequence { get; set; } // for internal use of Approving Requests

public enum State
{
Default = 0,
Pending = 1,
Approved = 2,
Disapproved = 3,
}

public enum Type
{
GroupRequest = 1,
ExitGroup = 13,
GroupInvitation = 22,
}
}
4 changes: 2 additions & 2 deletions Lagrange.Core/Common/Interface/Api/GroupExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public static Task<bool> LeaveGroup(this BotContext bot, uint groupUin)
public static Task<bool> InviteGroup(this BotContext bot, uint groupUin, List<uint> invitedUins)
=> bot.ContextCollection.Business.OperationLogic.InviteGroup(groupUin, invitedUins);

public static Task<bool> GroupInvitationRequest(this BotContext bot, BotGroupRequest request, bool accept = true)
=> bot.ContextCollection.Business.OperationLogic.GroupInvitationRequest(request.GroupUin, request.Sequence, accept);
public static Task<bool> SetGroupRequest(this BotContext bot, BotGroupRequest request, bool accept = true)
=> bot.ContextCollection.Business.OperationLogic.SetGroupRequest(request.GroupUin, request.Sequence, (uint)request.EventType, accept);

#region Group File System

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ public async Task<bool> RecallGroupMessage(MessageChain chain)

foreach (var result in resolved)
{
uint invitorUin = await ResolveUid(result.InvitorMemberUid);
uint targetUin = await ResolveUid(result.TargetMemberUid);
uint operatorUin = await ResolveUid(result.OperatorUid);
var uins = await Task.WhenAll(ResolveUid(result.InvitorMemberUid), ResolveUid(result.TargetMemberUid), ResolveUid(result.OperatorUid));
uint invitorUin = uins[0];
uint targetUin = uins[1];
uint operatorUin = uins[2];

results.Add(new BotGroupRequest(
result.GroupUin,
Expand All @@ -186,7 +187,8 @@ public async Task<bool> RecallGroupMessage(MessageChain chain)
operatorUin,
result.OperatorName,
result.State,
result.Sequence));
result.Sequence,
result.EventType));
}

return results;
Expand Down Expand Up @@ -272,9 +274,9 @@ public async Task<bool> InviteGroup(uint groupUin, List<uint> invitedUins)
return events.Count == 0 ? null : ((FetchClientKeyEvent)events[0]).ClientKey;
}

public async Task<bool> GroupInvitationRequest(uint groupUin, ulong sequence, bool accept)
public async Task<bool> SetGroupRequest(uint groupUin, ulong sequence, uint type, bool accept)
{
var inviteEvent = AcceptGroupRequestEvent.Create(accept, groupUin, sequence);
var inviteEvent = SetGroupRequestEvent.Create(accept, groupUin, sequence, type);
var results = await Collection.Business.SendEvent(inviteEvent);
return results.Count != 0 && results[0].ResultCode == 0;
}
Expand Down
23 changes: 0 additions & 23 deletions Lagrange.Core/Internal/Event/Action/AcceptGroupRequestEvent.cs

This file was deleted.

27 changes: 27 additions & 0 deletions Lagrange.Core/Internal/Event/Action/SetGroupRequestEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Lagrange.Core.Internal.Event.Action;

internal class SetGroupRequestEvent : ProtocolEvent
{
public ulong Sequence { get; set; }

public uint GroupUin { get; set; }

public bool Accept { get; set; }

public uint Type { get; }

private SetGroupRequestEvent(bool accept, uint groupUin, ulong sequence, uint type) : base(true)
{
Accept = accept;
GroupUin = groupUin;
Sequence = sequence;
Type = type;
}

private SetGroupRequestEvent(int resultCode) : base(resultCode) { }

public static SetGroupRequestEvent Create(bool accept, uint groupUin, ulong sequence, uint type)
=> new(accept, groupUin, sequence, type);

public static SetGroupRequestEvent Result(int resultCode) => new(resultCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ internal class OidbSvcTrpcTcp0x10C8_1Body
{
[ProtoMember(1)] public ulong Sequence { get; set; } // 1

[ProtoMember(2)] public uint Field2 { get; set; } // 2
[ProtoMember(2)] public uint EventType { get; set; } // 2

[ProtoMember(3)] public uint GroupUin { get; set; } // 3

[ProtoMember(4)] public string? Field4 { get; set; } // ""
[ProtoMember(4)] public string? Message { get; set; } // ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

namespace Lagrange.Core.Internal.Service.Action;

[EventSubscribe(typeof(AcceptGroupRequestEvent))]
[EventSubscribe(typeof(SetGroupRequestEvent))]
[Service("OidbSvcTrpcTcp.0x10c8_1")]
internal class AcceptGroupRequestService : BaseService<AcceptGroupRequestEvent>
internal class SetGroupRequestService : BaseService<SetGroupRequestEvent>
{
protected override bool Build(AcceptGroupRequestEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Build(SetGroupRequestEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out BinaryPacket output, out List<BinaryPacket>? extraPackets)
{
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x10C8_1>(new OidbSvcTrpcTcp0x10C8_1
Expand All @@ -22,9 +22,9 @@ protected override bool Build(AcceptGroupRequestEvent input, BotKeystore keystor
Body = new OidbSvcTrpcTcp0x10C8_1Body
{
Sequence = input.Sequence,
Field2 = 2,
EventType = 2,
GroupUin = input.GroupUin,
Field4 = ""
Message = ""
}
});

Expand All @@ -34,11 +34,11 @@ protected override bool Build(AcceptGroupRequestEvent input, BotKeystore keystor
}

protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out AcceptGroupRequestEvent output, out List<ProtocolEvent>? extraEvents)
out SetGroupRequestEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = Serializer.Deserialize<OidbSvcTrpcTcpResponse<byte[]>>(input.AsSpan());

output = AcceptGroupRequestEvent.Result((int)payload.ErrorCode);
output = SetGroupRequestEvent.Result((int)payload.ErrorCode);
extraEvents = null;
return true;
}
Expand Down

0 comments on commit 6edf192

Please sign in to comment.