Added weekly points back-up, writing points to dedicated directory.
This commit is contained in:
parent
19feb9a55f
commit
a9f733227c
|
@ -4,5 +4,5 @@ config/*
|
|||
*.config.js
|
||||
!ecosystem.config.js
|
||||
*.sqlite
|
||||
points*.json
|
||||
points/*
|
||||
assets/mash-words.json
|
||||
|
|
10
src/play.js
10
src/play.js
|
@ -3,6 +3,7 @@
|
|||
const config = require('config');
|
||||
const fs = require('fs').promises;
|
||||
const logger = require('simple-node-logger').createSimpleLogger();
|
||||
const { getWeek } = require('date-fns');
|
||||
const { argv } = require('yargs');
|
||||
// const timers = require('timers/promises');
|
||||
|
||||
|
@ -15,14 +16,16 @@ const points = {};
|
|||
|
||||
async function initPoints(identifier) {
|
||||
try {
|
||||
const pointsFile = await fs.readFile(`./points-${identifier}.json`, 'utf-8');
|
||||
const pointsFile = await fs.readFile(`./points/points-${identifier}.json`, 'utf-8');
|
||||
|
||||
Object.assign(points, JSON.parse(pointsFile));
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') {
|
||||
logger.info('Creating new points file');
|
||||
|
||||
await fs.writeFile(`./points-${identifier}.json`, '{}');
|
||||
await fs.mkdir('./points', { recursive: true });
|
||||
|
||||
await fs.writeFile(`./points/points-${identifier}.json`, '{}');
|
||||
await initPoints(identifier);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +53,8 @@ async function setPoints(identifier, defaultKey, user, value, { mode = 'add', ke
|
|||
points[gameKey][userKey] = value;
|
||||
}
|
||||
|
||||
await fs.writeFile(`./points-${identifier}.json`, JSON.stringify(points, null, 4));
|
||||
await fs.writeFile(`./points/points-${identifier}_backup${getWeek(new Date())}.json`, JSON.stringify(points, null, 4)); // weekly back-up
|
||||
await fs.writeFile(`./points/points-${identifier}.json`, JSON.stringify(points, null, 4));
|
||||
}
|
||||
|
||||
function getPoints(game, rawUsername, { user, room, command }) {
|
||||
|
|
Loading…
Reference in New Issue