2018-04-04 02:14:57 +02:00
|
|
|
const fs = require('fs');
|
2018-04-04 01:28:33 +02:00
|
|
|
const state = require('./state.js');
|
|
|
|
const logger = require('./logging.js');
|
|
|
|
|
2018-04-04 02:05:01 +02:00
|
|
|
function readWarnings() {
|
|
|
|
// Load the warnings file into the application state.
|
|
|
|
var readFilePath = '/data/discordWarnings.json';
|
|
|
|
fs.readFile(readFilePath, 'utf8', function (err, data) {
|
|
|
|
if (err) { throw err; }
|
|
|
|
if (data) {
|
|
|
|
state.warnings = JSON.parse(data);
|
|
|
|
logger.debug('Loaded warnings file.');
|
|
|
|
} else {
|
|
|
|
logger.warn(`${readFilePath} appears to be an empty file.`);
|
|
|
|
}
|
2018-04-04 01:28:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-04 02:05:01 +02:00
|
|
|
function readBans() {
|
|
|
|
// Load the ban file into the application state.
|
|
|
|
var readFilePath = '/data/discordBans.json';
|
|
|
|
fs.readFile(readFilePath, 'utf8', function (err, data) {
|
|
|
|
if (err) { throw err; }
|
|
|
|
if (data) {
|
|
|
|
state.bans = JSON.parse(data);
|
|
|
|
logger.debug('Loaded bans file.');
|
|
|
|
} else {
|
|
|
|
logger.warn(`${readFilePath} appears to be an empty file.`);
|
|
|
|
}
|
2018-04-04 01:28:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-04 02:05:01 +02:00
|
|
|
function readCustomResponses() {
|
2018-04-04 01:28:33 +02:00
|
|
|
// Load the responses file into the responses variable.
|
2018-07-30 00:47:19 +02:00
|
|
|
state.responses = require(`./${process.env.TENANT}.json`);
|
|
|
|
logger.debug(`Loaded responses file for ${process.env.TENANT} from external source.`);
|
2018-04-04 01:28:33 +02:00
|
|
|
}
|
|
|
|
|
2018-04-04 02:05:01 +02:00
|
|
|
function flushWarnings() {
|
2018-04-04 01:28:33 +02:00
|
|
|
var warningsJson = JSON.stringify(state.warnings, null, 4);
|
|
|
|
fs.writeFile('/data/discordWarnings.json', warningsJson, 'utf8', function (err) {
|
2018-04-04 02:05:01 +02:00
|
|
|
if (err) { throw err; }
|
2018-04-04 01:28:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-04 02:05:01 +02:00
|
|
|
function flushBans() {
|
2018-04-04 01:28:33 +02:00
|
|
|
var bansJson = JSON.stringify(state.bans, null, 4);
|
|
|
|
fs.writeFile('/data/discordBans.json', bansJson, 'utf8', function (err) {
|
2018-04-04 02:05:01 +02:00
|
|
|
if (err) { throw err; }
|
2018-04-04 01:28:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { readWarnings: readWarnings, readBans: readBans, readCustomResponses: readCustomResponses, flushWarnings: flushWarnings, flushBans: flushBans };
|