fix: коррекция статистики
This commit is contained in:
parent
d4693bb106
commit
67d3de5986
14
index.js
14
index.js
@ -188,16 +188,22 @@ function toxAnalyze(text) {
|
||||
// Проверяем, есть ли уже результат в кеше
|
||||
if (aiCache[text]) {
|
||||
stats.cacheHits += 1; // Увеличиваем счетчик попаданий в кеш
|
||||
return JSON.parse(aiCache[text]);
|
||||
let tempResult = JSON.parse(aiCache[text]);
|
||||
tempResult.firstTime = false;
|
||||
return tempResult;
|
||||
}
|
||||
|
||||
// Если нет, делаем запрос к AI
|
||||
stats.cacheMisses += 1; // Увеличиваем счетчик промахов в кеш
|
||||
return getAIResume(text, BASE_PROMPT).then(result => {
|
||||
// Сохраняем результат в кеш
|
||||
aiCache[text] = result;
|
||||
let tempResult = JSON.parse(result);
|
||||
tempResult.firstTime = true;
|
||||
|
||||
aiCache[text] = JSON.stringify(tempResult);
|
||||
|
||||
saveAiCache(); // Сохраняем кеш в файл
|
||||
return JSON.parse(result);
|
||||
return tempResult;
|
||||
});
|
||||
}
|
||||
|
||||
@ -322,7 +328,7 @@ bot.on('message', async (msg) => {
|
||||
const remainingAttempts = MAX_CALLS_PER_DAY - userUsage[userId].count;
|
||||
|
||||
// Отправляем отформатированное сообщение с оставшимися попытками
|
||||
await updateUserStats(userId, username, firstName, toxScore, average); // Обновляем статистику пользователя
|
||||
if (toxScore.firstTime) {await updateUserStats(msg.reply_to_message.from.id, msg.reply_to_message.from.username, msg.reply_to_message.from.firstName, toxScore, average);} // Обновляем статистику пользователя
|
||||
await bot.sendMessage(chatId, `Результаты анализа:\n${resultMessage}\n\nАнализов осталось: ${remainingAttempts}\n\nРекорд: ${stats.maxScore.toFixed(1)}`, { reply_to_message_id: msg.reply_to_message.message_id });
|
||||
} else {
|
||||
await bot.sendMessage(chatId, 'Пожалуйста, укажите текст для анализа.');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user