diff --git a/Lagrange.Core/Common/Entity/BotGroupRequest.cs b/Lagrange.Core/Common/Entity/BotGroupRequest.cs index 9ffac2a4a..b54fc6b0f 100644 --- a/Lagrange.Core/Common/Entity/BotGroupRequest.cs +++ b/Lagrange.Core/Common/Entity/BotGroupRequest.cs @@ -14,7 +14,8 @@ internal BotGroupRequest( uint state, ulong sequence, uint type, - string? comment) + string? comment, + bool isFiltered) { GroupUin = groupUin; InvitorMemberUin = invitorMemberUin; @@ -27,6 +28,7 @@ internal BotGroupRequest( Sequence = sequence; EventType = (Type)type; Comment = comment; + IsFiltered = isFiltered; } public uint GroupUin { get; set; } @@ -50,6 +52,8 @@ internal BotGroupRequest( internal ulong Sequence { get; set; } // for internal use of Approving Requests public string? Comment { get; } + + public bool IsFiltered { get; set; } public enum State { diff --git a/Lagrange.Core/Common/Interface/Api/GroupExt.cs b/Lagrange.Core/Common/Interface/Api/GroupExt.cs index d8798609a..1af8d2d94 100644 --- a/Lagrange.Core/Common/Interface/Api/GroupExt.cs +++ b/Lagrange.Core/Common/Interface/Api/GroupExt.cs @@ -66,8 +66,11 @@ public static Task LeaveGroup(this BotContext bot, uint groupUin) public static Task InviteGroup(this BotContext bot, uint groupUin, Dictionary invitedUins) => bot.ContextCollection.Business.OperationLogic.InviteGroup(groupUin, invitedUins); - public static Task SetGroupRequest(this BotContext bot, BotGroupRequest request, bool accept = true) - => bot.ContextCollection.Business.OperationLogic.SetGroupRequest(request.GroupUin, request.Sequence, (uint)request.EventType, accept); + public static Task SetGroupRequest(this BotContext bot, BotGroupRequest request, bool accept = true, string reason = "") + => bot.ContextCollection.Business.OperationLogic.SetGroupRequest(request.GroupUin, request.Sequence, (uint)request.EventType, accept, reason); + + public static Task SetGroupFilteredRequest(this BotContext bot, BotGroupRequest request, bool accept = true, string reason = "") + => bot.ContextCollection.Business.OperationLogic.SetGroupFilteredRequest(request.GroupUin, request.Sequence, (uint)request.EventType, accept, reason); public static Task SetFriendRequest(this BotContext bot, FriendRequestEvent request, bool accept = true) => bot.ContextCollection.Business.OperationLogic.SetFriendRequest(request.SourceUid, accept); diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs index 89ca726ef..eaff8921b 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs @@ -303,7 +303,8 @@ public async Task RecallFriendMessage(MessageChain chain) result.State, result.Sequence, result.EventType, - result.Comment + result.Comment, + result.IsFiltered )); } @@ -399,9 +400,16 @@ public async Task InviteGroup(uint targetGroupUin, Dictionary return events.Count == 0 ? null : ((FetchClientKeyEvent)events[0]).ClientKey; } - public async Task SetGroupRequest(uint groupUin, ulong sequence, uint type, bool accept) + public async Task SetGroupRequest(uint groupUin, ulong sequence, uint type, bool accept, string reason) { - var inviteEvent = SetGroupRequestEvent.Create(accept, groupUin, sequence, type); + var inviteEvent = SetGroupRequestEvent.Create(accept, groupUin, sequence, type, reason); + var results = await Collection.Business.SendEvent(inviteEvent); + return results.Count != 0 && results[0].ResultCode == 0; + } + + public async Task SetGroupFilteredRequest(uint groupUin, ulong sequence, uint type, bool accept, string reason) + { + var inviteEvent = SetGroupFilteredRequestEvent.Create(accept, groupUin, sequence, type, reason); var results = await Collection.Business.SendEvent(inviteEvent); return results.Count != 0 && results[0].ResultCode == 0; } diff --git a/Lagrange.Core/Internal/Event/Action/SetGroupFilteredRequestEvent.cs b/Lagrange.Core/Internal/Event/Action/SetGroupFilteredRequestEvent.cs new file mode 100644 index 000000000..b4968b924 --- /dev/null +++ b/Lagrange.Core/Internal/Event/Action/SetGroupFilteredRequestEvent.cs @@ -0,0 +1,30 @@ +namespace Lagrange.Core.Internal.Event.Action; + +internal class SetGroupFilteredRequestEvent : ProtocolEvent +{ + public ulong Sequence { get; set; } + + public uint GroupUin { get; set; } + + public bool Accept { get; set; } + + public uint Type { get; } + + public string Reason { get; set; } = string.Empty; + + private SetGroupFilteredRequestEvent(bool accept, uint groupUin, ulong sequence, uint type, string? reason) : base(true) + { + Accept = accept; + GroupUin = groupUin; + Sequence = sequence; + Type = type; + Reason = reason ?? ""; + } + + private SetGroupFilteredRequestEvent(int resultCode) : base(resultCode) { } + + public static SetGroupFilteredRequestEvent Create(bool accept, uint groupUin, ulong sequence, uint type, string? reason) + => new(accept, groupUin, sequence, type, reason); + + public static SetGroupFilteredRequestEvent Result(int resultCode) => new(resultCode); +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Event/Action/SetGroupRequestEvent.cs b/Lagrange.Core/Internal/Event/Action/SetGroupRequestEvent.cs index 1a79ffa82..7d5d03a7b 100644 --- a/Lagrange.Core/Internal/Event/Action/SetGroupRequestEvent.cs +++ b/Lagrange.Core/Internal/Event/Action/SetGroupRequestEvent.cs @@ -9,19 +9,22 @@ internal class SetGroupRequestEvent : ProtocolEvent public bool Accept { get; set; } public uint Type { get; } + + public string Reason { get; set; } = string.Empty; - private SetGroupRequestEvent(bool accept, uint groupUin, ulong sequence, uint type) : base(true) + private SetGroupRequestEvent(bool accept, uint groupUin, ulong sequence, uint type, string? reason) : base(true) { Accept = accept; GroupUin = groupUin; Sequence = sequence; Type = type; + Reason = reason ?? ""; } 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 Create(bool accept, uint groupUin, ulong sequence, uint type, string? reason) + => new(accept, groupUin, sequence, type, reason); public static SetGroupRequestEvent Result(int resultCode) => new(resultCode); } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Event/System/FetchGroupRequestsEvent.cs b/Lagrange.Core/Internal/Event/System/FetchGroupRequestsEvent.cs index 9e8e17c7f..997e944be 100644 --- a/Lagrange.Core/Internal/Event/System/FetchGroupRequestsEvent.cs +++ b/Lagrange.Core/Internal/Event/System/FetchGroupRequestsEvent.cs @@ -28,6 +28,7 @@ public record RawEvent( ulong Sequence, uint State, uint EventType, - string? Comment + string? Comment, + bool IsFiltered ); } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x10C8_1.cs b/Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x10C8.cs similarity index 75% rename from Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x10C8_1.cs rename to Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x10C8.cs index 31b68c851..9f4869de2 100644 --- a/Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x10C8_1.cs +++ b/Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x10C8.cs @@ -8,16 +8,15 @@ namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request; /// Accept group request /// [ProtoContract] -[OidbSvcTrpcTcp(0x10c8, 1)] -internal class OidbSvcTrpcTcp0x10C8_1 +internal class OidbSvcTrpcTcp0x10C8 { [ProtoMember(1)] public uint Accept { get; set; } // 2 for reject, 1 for accept, 3 for ignore - [ProtoMember(2)] public OidbSvcTrpcTcp0x10C8_1Body? Body { get; set; } + [ProtoMember(2)] public OidbSvcTrpcTcp0x10C8Body? Body { get; set; } } [ProtoContract] -internal class OidbSvcTrpcTcp0x10C8_1Body +internal class OidbSvcTrpcTcp0x10C8Body { [ProtoMember(1)] public ulong Sequence { get; set; } // 1 diff --git a/Lagrange.Core/Internal/Service/Action/SetGroupFilteredRequestService.cs b/Lagrange.Core/Internal/Service/Action/SetGroupFilteredRequestService.cs new file mode 100644 index 000000000..999709f56 --- /dev/null +++ b/Lagrange.Core/Internal/Service/Action/SetGroupFilteredRequestService.cs @@ -0,0 +1,44 @@ +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.Extension; +using ProtoBuf; + +namespace Lagrange.Core.Internal.Service.Action; + +[EventSubscribe(typeof(SetGroupFilteredRequestEvent))] +[Service("OidbSvcTrpcTcp.0x10c8_2")] +internal class SetGroupFilteredRequestService : BaseService +{ + protected override bool Build(SetGroupFilteredRequestEvent input, BotKeystore keystore, BotAppInfo appInfo, + BotDeviceInfo device, out Span output, out List>? extraPackets) + { + var packet = new OidbSvcTrpcTcpBase(new OidbSvcTrpcTcp0x10C8 + { + Accept = Convert.ToUInt32(!input.Accept) + 1, + Body = new OidbSvcTrpcTcp0x10C8Body + { + Sequence = input.Sequence, + EventType = input.Type, + GroupUin = input.GroupUin, + Message = input.Reason + } + }, 0x10c8, 2, false, true); + + output = packet.Serialize(); + extraPackets = null; + return true; + } + + protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, + out SetGroupFilteredRequestEvent output, out List? extraEvents) + { + var payload = Serializer.Deserialize>(input); + + output = SetGroupFilteredRequestEvent.Result((int)payload.ErrorCode); + extraEvents = null; + return true; + } +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Service/Action/SetGroupRequestService.cs b/Lagrange.Core/Internal/Service/Action/SetGroupRequestService.cs index eb329d4e3..b7b2a6650 100644 --- a/Lagrange.Core/Internal/Service/Action/SetGroupRequestService.cs +++ b/Lagrange.Core/Internal/Service/Action/SetGroupRequestService.cs @@ -15,17 +15,17 @@ internal class SetGroupRequestService : BaseService protected override bool Build(SetGroupRequestEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out Span output, out List>? extraPackets) { - var packet = new OidbSvcTrpcTcpBase(new OidbSvcTrpcTcp0x10C8_1 + var packet = new OidbSvcTrpcTcpBase(new OidbSvcTrpcTcp0x10C8 { Accept = Convert.ToUInt32(!input.Accept) + 1, - Body = new OidbSvcTrpcTcp0x10C8_1Body + Body = new OidbSvcTrpcTcp0x10C8Body { Sequence = input.Sequence, EventType = input.Type, GroupUin = input.GroupUin, - Message = "" + Message = input.Reason } - }); + }, 0x10c8, 1, false, true); output = packet.Serialize(); extraPackets = null; diff --git a/Lagrange.Core/Internal/Service/System/FetchFilteredGroupRequestsService.cs b/Lagrange.Core/Internal/Service/System/FetchFilteredGroupRequestsService.cs index b25ec4b0b..216ff9580 100644 --- a/Lagrange.Core/Internal/Service/System/FetchFilteredGroupRequestsService.cs +++ b/Lagrange.Core/Internal/Service/System/FetchFilteredGroupRequestsService.cs @@ -42,7 +42,8 @@ protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo x.Sequence, x.State, x.EventType, - x.Comment + x.Comment, + true )).ToList() ?? new List(); output = FetchGroupRequestsEvent.Result((int)payload.ErrorCode, events); diff --git a/Lagrange.Core/Internal/Service/System/FetchGroupRequestsService.cs b/Lagrange.Core/Internal/Service/System/FetchGroupRequestsService.cs index 02552c32c..c78d15d36 100644 --- a/Lagrange.Core/Internal/Service/System/FetchGroupRequestsService.cs +++ b/Lagrange.Core/Internal/Service/System/FetchGroupRequestsService.cs @@ -42,7 +42,8 @@ protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo x.Sequence, x.State, x.EventType, - x.Comment + x.Comment, + false )).ToList() ?? new List(); output = FetchGroupRequestsEvent.Result((int)payload.ErrorCode, events); diff --git a/Lagrange.OneBot/Core/Entity/Action/OneBotSetRequest.cs b/Lagrange.OneBot/Core/Entity/Action/OneBotSetRequest.cs index 9e02db9cf..2c5bec7d5 100644 --- a/Lagrange.OneBot/Core/Entity/Action/OneBotSetRequest.cs +++ b/Lagrange.OneBot/Core/Entity/Action/OneBotSetRequest.cs @@ -8,4 +8,6 @@ public class OneBotSetRequest [JsonPropertyName("flag")] public string Flag { get; set; } = string.Empty; [JsonPropertyName("approve")] public bool Approve { get; set; } = true; + + [JsonPropertyName("reason")] public string Reason { get; set; } = string.Empty; } \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Notify/NotifyService.cs b/Lagrange.OneBot/Core/Notify/NotifyService.cs index fcf475bb8..96b5bc11b 100644 --- a/Lagrange.OneBot/Core/Notify/NotifyService.cs +++ b/Lagrange.OneBot/Core/Notify/NotifyService.cs @@ -65,7 +65,7 @@ public void RegisterEvents() var requests = await bot.FetchGroupRequests(); if (requests?.FirstOrDefault(x => @event.GroupUin == x.GroupUin && @event.TargetUin == x.TargetMemberUin) is { } request) { - string flag = $"{request.Sequence}-{request.GroupUin}-{(uint)request.EventType}"; + string flag = $"{request.Sequence}-{request.GroupUin}-{(uint)request.EventType}-{Convert.ToInt32(request.IsFiltered)}"; await service.SendJsonAsync(new OneBotGroupRequest(bot.BotUin, @event.TargetUin, @event.GroupUin, "add", request.Comment, flag)); } }; diff --git a/Lagrange.OneBot/Core/Operation/Request/SetGroupAddRequestOperation.cs b/Lagrange.OneBot/Core/Operation/Request/SetGroupAddRequestOperation.cs index bde6b523e..e85a45a9c 100644 --- a/Lagrange.OneBot/Core/Operation/Request/SetGroupAddRequestOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Request/SetGroupAddRequestOperation.cs @@ -17,8 +17,13 @@ public async Task HandleOperation(BotContext context, JsonNode? pa ulong sequence = ulong.Parse(split[0]); uint groupUin = uint.Parse(split[1]); uint eventType = uint.Parse(split[2]); - - bool result = await context.ContextCollection.Business.OperationLogic.SetGroupRequest(groupUin, sequence, eventType, request.Approve); + bool isFiltered = Convert.ToBoolean(uint.Parse(split.Length > 3 ? split[3] : "0")); + + bool result = isFiltered + ? await context.ContextCollection.Business.OperationLogic.SetGroupFilteredRequest(groupUin, sequence, + eventType, request.Approve, request.Reason) + : await context.ContextCollection.Business.OperationLogic.SetGroupRequest(groupUin, sequence, eventType, + request.Approve, request.Reason); return new OneBotResult(null, result ? 0 : 1, "ok"); }