From c9374ff515209534fe18e50e4deca9403d94f07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=BD=B1?= <summer@summerlight.com> Date: Sat, 20 Jul 2024 00:49:34 +0800 Subject: [PATCH] fix: skip problematic name-value pairs in encodeCQCode to prevent undefined errors Added logic to skip name-value pairs in encodeCQCode when value cannot be converted to string, preventing errors caused by undefined values. This ensures the function can handle such cases gracefully and continue processing other valid data. --- src/onebot11/cqcode.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/onebot11/cqcode.ts b/src/onebot11/cqcode.ts index 121320d..6b61160 100644 --- a/src/onebot11/cqcode.ts +++ b/src/onebot11/cqcode.ts @@ -61,6 +61,14 @@ export function encodeCQCode(data: OB11MessageData) { let result = '[CQ:' + data.type for (const name in data.data) { const value = data.data[name] + try { + // Check if the value can be converted to a string + value.toString(); + } catch (error) { + // If it can't be converted, skip this name-value pair + // console.warn(`Skipping problematic name-value pair. Name: ${name}, Value: ${value}`); + continue; + } result += `,${name}=${CQCodeEscape(value)}` } result += ']'