Refactor Athena's Shield configuration handling

This commit is contained in:
Sandro642 2024-10-27 10:45:45 +01:00
parent f0321e1f6d
commit 0348e83ffe
4 changed files with 21 additions and 42 deletions

View File

@ -1,5 +0,0 @@
{
"athenaShieldActivated": false,
"menuVisibility": "visible",
"debug": "false"
}

View File

@ -2,75 +2,62 @@ const fs = require('fs')
const readline = require('readline')
const path = require('path')
// Path to the configuration file
const configPath = path.join(__dirname, 'variables.athshield')
const configPath = path.join(__dirname, 'variables.json')
// Load the variables from the file
function loadConfig() {
const rawData = fs.readFileSync(configPath)
return JSON.parse(rawData.toString()) // Convert Buffer to string
return JSON.parse(rawData.toString())
}
// Save the variables to the file
function saveConfig(config) {
const data = JSON.stringify(config, null, 2)
fs.writeFileSync(configPath, data)
}
// Create the readline interface
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
// Function to ask questions to the user
function startCLI() {
const config = loadConfig()
rl.question('Would you like to activate Athena\'s Shield? (yes/no): ', (answer) => {
if (answer.trim().startsWith('//')) {
console.log('This is a comment; the line is ignored.')
rl.question('Would you like to activate extra file verification? (yes/no): ', (answer) => {
rl.close()
return
}
if (answer.toLowerCase() === 'yes') {
config.athenaShieldActivated = true
config.extraFileVerifActivated = true
rl.question('Would you like to activate debug mode? (yes/no): ', (debugAnswer) => {
config.debug = debugAnswer.toLowerCase() === 'yes' // Set debug to true or false
config.debug = debugAnswer.toLowerCase() === 'yes'
rl.question('Would you like to hide or block the menu? (hide/block): ', (menuAnswer) => {
if (menuAnswer.trim().startsWith('//')) {
console.log('This is a comment; the line is ignored.')
rl.close()
return
}
if (menuAnswer.toLowerCase() === 'hide') {
config.menuVisibility = 'hidden' // Set to 'hidden'
console.log('Athena\'s Shield activated. Menu hidden.')
config.menuVisibility = 'hidden'
console.log('Extra file verification is activated. Menu hidden.')
} else if (menuAnswer.toLowerCase() === 'block') {
config.menuVisibility = 'blocked' // Set to 'blocked'
console.log('Athena\'s Shield activated. Menu blocked.')
config.menuVisibility = 'blocked'
console.log('Extra file verification is activated. Menu blocked.')
} else {
console.log('Invalid option for the menu.')
rl.close()
return
}
// Save the modified configuration
saveConfig(config)
rl.close()
})
})
} else if (answer.toLowerCase() === 'no') {
console.log('Athena\'s Shield not activated. Closing the CLI.')
config.athenaShieldActivated = false
config.menuVisibility = 'visible' // Reset to default
config.debug = 'false'
console.log('Extra file verification is not activated. Closing the CLI.')
config.extraFileVerifActivated = false
config.menuVisibility = 'visible'
config.debug = false
// Save the modified configuration
saveConfig(config)
rl.close()
} else {
@ -80,5 +67,4 @@ function startCLI() {
})
}
// Launch the CLI
startCLI()

View File

@ -1,37 +1,30 @@
const fs = require('fs')
const path = require('path')
// Chemin vers le fichier de configuration
const configPath = path.join(__dirname, 'variables.athshield')
const configPath = path.join(__dirname, 'variables.json')
// Classe pour gérer Athena's Shield
class AthenaShield {
class ExtraFileVerification {
constructor() {
this.config = this.loadConfig()
}
// Charger les variables depuis le fichier
loadConfig() {
const rawData = fs.readFileSync(configPath)
return JSON.parse(rawData.toString())
}
// Récupérer le statut d'Athena's Shield
get status() {
return this.config.athenaShieldActivated
return this.config.extraFileVerifActivated
}
// Récupérer la visibilité du menu
get type() {
return this.config.menuVisibility
}
// Récupérer le mode debug
get debug() {
return this.config.debug
}
}
// Exporter une instance de la classe
const athenaShieldInstance = new AthenaShield()
module.exports = athenaShieldInstance

View File

@ -0,0 +1,5 @@
{
"extraFileVerifActivated": false,
"menuVisibility": "visible",
"debug": "false"
}