mirror of
https://github.com/yuzu-emu/Command-fix.git
synced 2024-11-25 04:35:41 +01:00
Implement loading responses from data/ (#27)
This commit is contained in:
parent
e976651df7
commit
2a6c57ce0d
6
env.json
6
env.json
@ -19,5 +19,9 @@
|
|||||||
"CANARY_WEBHOOK_URL": {
|
"CANARY_WEBHOOK_URL": {
|
||||||
"required": false,
|
"required": false,
|
||||||
"description": "The URL for the webhook to trigger canary builds."
|
"description": "The URL for the webhook to trigger canary builds."
|
||||||
|
},
|
||||||
|
"DATA_CUSTOM_RESPONSES": {
|
||||||
|
"required": false,
|
||||||
|
"description": "Whether or not to load responses.js from the data directory."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
src/data.js
13
src/data.js
@ -22,6 +22,17 @@ function readBans () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readCustomResponses()
|
||||||
|
{
|
||||||
|
// Load the responses file into the responses variable.
|
||||||
|
fs.readFile('data/responses.json', 'utf8', function (err, data) {
|
||||||
|
if (err && err.code === 'ENOENT') { return; }
|
||||||
|
if (err) { logger.error(err); }
|
||||||
|
state.responses = JSON.parse(data);
|
||||||
|
logger.debug('Loaded responses file.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function flushWarnings () {
|
function flushWarnings () {
|
||||||
var warningsJson = JSON.stringify(state.warnings, null, 4);
|
var warningsJson = JSON.stringify(state.warnings, null, 4);
|
||||||
if (!fs.existsSync('./data/')) fs.mkdirSync('data');
|
if (!fs.existsSync('./data/')) fs.mkdirSync('data');
|
||||||
@ -38,4 +49,4 @@ function flushBans () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { readWarnings: readWarnings, readBans: readBans, flushWarnings: flushWarnings, flushBans: flushBans };
|
module.exports = { readWarnings: readWarnings, readBans: readBans, readCustomResponses: readCustomResponses, flushWarnings: flushWarnings, flushBans: flushBans };
|
||||||
|
@ -10,7 +10,7 @@ const logger = require('./logging.js');
|
|||||||
const state = require('./state.js');
|
const state = require('./state.js');
|
||||||
const data = require('./data.js');
|
const data = require('./data.js');
|
||||||
|
|
||||||
var responses = require('./responses.json');
|
state.responses = require('./responses.json');
|
||||||
|
|
||||||
var cachedModules = [];
|
var cachedModules = [];
|
||||||
var cachedTriggers = [];
|
var cachedTriggers = [];
|
||||||
@ -57,11 +57,11 @@ schedule.scheduleJob({ hour: 3, minute: 30 }, function () {
|
|||||||
client.on('message', message => {
|
client.on('message', message => {
|
||||||
if (message.author.bot && message.content.startsWith('.ban') === false) { return; }
|
if (message.author.bot && message.content.startsWith('.ban') === false) { return; }
|
||||||
|
|
||||||
if (message.guild == null && responses.pmReply) {
|
if (message.guild == null && state.responses.pmReply) {
|
||||||
// We want to log PM attempts.
|
// We want to log PM attempts.
|
||||||
logger.info(`${message.author.username} ${message.author} [PM]: ${message.content}`);
|
logger.info(`${message.author.username} ${message.author} [PM]: ${message.content}`);
|
||||||
state.logChannel.sendMessage(`${message.author} [PM]: ${message.content}`);
|
state.logChannel.sendMessage(`${message.author} [PM]: ${message.content}`);
|
||||||
message.reply(responses.pmReply);
|
message.reply(state.responses.pmReply);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ client.on('message', message => {
|
|||||||
let cachedModule = cachedModules[`${cmd}.js`];
|
let cachedModule = cachedModules[`${cmd}.js`];
|
||||||
let cachedModuleType = 'Command';
|
let cachedModuleType = 'Command';
|
||||||
// Check by the quotes in the configuration.
|
// Check by the quotes in the configuration.
|
||||||
if (cachedModule == null) { cachedModule = responses.quotes[cmd]; cachedModuleType = 'Quote'; }
|
if (cachedModule == null) { cachedModule = state.responses.quotes[cmd]; cachedModuleType = 'Quote'; }
|
||||||
|
|
||||||
if (cachedModule) {
|
if (cachedModule) {
|
||||||
// Check access permissions.
|
// Check access permissions.
|
||||||
@ -157,5 +157,11 @@ fs.readdirSync('./src/triggers/').forEach(function (file) {
|
|||||||
data.readWarnings();
|
data.readWarnings();
|
||||||
data.readBans();
|
data.readBans();
|
||||||
|
|
||||||
|
// Load custom responses
|
||||||
|
if (process.env.DATA_CUSTOM_RESPONSES)
|
||||||
|
{
|
||||||
|
data.readCustomResponses();
|
||||||
|
}
|
||||||
|
|
||||||
client.login(process.env.DISCORD_LOGIN_TOKEN);
|
client.login(process.env.DISCORD_LOGIN_TOKEN);
|
||||||
logger.info('Startup completed. Established connection to Discord.');
|
logger.info('Startup completed. Established connection to Discord.');
|
||||||
|
@ -3,6 +3,7 @@ var State = function () {
|
|||||||
this.guild = null;
|
this.guild = null;
|
||||||
this.logChannel = null;
|
this.logChannel = null;
|
||||||
this.warnings = [];
|
this.warnings = [];
|
||||||
|
this.responses = null;
|
||||||
this.bans = [];
|
this.bans = [];
|
||||||
this.stats = {
|
this.stats = {
|
||||||
joins: 0,
|
joins: 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user