2016-12-08 03:52:37 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
var app = require('./app.js');
|
|
|
|
var logger = require('./logging.js');
|
|
|
|
|
2017-09-29 23:38:00 +00:00
|
|
|
function readWarnings () {
|
2016-12-08 03:52:37 +00: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);
|
2017-08-02 23:11:05 +00:00
|
|
|
logger.debug('Loaded warnings file.');
|
2016-12-08 03:52:37 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-29 23:38:00 +00:00
|
|
|
function readBans () {
|
2016-12-08 03:52:37 +00: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);
|
2017-08-02 23:11:05 +00:00
|
|
|
logger.debug('Loaded bans file.');
|
2016-12-08 03:52:37 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-29 23:38:00 +00:00
|
|
|
function flushWarnings () {
|
2016-12-08 03:52:37 +00: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 23:38:00 +00:00
|
|
|
if (err) { logger.error(err); }
|
2016-12-08 03:52:37 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-29 23:38:00 +00:00
|
|
|
function flushBans () {
|
2016-12-08 03:52:37 +00: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 23:38:00 +00:00
|
|
|
if (err) { logger.error(err); }
|
2016-12-08 03:52:37 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-29 23:38:00 +00:00
|
|
|
module.exports = { readWarnings: readWarnings, readBans: readBans, flushWarnings: flushWarnings, flushBans: flushBans };
|