1
0
mirror of https://github.com/sadfsdfdsa/allbot.git synced 2024-11-19 00:31:42 +02:00

fix: long messages

This commit is contained in:
Artem Shuvaev 2024-10-06 21:14:23 +05:00
parent 19a4ba0e89
commit 04a696f12d
5 changed files with 47 additions and 15 deletions

0
Dockerfile Normal file
View File

View File

@ -1107,6 +1107,11 @@ Someone should write something (read more /help).
console.log('[ALL] Broken users:', brokenUsers.length)
let lastStr = str
/**
* Max Telegram message length - so we need to split this message by chunks
*/
const MAX_LENGTH = 4096
if (brokenUsers.length) {
lastStr =
lastStr +
@ -1136,13 +1141,28 @@ Someone should write something (read more /help).
]
try {
await ctx.reply(lastStr, {
reply_to_message_id: withReply ? messageId : undefined,
parse_mode: 'HTML',
reply_markup: {
inline_keyboard: inlineKeyboard,
},
let arr: string[] = []
let currentStr = lastStr
while (currentStr.length >= MAX_LENGTH) {
const firstPart = currentStr.slice(0, 4000)
currentStr = currentStr.slice(4000)
arr.push(firstPart)
}
const promises: Promise<unknown>[] = []
arr.map((str) => {
return ctx.reply(str, {
reply_to_message_id: withReply ? messageId : undefined,
parse_mode: 'HTML',
reply_markup: {
inline_keyboard: inlineKeyboard,
},
})
})
await Promise.all(promises)
resolve(null)
} catch (error) {
const response:

View File

@ -45,8 +45,6 @@ export class CacheService {
const arr = [...this.cachedChats.values()].map((set) => [...set]).flat()
if (arr.length < this.MAX_CACHE_SIZE) return
this.metricsService.cacheCounter.reset()
const date = new Date()
this.metricsService.cacheClearingCounter.inc({
time: date.toLocaleString('ru-RU', { timeZone: 'Asia/Yekaterinburg' }),

27
dist/core/bot.js vendored
View File

@ -736,6 +736,10 @@ Someone should write something (read more /help).
return new Promise(async (resolve) => {
console.log('[ALL] Broken users:', brokenUsers.length);
let lastStr = str;
/**
* Max Telegram message length - so we need to split this message by chunks
*/
const MAX_LENGTH = 4096;
if (brokenUsers.length) {
lastStr =
lastStr +
@ -759,13 +763,24 @@ Someone should write something (read more /help).
buttons,
];
try {
await ctx.reply(lastStr, {
reply_to_message_id: withReply ? messageId : undefined,
parse_mode: 'HTML',
reply_markup: {
inline_keyboard: inlineKeyboard,
},
let arr = [];
let currentStr = lastStr;
while (currentStr.length >= MAX_LENGTH) {
const firstPart = currentStr.slice(0, 4000);
currentStr = currentStr.slice(4000);
arr.push(firstPart);
}
const promises = [];
arr.map((str) => {
return ctx.reply(str, {
reply_to_message_id: withReply ? messageId : undefined,
parse_mode: 'HTML',
reply_markup: {
inline_keyboard: inlineKeyboard,
},
});
});
await Promise.all(promises);
resolve(null);
}
catch (error) {

1
dist/core/cache.js vendored
View File

@ -34,7 +34,6 @@ export class CacheService {
const arr = [...this.cachedChats.values()].map((set) => [...set]).flat();
if (arr.length < this.MAX_CACHE_SIZE)
return;
this.metricsService.cacheCounter.reset();
const date = new Date();
this.metricsService.cacheClearingCounter.inc({
time: date.toLocaleString('ru-RU', { timeZone: 'Asia/Yekaterinburg' }),