-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
38 lines (30 loc) · 1.06 KB
/
Copy pathutils.js
File metadata and controls
38 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fs = require('fs');
function loadConfig() {
return JSON.parse(fs.readFileSync('./data/config.json', 'utf8'));
}
function loadJSON(file) {
if (fs.existsSync(file)) {
return JSON.parse(fs.readFileSync(file, 'utf8'));
} else {
return {};
}
}
const formatOptions = (interaction) => {
if (!interaction.options || !interaction.options.data.length) return "No options provided.";
return interaction.options.data.map(opt =>
`- ${opt.name}: ${opt.value || "No value"}`
).join("\n");
};
const getTimestamp = () => {
const now = new Date();
const timestamp = now.toLocaleString('fr-FR', { timeZone: 'Europe/Paris' }).replace(',', '');
return `[${timestamp}]`;
};
const writeLogToFile = (message) => {
const logMessage = `${getTimestamp()} ${message}\n`;
fs.appendFileSync('./data/bot.log', logMessage, 'utf8');
};
function saveJSON(file, data) {
fs.writeFileSync(file, JSON.stringify(data, null, 4));
}
module.exports = { loadConfig, loadJSON, saveJSON, getTimestamp, writeLogToFile, formatOptions };