From 508efdd36d86e67a6c61afd160f46f465147b1a6 Mon Sep 17 00:00:00 2001 From: Zaw <177550418+A-n-o-n-0@users.noreply.github.com> Date: Tue, 26 Aug 2025 18:28:29 +0800 Subject: [PATCH] [Core] Add specific exception for Stranger not found --- .../Internal/Services/System/FetchStrangerService.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Lagrange.Core/Internal/Services/System/FetchStrangerService.cs b/Lagrange.Core/Internal/Services/System/FetchStrangerService.cs index 1af4ba7e..1087096a 100644 --- a/Lagrange.Core/Internal/Services/System/FetchStrangerService.cs +++ b/Lagrange.Core/Internal/Services/System/FetchStrangerService.cs @@ -91,6 +91,12 @@ protected override ValueTask Parse(ReadOnlyMemory property => property.Value ); + // Check exists + if (!bytes.TryGetValue(20002, out byte[]? nicknameBytes)) + { + throw new OperationException(-1, "Stranger not found"); + } + // Birthday byte[] birthday = bytes[20031]; int year = BinaryPrimitives.ReadUInt16BigEndian(birthday.AsSpan(0, 2)); @@ -99,7 +105,7 @@ protected override ValueTask Parse(ReadOnlyMemory return ValueTask.FromResult(new FetchStrangerEventResp(new BotStranger( response.Body.Uin, - Encoding.UTF8.GetString(bytes[20002]), + Encoding.UTF8.GetString(nicknameBytes), string.Empty, // Can't not get uid Encoding.UTF8.GetString(bytes[102]), Encoding.UTF8.GetString(bytes[103]),