2018-04-04 01:28:33 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const state = require('./state.js');
|
|
|
|
const logger = require('./logging.js');
|
|
|
|
|
|
|
|
function readWarnings () {
|
|
|
|
// Load the warnings file into the bans variable.
|
|
|
|
fs.readFile('/data/discordWarnings.json', 'utf8', function (err, data) {
|
2018-04-04 01:50:20 +02:00
|
|
|
if (err) { logger.error(err); throw err; }
|
2018-04-04 01:28:33 +02:00
|
|
|
state.warnings = JSON.parse(data);
|
|
|
|
logger.debug('Loaded warnings file.');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function readBans () {
|
|
|
|
// Load the ban file into the bans variable.
|
|
|
|
fs.readFile('/data/discordBans.json', 'utf8', function (err, data) {
|
2018-04-04 01:50:20 +02:00
|
|
|
if (err) { logger.error(err); throw err; }
|
2018-04-04 01:28:33 +02:00
|
|
|
state.bans = JSON.parse(data);
|
|
|
|
logger.debug('Loaded bans file.');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function readCustomResponses()
|
|
|
|
{
|
|
|
|
// Load the responses file into the responses variable.
|
|
|
|
fs.readFile('/data/responses.json', 'utf8', function (err, data) {
|
2018-04-04 01:50:20 +02:00
|
|
|
if (err) { logger.error(err); throw err; }
|
2018-04-04 01:28:33 +02:00
|
|
|
state.responses = JSON.parse(data);
|
|
|
|
logger.debug('Loaded responses file from external source.');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function flushWarnings () {
|
|
|
|
var warningsJson = JSON.stringify(state.warnings, null, 4);
|
|
|
|
if (!fs.existsSync('./data/')) fs.mkdirSync('data');
|
2018-04-04 01:50:20 +02:00
|
|
|
|
2018-04-04 01:28:33 +02:00
|
|
|
fs.writeFile('/data/discordWarnings.json', warningsJson, 'utf8', function (err) {
|
2018-04-04 01:50:20 +02:00
|
|
|
if (err) { logger.error(err); throw err; }
|
2018-04-04 01:28:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function flushBans () {
|
|
|
|
var bansJson = JSON.stringify(state.bans, null, 4);
|
|
|
|
if (!fs.existsSync('data')) fs.mkdirSync('data');
|
2018-04-04 01:50:20 +02:00
|
|
|
|
2018-04-04 01:28:33 +02:00
|
|
|
fs.writeFile('/data/discordBans.json', bansJson, 'utf8', function (err) {
|
2018-04-04 01:50:20 +02:00
|
|
|
if (err) { logger.error(err); throw err; }
|
2018-04-04 01:28:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { readWarnings: readWarnings, readBans: readBans, readCustomResponses: readCustomResponses, flushWarnings: flushWarnings, flushBans: flushBans };
|