From 6b3d691c7e7d22fca5cb2bb14985a20f201db480 Mon Sep 17 00:00:00 2001 From: Linwenxuan <116782992+Linwenxuan05@users.noreply.github.com> Date: Thu, 26 Oct 2023 22:40:48 +0800 Subject: [PATCH] [OneBot] Fixed object of Echo for OneBotAction.cs --- Lagrange.OneBot/Core/Entity/Action/OneBotAction.cs | 2 +- Lagrange.OneBot/Core/Entity/Action/OneBotResult.cs | 5 +++-- .../Core/Operation/Group/SetGroupAdminOperation.cs | 4 ++-- .../Core/Operation/Group/SetGroupBanOperation.cs | 4 ++-- .../Core/Operation/Group/SetGroupCardOperation.cs | 4 ++-- .../Core/Operation/Group/SetGroupKickOperation.cs | 4 ++-- .../Core/Operation/Group/SetGroupLeaveOperation.cs | 4 ++-- .../Core/Operation/Group/SetGroupNameOperation.cs | 4 ++-- .../Core/Operation/Group/SetGroupWholeBanOperation.cs | 4 ++-- Lagrange.OneBot/Core/Operation/IOperation.cs | 2 +- .../Core/Operation/Info/GetGroupInfoOperation.cs | 4 ++-- .../Core/Operation/Info/GetGroupListOperation.cs | 6 +++--- .../Core/Operation/Info/GetLoginInfoOperation.cs | 4 ++-- .../Core/Operation/Info/GetVersionInfoOperation.cs | 4 ++-- .../Core/Operation/Message/SendGroupMessageOperation.cs | 4 ++-- .../Core/Operation/Message/SendMessageOperation.cs | 4 ++-- .../Core/Operation/Message/SendPrivateMessageOperation.cs | 4 ++-- Lagrange.OneBot/Core/Operation/OperationService.cs | 4 +++- 18 files changed, 37 insertions(+), 34 deletions(-) diff --git a/Lagrange.OneBot/Core/Entity/Action/OneBotAction.cs b/Lagrange.OneBot/Core/Entity/Action/OneBotAction.cs index 2a80b85b6..0b9937de8 100644 --- a/Lagrange.OneBot/Core/Entity/Action/OneBotAction.cs +++ b/Lagrange.OneBot/Core/Entity/Action/OneBotAction.cs @@ -10,5 +10,5 @@ public class OneBotAction [JsonPropertyName("params")] public JsonObject? Params { get; set; } - [JsonPropertyName("echo")] public string Echo { get; set; } = ""; + [JsonPropertyName("echo")] public JsonObject? Echo { get; set; } } \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Entity/Action/OneBotResult.cs b/Lagrange.OneBot/Core/Entity/Action/OneBotResult.cs index 8755fd2dc..7c763210d 100644 --- a/Lagrange.OneBot/Core/Entity/Action/OneBotResult.cs +++ b/Lagrange.OneBot/Core/Entity/Action/OneBotResult.cs @@ -1,9 +1,10 @@ +using System.Text.Json.Nodes; using System.Text.Json.Serialization; namespace Lagrange.OneBot.Core.Entity.Action; [Serializable] -public class OneBotResult(object? data, int retCode, string status, string echo) +public class OneBotResult(object? data, int retCode, string status) { [JsonPropertyName("status")] public string Status { get; set; } = status; @@ -11,7 +12,7 @@ public class OneBotResult(object? data, int retCode, string status, string echo) [JsonPropertyName("data")] public object? Data { get; set; } = data; - [JsonPropertyName("echo")] public string Echo { get; set; } = echo; + [JsonPropertyName("echo")] public JsonObject? Echo { get; set; } [JsonIgnore] public string? Identifier { get; internal set; } } diff --git a/Lagrange.OneBot/Core/Operation/Group/SetGroupAdminOperation.cs b/Lagrange.OneBot/Core/Operation/Group/SetGroupAdminOperation.cs index 65ff8b040..27b8dc1e3 100644 --- a/Lagrange.OneBot/Core/Operation/Group/SetGroupAdminOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Group/SetGroupAdminOperation.cs @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group; [Operation("set_group_admin")] public class SetGroupAdminOperation : IOperation { - public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public async Task HandleOperation(BotContext context, JsonObject? payload) { var message = payload.Deserialize(); if (message != null) { bool _ = await context.SetGroupAdmin(message.GroupId, message.UserId, message.Enable); - return new OneBotResult(null, 0, "ok", echo); + return new OneBotResult(null, 0, "ok"); } throw new Exception(); diff --git a/Lagrange.OneBot/Core/Operation/Group/SetGroupBanOperation.cs b/Lagrange.OneBot/Core/Operation/Group/SetGroupBanOperation.cs index f04118ab2..20b2e7781 100644 --- a/Lagrange.OneBot/Core/Operation/Group/SetGroupBanOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Group/SetGroupBanOperation.cs @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group; [Operation("set_group_ban")] public class SetGroupBanOperation : IOperation { - public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public async Task HandleOperation(BotContext context, JsonObject? payload) { var message = payload.Deserialize(); if (message != null) { bool _ = await context.MuteGroupMember(message.GroupId, message.UserId, message.Duration); - return new OneBotResult(null, 0, "ok", echo); + return new OneBotResult(null, 0, "ok"); } throw new Exception(); diff --git a/Lagrange.OneBot/Core/Operation/Group/SetGroupCardOperation.cs b/Lagrange.OneBot/Core/Operation/Group/SetGroupCardOperation.cs index a3f2c5266..0999de6d0 100644 --- a/Lagrange.OneBot/Core/Operation/Group/SetGroupCardOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Group/SetGroupCardOperation.cs @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group; [Operation("set_group_card")] public class SetGroupCardOperation : IOperation { - public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public async Task HandleOperation(BotContext context, JsonObject? payload) { var message = payload.Deserialize(); if (message != null) { bool _ = await context.RenameGroupMember(message.GroupId, message.UserId, message.Card); - return new OneBotResult(null, 0, "ok", echo); + return new OneBotResult(null, 0, "ok"); } throw new Exception(); diff --git a/Lagrange.OneBot/Core/Operation/Group/SetGroupKickOperation.cs b/Lagrange.OneBot/Core/Operation/Group/SetGroupKickOperation.cs index d3c4cd730..7ffc533a5 100644 --- a/Lagrange.OneBot/Core/Operation/Group/SetGroupKickOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Group/SetGroupKickOperation.cs @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group; [Operation("set_group_kick")] public class SetGroupKickOperation : IOperation { - public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public async Task HandleOperation(BotContext context, JsonObject? payload) { var message = payload.Deserialize(); if (message != null) { bool _ = await context.KickGroupMember(message.GroupId, message.UserId, message.RejectAddRequest); - return new OneBotResult(null, 0, "ok", echo); + return new OneBotResult(null, 0, "ok"); } throw new Exception(); diff --git a/Lagrange.OneBot/Core/Operation/Group/SetGroupLeaveOperation.cs b/Lagrange.OneBot/Core/Operation/Group/SetGroupLeaveOperation.cs index 31b031e70..3adbe5587 100644 --- a/Lagrange.OneBot/Core/Operation/Group/SetGroupLeaveOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Group/SetGroupLeaveOperation.cs @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group; [Operation("set_group_leave")] public class SetGroupLeaveOperation : IOperation { - public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public async Task HandleOperation(BotContext context, JsonObject? payload) { var message = payload.Deserialize(); if (message != null) { bool _ = await context.LeaveGroup(message.GroupId); // TODO: Figure out is_dismiss - return new OneBotResult(null, 0, "ok", echo); + return new OneBotResult(null, 0, "ok"); } throw new Exception(); diff --git a/Lagrange.OneBot/Core/Operation/Group/SetGroupNameOperation.cs b/Lagrange.OneBot/Core/Operation/Group/SetGroupNameOperation.cs index 288240bc8..33580b1d8 100644 --- a/Lagrange.OneBot/Core/Operation/Group/SetGroupNameOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Group/SetGroupNameOperation.cs @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group; [Operation("set_group_name")] public class SetGroupNameOperation : IOperation { - public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public async Task HandleOperation(BotContext context, JsonObject? payload) { var message = payload.Deserialize(); if (message != null) { bool _ = await context.RenameGroup(message.GroupId, message.GroupName); - return new OneBotResult(null, 0, "ok", echo); + return new OneBotResult(null, 0, "ok"); } throw new Exception(); diff --git a/Lagrange.OneBot/Core/Operation/Group/SetGroupWholeBanOperation.cs b/Lagrange.OneBot/Core/Operation/Group/SetGroupWholeBanOperation.cs index 9ed397225..8c0035dab 100644 --- a/Lagrange.OneBot/Core/Operation/Group/SetGroupWholeBanOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Group/SetGroupWholeBanOperation.cs @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group; [Operation("set_group_whole_ban")] public class SetGroupWholeBanOperation : IOperation { - public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public async Task HandleOperation(BotContext context, JsonObject? payload) { var message = payload.Deserialize(); if (message != null) { bool _ = await context.MuteGroupGlobal(message.GroupId, message.Enable); - return new OneBotResult(null, 0, "ok", echo); + return new OneBotResult(null, 0, "ok"); } throw new Exception(); diff --git a/Lagrange.OneBot/Core/Operation/IOperation.cs b/Lagrange.OneBot/Core/Operation/IOperation.cs index 3a503c772..d9128bf1f 100644 --- a/Lagrange.OneBot/Core/Operation/IOperation.cs +++ b/Lagrange.OneBot/Core/Operation/IOperation.cs @@ -6,5 +6,5 @@ namespace Lagrange.OneBot.Core.Operation; public interface IOperation { - public Task HandleOperation(string echo, BotContext context, JsonObject? payload); + public Task HandleOperation(BotContext context, JsonObject? payload); } \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Operation/Info/GetGroupInfoOperation.cs b/Lagrange.OneBot/Core/Operation/Info/GetGroupInfoOperation.cs index 5e6166490..aa690fb70 100644 --- a/Lagrange.OneBot/Core/Operation/Info/GetGroupInfoOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Info/GetGroupInfoOperation.cs @@ -9,12 +9,12 @@ namespace Lagrange.OneBot.Core.Operation.Info; [Operation("get_group_info")] public class GetGroupInfoOperation : IOperation { - public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public async Task HandleOperation(BotContext context, JsonObject? payload) { if (payload.Deserialize() is { } message) { var result = await context.FetchGroups(message.NoCache); - return new OneBotResult(result.FirstOrDefault(x => x.GroupUin == message.GroupId), 0, "ok", echo); + return new OneBotResult(result.FirstOrDefault(x => x.GroupUin == message.GroupId), 0, "ok"); } throw new Exception(); diff --git a/Lagrange.OneBot/Core/Operation/Info/GetGroupListOperation.cs b/Lagrange.OneBot/Core/Operation/Info/GetGroupListOperation.cs index bdd3b70c4..fe77f29fa 100644 --- a/Lagrange.OneBot/Core/Operation/Info/GetGroupListOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Info/GetGroupListOperation.cs @@ -9,17 +9,17 @@ namespace Lagrange.OneBot.Core.Operation.Info; [Operation("get_group_list")] public class GetGroupListOperation : IOperation { - public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public async Task HandleOperation(BotContext context, JsonObject? payload) { if (payload.Deserialize() is { } message) { var result = await context.FetchGroups(message.NoCache); - return new OneBotResult(result, 0, "ok", echo); + return new OneBotResult(result, 0, "ok"); } else { var result = await context.FetchGroups(); - return new OneBotResult(result, 0, "ok", echo); + return new OneBotResult(result, 0, "ok"); } } } \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Operation/Info/GetLoginInfoOperation.cs b/Lagrange.OneBot/Core/Operation/Info/GetLoginInfoOperation.cs index 4e220ddb0..8488ef3e4 100644 --- a/Lagrange.OneBot/Core/Operation/Info/GetLoginInfoOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Info/GetLoginInfoOperation.cs @@ -8,10 +8,10 @@ namespace Lagrange.OneBot.Core.Operation.Info; [Operation("get_login_info")] public class GetLoginInfoOperation : IOperation { - public Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public Task HandleOperation(BotContext context, JsonObject? payload) { var keystore = context.ContextCollection.Keystore; var result = new OneBotLoginInfoResponse(keystore.Uin, keystore.Info?.Name ?? ""); - return Task.FromResult(new OneBotResult(result, 0, "ok", echo)); + return Task.FromResult(new OneBotResult(result, 0, "ok")); } } \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Operation/Info/GetVersionInfoOperation.cs b/Lagrange.OneBot/Core/Operation/Info/GetVersionInfoOperation.cs index d66e548fa..e4318448c 100644 --- a/Lagrange.OneBot/Core/Operation/Info/GetVersionInfoOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Info/GetVersionInfoOperation.cs @@ -8,11 +8,11 @@ namespace Lagrange.OneBot.Core.Operation.Info; [Operation("get_version_info")] public class GetVersionInfoOperation : IOperation { - public Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public Task HandleOperation(BotContext context, JsonObject? payload) { var appInfo = context.ContextCollection.AppInfo; string version = $"{appInfo.Os} | {appInfo.CurrentVersion}"; - return Task.FromResult(new OneBotResult(new OneBotVersionInfoResponse(version), 0, "ok", echo)); + return Task.FromResult(new OneBotResult(new OneBotVersionInfoResponse(version), 0, "ok")); } } \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Operation/Message/SendGroupMessageOperation.cs b/Lagrange.OneBot/Core/Operation/Message/SendGroupMessageOperation.cs index 39ae9583e..423929ac1 100644 --- a/Lagrange.OneBot/Core/Operation/Message/SendGroupMessageOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/SendGroupMessageOperation.cs @@ -10,12 +10,12 @@ namespace Lagrange.OneBot.Core.Operation.Message; [Operation("send_group_msg")] public sealed class SendGroupMessageOperation : IOperation { - public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public async Task HandleOperation(BotContext context, JsonObject? payload) { if (payload.Deserialize() is { } message) { await context.SendMessage(MessageCommon.ParseChain(message).Build()); - return new OneBotResult(new OneBotMessageResponse(0), 0, "ok", echo); + return new OneBotResult(new OneBotMessageResponse(0), 0, "ok"); } throw new Exception(); diff --git a/Lagrange.OneBot/Core/Operation/Message/SendMessageOperation.cs b/Lagrange.OneBot/Core/Operation/Message/SendMessageOperation.cs index e5d3a6647..52d2006e4 100644 --- a/Lagrange.OneBot/Core/Operation/Message/SendMessageOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/SendMessageOperation.cs @@ -10,12 +10,12 @@ namespace Lagrange.OneBot.Core.Operation.Message; [Operation("send_msg")] public sealed class SendMessageOperation : IOperation { - public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public async Task HandleOperation(BotContext context, JsonObject? payload) { if (payload.Deserialize() is { } message) { await context.SendMessage(MessageCommon.ParseChain(message).Build()); - return new OneBotResult(new OneBotMessageResponse(0), 0, "ok", echo); + return new OneBotResult(new OneBotMessageResponse(0), 0, "ok"); } throw new Exception(); diff --git a/Lagrange.OneBot/Core/Operation/Message/SendPrivateMessageOperation.cs b/Lagrange.OneBot/Core/Operation/Message/SendPrivateMessageOperation.cs index 6a43be3a1..b12dc3e63 100644 --- a/Lagrange.OneBot/Core/Operation/Message/SendPrivateMessageOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/SendPrivateMessageOperation.cs @@ -10,12 +10,12 @@ namespace Lagrange.OneBot.Core.Operation.Message; [Operation("send_private_msg")] public sealed class SendPrivateMessageOperation : IOperation { - public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + public async Task HandleOperation(BotContext context, JsonObject? payload) { if (payload.Deserialize() is { } message) { await context.SendMessage(MessageCommon.ParseChain(message).Build()); - return new OneBotResult(new OneBotMessageResponse(0), 0, "ok", echo); + return new OneBotResult(new OneBotMessageResponse(0), 0, "ok"); } throw new Exception(); diff --git a/Lagrange.OneBot/Core/Operation/OperationService.cs b/Lagrange.OneBot/Core/Operation/OperationService.cs index 553352330..c4d91da3e 100644 --- a/Lagrange.OneBot/Core/Operation/OperationService.cs +++ b/Lagrange.OneBot/Core/Operation/OperationService.cs @@ -38,7 +38,9 @@ private async Task HandleOperation(string data) if (supported && handler != null) { - var result = await handler.HandleOperation(action.Echo, _bot, action.Params); + var result = await handler.HandleOperation(_bot, action.Params); + result.Echo = action.Echo; + await _service.SendJsonAsync(result); } }