heart2heart/src/utils.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-08-03 03:48:20 +03:00
import fs from 'fs'
const configPath = './config.json'
const messagesPath = './messages.json'
export const logError = (message) => {
let time = new Date
console.error(`[${time.toLocaleString()}] [LOG] [E] ${message}`)
}
export const logInfo = (message) => {
let time = new Date
console.log(`[${time.toLocaleString()}] [LOG] [I] ${message}`)
}
export const readConfig = () => {
if (!fs.existsSync(configPath)) {
2024-08-03 12:18:42 +03:00
fs.writeFileSync(configPath,
2024-08-03 03:48:20 +03:00
`{
"homeserverURL": "https://matrix.org/",
"token": "Super secret token! Do not show to anyone! Even your mum! ;)"
}`
);
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)
2024-08-03 12:18:42 +03:00
)
2024-08-03 03:48:20 +03:00
}
export 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))
}