Command-fix/data.js

42 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-12-07 22:52:37 -05:00
var fs = require('fs');
var app = require('./app.js');
var logger = require('./logging.js');
2017-09-29 19:38:00 -04:00
function readWarnings () {
2016-12-07 22:52:37 -05:00
// Load the warnings file into the bans variable.
fs.readFile('./data/discordWarnings.json', 'utf8', function (err, data) {
if (err && err.code === 'ENOENT') { return; }
if (err) { logger.error(err); }
app.warnings = JSON.parse(data);
logger.debug('Loaded warnings file.');
2016-12-07 22:52:37 -05:00
});
}
2017-09-29 19:38:00 -04:00
function readBans () {
2016-12-07 22:52:37 -05:00
// Load the ban file into the bans variable.
fs.readFile('./data/discordBans.json', 'utf8', function (err, data) {
if (err && err.code === 'ENOENT') { return; }
if (err) { logger.error(err); }
app.bans = JSON.parse(data);
logger.debug('Loaded bans file.');
2016-12-07 22:52:37 -05:00
});
}
2017-09-29 19:38:00 -04:00
function flushWarnings () {
2016-12-07 22:52:37 -05:00
var warningsJson = JSON.stringify(app.warnings, null, 4);
if (!fs.existsSync('./data/')) fs.mkdirSync('./data/');
fs.writeFile('./data/discordWarnings.json', warningsJson, 'utf8', function (err) {
2017-09-29 19:38:00 -04:00
if (err) { logger.error(err); }
2016-12-07 22:52:37 -05:00
});
}
2017-09-29 19:38:00 -04:00
function flushBans () {
2016-12-07 22:52:37 -05:00
var bansJson = JSON.stringify(app.bans, null, 4);
if (!fs.existsSync('./data/')) fs.mkdirSync('./data/');
fs.writeFile('./data/discordBans.json', bansJson, 'utf8', function (err) {
2017-09-29 19:38:00 -04:00
if (err) { logger.error(err); }
2016-12-07 22:52:37 -05:00
});
}
2017-09-29 19:38:00 -04:00
module.exports = { readWarnings: readWarnings, readBans: readBans, flushWarnings: flushWarnings, flushBans: flushBans };