42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
|
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)) {
|
||
|
|
||
|
fs.writeFileSync(configPath,
|
||
|
`{
|
||
|
"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)
|
||
|
)
|
||
|
}
|
||
|
|
||
|
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))
|
||
|
}
|