CampFirePlay/utils/logs.js
Degradin d0dbf635ec v5.7
Test public pve
2025-01-14 20:09:13 +03:00

35 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const fs = require("fs");
const path = require("path");
/**
* Функция для записи логов.
* @param {Object} ctx - Контекст Telegraf (содержит данные о пользователе и сообщении).
* @param {String} action - Описание действия, например, "Начало битвы", "Использована граната".
* @param {Object} [extraData] - Дополнительные данные для логов.
*/
function logAction(ctx, action, extraData = {}) {
const logEntry = {
timestamp: new Date().toISOString(),
user: {
id: ctx.from.id,
username: ctx.from.username || "unknown",
first_name: ctx.from.first_name || "unknown",
last_name: ctx.from.last_name || "",
},
chat: ctx.chat ? { id: ctx.chat.id, type: ctx.chat.type } : null,
action,
extraData,
};
const logString = JSON.stringify(logEntry, null, 2);
// Сохраняем лог в файл
fs.appendFile('./json/logs.json', logString + "\n", (err) => {
if (err) {
console.error("Ошибка при записи лога:", err);
}
});
}
module.exports = logAction;