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');
function readWarnings() {
// 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
});
}
function readBans() {
// 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
});
}
function flushWarnings() {
var warningsJson = JSON.stringify(app.warnings, null, 4);
if (!fs.existsSync('./data/')) fs.mkdirSync('./data/');
fs.writeFile('./data/discordWarnings.json', warningsJson, 'utf8', function (err) {
if (err) return console.log(err);
});
}
function flushBans() {
var bansJson = JSON.stringify(app.bans, null, 4);
if (!fs.existsSync('./data/')) fs.mkdirSync('./data/');
fs.writeFile('./data/discordBans.json', bansJson, 'utf8', function (err) {
if (err) return console.log(err);
});
}
module.exports = { readWarnings: readWarnings, readBans: readBans, flushWarnings: flushWarnings, flushBans: flushBans }