(
msg: Api.Message,
text: string,
replyToId?: number,
token?: AbortToken,
options?: { poweredByTag?: string },
)
| 1251 | |
| 1252 | async sendLongMessage( |
| 1253 | msg: Api.Message, |
| 1254 | text: string, |
| 1255 | replyToId?: number, |
| 1256 | token?: AbortToken, |
| 1257 | options?: { poweredByTag?: string }, |
| 1258 | ): Promise<Api.Message> { |
| 1259 | token?.throwIfAborted(); |
| 1260 | |
| 1261 | const configManager = await this.configManagerPromise; |
| 1262 | const config = configManager.getConfig(); |
| 1263 | |
| 1264 | const poweredByTag = (options?.poweredByTag ?? config.currentChatTag) || ""; |
| 1265 | const poweredByText = poweredByTag |
| 1266 | ? `\n<i>🍀Powered by ${poweredByTag}</i>` |
| 1267 | : ""; |
| 1268 | |
| 1269 | if (text.length <= 4050) { |
| 1270 | token?.throwIfAborted(); |
| 1271 | |
| 1272 | const parts = text.split(/(?=A:\n)/); |
| 1273 | if (parts.length === 2) { |
| 1274 | const questionPart = parts[0]; |
| 1275 | const answerPart = parts[1]; |
| 1276 | const cleanAnswer = answerPart.replace(/^A:\n/, ""); |
| 1277 | const cleanQuestion = questionPart |
| 1278 | .replace(/^Q:\n/, "") |
| 1279 | .replace(/\n\n$/, ""); |
| 1280 | const questionBlock = `Q:\n${this.wrapHtmlWithCollapseIfNeeded(cleanQuestion, config.collapse)}\n`; |
| 1281 | const answerBlock = `A:\n${this.wrapHtmlWithCollapseIfNeeded(cleanAnswer, config.collapse)}`; |
| 1282 | const finalText = questionBlock + answerBlock + poweredByText; |
| 1283 | |
| 1284 | return await this.sendHtml(msg, finalText, replyToId, false); |
| 1285 | } |
| 1286 | const finalText = |
| 1287 | this.wrapHtmlWithCollapseIfNeeded(text, config.collapse) + |
| 1288 | poweredByText; |
| 1289 | return await this.sendHtml(msg, finalText, replyToId, false); |
| 1290 | } |
| 1291 | |
| 1292 | const qa = text.match(/Q:\n([\s\S]+?)\n\nA:\n([\s\S]+)/); |
| 1293 | if (!qa) { |
| 1294 | token?.throwIfAborted(); |
| 1295 | const finalText = |
| 1296 | this.wrapHtmlWithCollapseIfNeeded(text, config.collapse) + |
| 1297 | poweredByText; |
| 1298 | return await this.sendHtml(msg, finalText, replyToId, false); |
| 1299 | } |
| 1300 | |
| 1301 | const [, question, answer] = qa; |
| 1302 | const answerText = answer.replace(/^A:\n/, ""); |
| 1303 | const chunks: string[] = []; |
| 1304 | let current = ""; |
| 1305 | |
| 1306 | for (const line of answerText.split("\n")) { |
| 1307 | token?.throwIfAborted(); |
| 1308 | const testLength = (current + line + "\n").length; |
| 1309 | if (testLength > 4050 && current) { |
| 1310 | chunks.push(current); |
no test coverage detected