Enhance init logging + add more user setting file generation error handling

This commit is contained in:
hgw 2023-10-02 02:11:27 +00:00
parent a87de44e61
commit 16af27106f

24
bot.js
View File

@ -1,3 +1,10 @@
// Mercury RSS Client - git.supernets.org/hgw/mercury
// ____ ___ ___ ____________ _________ __
// / __ `__ \/ _ \/ ___/ ___/ / / / ___/ / / /
// / / / / / / __/ / / /__/ /_/ / / / /_/ /
// /_/ /_/ /_/\___/_/ \___/\__,_/_/ \__, /
// COLD HARD FEEDS /____/
//
var config = require('./config/default.json');
//var uconfig = require('./config/usersettings.json');
var irc = require("irc");
@ -202,7 +209,6 @@ bot.addListener('error', function(message) {
});
async function init() {
consoleLog('[bot.init] Welcome to Mercury');
consoleLog('[bot.init] Checking config validity')
checkConfigValidity()
await timer(1500)
@ -212,17 +218,31 @@ async function init() {
fs.writeFile('./config/usersettings.json', '', function(err) {
if(err) {
consoleLog(err);
consoleLog('[bot.init] [FATAL] User settings file could not be created. Mercury can not start')
process.exit()
}
consoleLog("[bot.init] User settings did not exist, it has been created for you");
consoleLog("[bot.init] User settings does not exist, please hold...");
});
try {
fs.writeFileSync('./config/usersettings.json', "\{\n\}")
} catch(e) {
consoleLog(e)
consoleLog('[bot.init] [FATAL] User settings file was created but is not writable, could be a permissions issue. Mercury can not start')
process.exit()
}
consoleLog('[bot.init] User settings file has been created')
} else {
consoleLog("[bot.init] User settings file exists");
}
});
await timer(100)
if (config.irc.ssl == "true") {
consoleLog('[bot.init] Initialisation completed, connecting to '+config.irc.server+'/'+config.irc.port+' (SSL) as '+config.irc.nickname);
} else {
consoleLog('[bot.init] Initialisation completed, connecting to '+config.irc.server+'/'+config.irc.port+' as '+config.irc.nickname);
}
consoleLog('[bot] Welcome to Mercury');
}
init()