Skip to content

Commit 6d63634

Browse files
try llm?
1 parent 84de793 commit 6d63634

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ function getSendTime(r: R) {
2525
return new Date(r.timeStamp).toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" });
2626
}
2727

28+
function escapeMarkdownV2(text: string) {
29+
// 注意:反斜杠 \ 本身也需要转义,所以正则表达式中是 \\\\
30+
// 或者直接在字符串中使用 \
31+
const reservedChars = ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!'];
32+
// 正则表达式需要转义特殊字符
33+
const escapedChars = reservedChars.map(char => '\\' + char).join('');
34+
const regex = new RegExp(`([${escapedChars}])`, 'g');
35+
return text.replace(regex, '\\$1');
36+
}
37+
2838
/**
2939
* 将数字转换为上标数字
3040
* @param {number} num - 要转换的数字
@@ -297,8 +307,8 @@ export default {
297307
.bind(groupId, `*${messageText.split(" ")[1]}*`)
298308
.all();
299309
const res = (await ctx.reply(
300-
telegramifyMarkdown(`查询结果:
301-
${results.map((r: any) => `${r.userName}: ${r.content} ${r.messageId == null ? "" : `[link](https://t.me/c/${parseInt(r.groupId.slice(2))}/${r.messageId})`}`).join('\n')}`, 'keep'), "MarkdownV2"))!;
310+
escapeMarkdownV2(`查询结果:
311+
${results.map((r: any) => `${r.userName}: ${r.content} ${r.messageId == null ? "" : `[link](https://t.me/c/${parseInt(r.groupId.slice(2))}/${r.messageId})`}`).join('\n')}`), "MarkdownV2"))!;
302312
if (!res.ok) {
303313
console.error(`Error sending message:`, res.status, res.statusText, await res.text());
304314
}

0 commit comments

Comments
 (0)