From c79f814b14943fa9ef95ab4fefb54b7dd69e58a0 Mon Sep 17 00:00:00 2001 From: DarkRRb <177549718+DarkRRb@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:22:48 +0800 Subject: [PATCH] [OneBot] fix check sequence (#696) --- .../Core/Operation/Message/SendGroupAiRecordOperation.cs | 5 ++++- .../Core/Operation/Message/SendGroupForwardOperation.cs | 4 ++++ .../Core/Operation/Message/SendGroupMessageOperation.cs | 8 ++++++-- .../Core/Operation/Message/SendMessageOperation.cs | 1 + .../Operation/Message/SendPrivateForwardOperation.cs | 1 + .../Operation/Message/SendPrivateMessageOperation.cs | 1 + Lagrange.OneBot/LagrangeAppBuilder.cs | 2 +- Lagrange.OneBot/Utility/QrCodeHelper.cs | 9 ++++++--- 8 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Lagrange.OneBot/Core/Operation/Message/SendGroupAiRecordOperation.cs b/Lagrange.OneBot/Core/Operation/Message/SendGroupAiRecordOperation.cs index 626e45074..858734ced 100644 --- a/Lagrange.OneBot/Core/Operation/Message/SendGroupAiRecordOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/SendGroupAiRecordOperation.cs @@ -26,9 +26,12 @@ public async Task HandleOperation(BotContext context, JsonNode? pa ); if (code != 0 || recordEntity == null) return new OneBotResult(null, code, "failed"); - var chain = MessageBuilder.Group(message.GroupId).Add(recordEntity).Build(); var result = await context.SendMessage(chain); + + if (result.Result != 0) return new OneBotResult(null, (int)result.Result, "failed"); + if (result.Sequence == null || result.Sequence == 0) return new OneBotResult(null, 9000, "failed"); + int hash = MessageRecord.CalcMessageHash(chain.MessageId, result.Sequence ?? 0); return new OneBotResult(new OneBotMessageResponse(hash), (int)result.Result, "ok"); diff --git a/Lagrange.OneBot/Core/Operation/Message/SendGroupForwardOperation.cs b/Lagrange.OneBot/Core/Operation/Message/SendGroupForwardOperation.cs index 8e9f1272f..8714e0bf3 100644 --- a/Lagrange.OneBot/Core/Operation/Message/SendGroupForwardOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/SendGroupForwardOperation.cs @@ -23,6 +23,10 @@ public async Task HandleOperation(BotContext context, JsonNode? pa var multi = new MultiMsgEntity(chains); var chain = MessageBuilder.Group(forward.GroupId).Add(multi).Build(); var ret = await context.SendMessage(chain); + + if (ret.Result != 0) return new OneBotResult(null, (int)ret.Result, "failed"); + if (ret.Sequence == null || ret.Sequence == 0) return new OneBotResult(null, 9000, "failed"); + int hash = MessageRecord.CalcMessageHash(chain.MessageId, ret.Sequence ?? 0); return new OneBotResult(new OneBotForwardResponse(hash, multi.ResId ?? ""), (int)ret.Result, "ok"); diff --git a/Lagrange.OneBot/Core/Operation/Message/SendGroupMessageOperation.cs b/Lagrange.OneBot/Core/Operation/Message/SendGroupMessageOperation.cs index 79703df7a..fd77191a8 100644 --- a/Lagrange.OneBot/Core/Operation/Message/SendGroupMessageOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/SendGroupMessageOperation.cs @@ -21,10 +21,14 @@ public async Task HandleOperation(BotContext context, JsonNode? pa OneBotGroupMessageText messageText => common.ParseChain(messageText).Build(), _ => throw new Exception() }; - + var result = await context.SendMessage(chain); + + if (result.Result != 0) return new OneBotResult(null, (int)result.Result, "failed"); + if (result.Sequence == null || result.Sequence == 0) return new OneBotResult(null, 9000, "failed"); + int hash = MessageRecord.CalcMessageHash(chain.MessageId, result.Sequence ?? 0); - + return new OneBotResult(new OneBotMessageResponse(hash), (int)result.Result, "ok"); } } diff --git a/Lagrange.OneBot/Core/Operation/Message/SendMessageOperation.cs b/Lagrange.OneBot/Core/Operation/Message/SendMessageOperation.cs index 422bff57f..7d69f5f59 100644 --- a/Lagrange.OneBot/Core/Operation/Message/SendMessageOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/SendMessageOperation.cs @@ -26,6 +26,7 @@ public async Task HandleOperation(BotContext context, JsonNode? pa var result = await context.SendMessage(chain); if (result.Result != 0) return new OneBotResult(null, (int)result.Result, "failed"); + if (result.Sequence == null || result.Sequence == 0) return new OneBotResult(null, 9000, "failed"); int hash = MessageRecord.CalcMessageHash(result.MessageId, result.Sequence ?? 0); diff --git a/Lagrange.OneBot/Core/Operation/Message/SendPrivateForwardOperation.cs b/Lagrange.OneBot/Core/Operation/Message/SendPrivateForwardOperation.cs index 16e18d0ce..f1bef6041 100644 --- a/Lagrange.OneBot/Core/Operation/Message/SendPrivateForwardOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/SendPrivateForwardOperation.cs @@ -27,6 +27,7 @@ public async Task HandleOperation(BotContext context, JsonNode? pa var result = await context.SendMessage(chain); if (result.Result != 0) return new OneBotResult(null, (int)result.Result, "failed"); + if (result.Sequence == null || result.Sequence == 0) return new OneBotResult(null, 9000, "failed"); int hash = MessageRecord.CalcMessageHash(result.MessageId, result.Sequence ?? 0); diff --git a/Lagrange.OneBot/Core/Operation/Message/SendPrivateMessageOperation.cs b/Lagrange.OneBot/Core/Operation/Message/SendPrivateMessageOperation.cs index 88bc27197..e0f83828b 100644 --- a/Lagrange.OneBot/Core/Operation/Message/SendPrivateMessageOperation.cs +++ b/Lagrange.OneBot/Core/Operation/Message/SendPrivateMessageOperation.cs @@ -26,6 +26,7 @@ public async Task HandleOperation(BotContext context, JsonNode? pa var result = await context.SendMessage(chain); if (result.Result != 0) return new OneBotResult(null, (int)result.Result, "failed"); + if (result.Sequence == null || result.Sequence == 0) return new OneBotResult(null, 9000, "failed"); int hash = MessageRecord.CalcMessageHash(result.MessageId, result.Sequence ?? 0); diff --git a/Lagrange.OneBot/LagrangeAppBuilder.cs b/Lagrange.OneBot/LagrangeAppBuilder.cs index ed357287f..a7ca0d1fa 100644 --- a/Lagrange.OneBot/LagrangeAppBuilder.cs +++ b/Lagrange.OneBot/LagrangeAppBuilder.cs @@ -103,7 +103,7 @@ public LagrangeAppBuilder ConfigureBots() { appInfo = JsonSerializer.Deserialize(File.ReadAllText(appInfoPath)) ?? BotAppInfo.ProtocolToAppInfo[config.Protocol]; } - + Services.AddSingleton(BotFactory.Create(config, deviceInfo, keystore, appInfo)); return this; diff --git a/Lagrange.OneBot/Utility/QrCodeHelper.cs b/Lagrange.OneBot/Utility/QrCodeHelper.cs index f852286d1..ba870b686 100644 --- a/Lagrange.OneBot/Utility/QrCodeHelper.cs +++ b/Lagrange.OneBot/Utility/QrCodeHelper.cs @@ -23,14 +23,17 @@ internal static void Output(string text, bool compatibilityMode) if (foregroundBlack && !backgroundBlack) { Console.Write(bottomHalfBlock); - } else if (!foregroundBlack && backgroundBlack) + } + else if (!foregroundBlack && backgroundBlack) { Console.Write(topHalfBlock); - } else if (foregroundBlack && backgroundBlack) + } + else if (foregroundBlack && backgroundBlack) { Console.Write(emptyBlock); - } else if (!foregroundBlack && !backgroundBlack) + } + else if (!foregroundBlack && !backgroundBlack) { Console.Write(fullBlock); }