From 2b21401587967ed7922a189311f493cafc91cea1 Mon Sep 17 00:00:00 2001 From: Last2014 Date: Sun, 3 May 2026 14:01:45 +0900 Subject: [PATCH] =?UTF-8?q?Chg:=20=E6=96=87=E5=AD=97=E6=95=B0=E5=88=B6?= =?UTF-8?q?=E9=99=90=E5=9B=9E=E9=81=BF=E3=82=921=E8=A1=8C=E3=81=9A?= =?UTF-8?q?=E3=81=A4=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/client.ts | 48 ++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/src/lib/client.ts b/src/lib/client.ts index 2db59f2..0780bcc 100644 --- a/src/lib/client.ts +++ b/src/lib/client.ts @@ -17,22 +17,39 @@ export const createUeuse = async (data: ApiMap["ueuse/create"]["body"], title: s const mem = Memory.memory; const maxLength = mem.max_length; const excessedMessage = "πŸ‘‰θΏ”δΏ‘γ«ηΆšγγŒγ‚γ‚ŠγΎγ™γ€‚"; - - let remainingText = data.text; + + // θ‘Œε˜δ½γ§εˆ†ε‰² + let lines = data.text.split(EOL); let firstUniqid = ""; - while (remainingText.length > 0) { + while (lines.length > 0) { let currentText = ""; - let bodyTextLength = 0; + + const limit = maxLength - (excessedMessage.length + EOL.length * 2); - if (remainingText.length <= maxLength) { - currentText = remainingText; - bodyTextLength = remainingText.length; - remainingText = ""; - } else { - bodyTextLength = maxLength - excessedMessage.length - 2; - currentText = remainingText.slice(0, bodyTextLength) + EOL.repeat(2) + excessedMessage; - remainingText = remainingText.slice(bodyTextLength); + while (lines.length > 0) { + const nextLine = lines[0]; + if (nextLine === undefined) break; + + if (nextLine.length > limit && currentText === "") { + const targetLine = lines.shift() || ""; + currentText = targetLine.slice(0, limit); + + lines.unshift(targetLine.slice(limit)); + break; + } + + const potentialText = currentText ? currentText + EOL + nextLine : nextLine; + if (potentialText.length <= limit) { + currentText = potentialText; + lines.shift(); + } else { + break; + } + } + + if (lines.length > 0) { + currentText += EOL.repeat(2) + excessedMessage; } let postedUniqid = ""; @@ -64,10 +81,7 @@ export const createUeuse = async (data: ApiMap["ueuse/create"]["body"], title: s break; } - if (firstUniqid === "") { - firstUniqid = postedUniqid; - } - + if (firstUniqid === "") firstUniqid = postedUniqid; console.log(`${title}γ‚’ζŠ•η¨Ώ:`, postedUniqid); } -} +} \ No newline at end of file