From 0983abde5fc8b8e2d47db710bf6689cf816f2add Mon Sep 17 00:00:00 2001 From: Ayfri Date: Sun, 25 Oct 2020 00:38:13 +0200 Subject: [PATCH] Added checks on JSONs. --- src/classes/SanctionCommand.js | 2 +- src/commands/moderation/infractions.js | 7 ++++++- src/events/ready.js | 4 +--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/classes/SanctionCommand.js b/src/classes/SanctionCommand.js index f53136a..e3e7e92 100644 --- a/src/classes/SanctionCommand.js +++ b/src/classes/SanctionCommand.js @@ -54,7 +54,7 @@ module.exports = class SanctionCommand extends Command { case: this.userData.sanctionsLastNumber, }); this.userData.sanctionsLastNumber++; - if (!writeInJSON('./assets/jsons/userData.json', this.userData)) { + if (!writeInJSON('./assets/jsons/userdata.json', this.userData)) { return runError(this.message, this, `Tentative d'écriture dans le fichier './assets/jsons/userdata.json', le fichier n'a pas été trouvé.`); } diff --git a/src/commands/moderation/infractions.js b/src/commands/moderation/infractions.js index 4bde1b1..9c277ee 100644 --- a/src/commands/moderation/infractions.js +++ b/src/commands/moderation/infractions.js @@ -1,5 +1,6 @@ const {MessageEmbed} = require('discord.js'); const Command = require('../../entities/Command.js'); +const {runError} = require('../../utils/Errors.js'); const {readJSON} = require('../../utils/Utils.js'); const {argTypes, tags} = require('../../constants.js'); const {getArg, getArgWithContent} = require('../../utils/ArgUtils.js'); @@ -63,7 +64,7 @@ module.exports = class InfractionsCommand extends Command { userData[message.guild.id][person.user.id] = { sanctions: [], }; - writeInJSON('./assets/jsons/userdata.json', userData); + this.writeData(userData); } if (args[1] === 'supprimer') { @@ -111,4 +112,8 @@ module.exports = class InfractionsCommand extends Command { return this.createPage(userData, page, person.user, embed); } + + writeData(userData) { + if (!writeInJSON('./assets/jsons/userdata.json', userData)) runError(this.message, this, "Tentative d'écriture dans le fichier './assets/jsons/userdata.json', le fichier n'a pas été trouvé."); + } }; diff --git a/src/events/ready.js b/src/events/ready.js index 81a5f1b..3021098 100644 --- a/src/events/ready.js +++ b/src/events/ready.js @@ -25,11 +25,10 @@ module.exports = class ReadyEvent extends Event { async run(client) { await super.run(client); - // Status + this.setRandomPresence(); setInterval(() => this.setRandomPresence(), 10 * 1000); - // REBOOT const config = readJSON('./assets/jsons/config.json'); if (config.statut === 'reboot') { if (client.channels.cache.has(config.cacheChannel)) client.channels.cache.get(config.cacheChannel).send('Relancement du bot fini.'); @@ -52,7 +51,6 @@ module.exports = class ReadyEvent extends Event { config.dateUpdate = parseDate('dd/MM/yyyy'); writeInJSON('./assets/jsons/config.json', config); - // Logging Logger.info(`${client.user.username} (${client.user.id}) Est allumé ! Nombre de serveurs : ${client.guilds.cache.size}.`, 'ReadyEvent'); this.logInfosOfBot();