import fs from 'fs'; const configPath = './config.json'; const messagesPath = './messages.json'; const logError = (message) => { let time = new Date; console.error(`[${time.toLocaleString()}] [LOG] [E] ${message}`); }; const logInfo = (message) => { let time = new Date; console.log(`[${time.toLocaleString()}] [LOG] [I] ${message}`); }; const readConfig = () => { if (!fs.existsSync(configPath)) { fs.writeFileSync(configPath, `{ "homeserverURL": "https://matrix.org/", "token": "Super secret token! Do not show to anyone! Even your mum! ;)", "maxAmountOfPhotoesPerUser": 5 }` ); logError('[LOG] [E] Config file was not found. I have created a template, please, edit it and restart a bot.'); process.exit(-1); } return JSON.parse(fs.readFileSync(configPath)); }; const readMessages = () => { if (!fs.existsSync(messagesPath)) { logError("No 'messages.json' file found. Please, ensure that you are up to date by syncing using 'git pull' command."); process.exit(-1); } return JSON.parse(fs.readFileSync(messagesPath)); }; export {readMessages, readConfig, logError, logInfo};