Compare commits
No commits in common. "ed3d18abfa7289188e6bc693056106b95cccf22f" and "4c27bd5a1ebc7a9d6568847b45243de48caac507" have entirely different histories.
ed3d18abfa
...
4c27bd5a1e
36
bot.js
36
bot.js
@ -5,27 +5,14 @@
|
||||
// /_/ /_/ /_/\___/_/ \___/\__,_/_/ \__, /
|
||||
// COLD HARD FEEDS /____/
|
||||
//
|
||||
//var config = require('./config/default.json');
|
||||
var config = require('./config/default.json');
|
||||
//var uconfig = require('./config/usersettings.json');
|
||||
var irc = require("irc");
|
||||
var fs = require("fs");
|
||||
var readline = require('readline');
|
||||
const { Worker } = require('worker_threads');
|
||||
const { setMaxIdleHTTPParsers } = require("http");
|
||||
//var randomWords = require('better-random-words');
|
||||
|
||||
const timer = ms => new Promise(res => setTimeout(res, ms))
|
||||
|
||||
console.log('[bot] Checking if config file exists')
|
||||
if (fs.existsSync('./config/default.json')) {
|
||||
var config = require('./config/default.json');
|
||||
console.log('[bot] Config file exists, can proceed with initialisation')
|
||||
} else {
|
||||
console.log('[bot] The config file, default.json, does not exist in the config folder. Mercury can not start.')
|
||||
process.exit()
|
||||
}
|
||||
timer(100)
|
||||
|
||||
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
||||
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
|
||||
|
||||
@ -43,6 +30,7 @@ var bot = new irc.Client(config.irc.server, config.irc.nickname, {
|
||||
const msgTimeout = new Set();
|
||||
const msgTimeoutMsg = new Set();
|
||||
|
||||
const timer = ms => new Promise(res => setTimeout(res, ms))
|
||||
|
||||
const isValidUrl = urlString=> {
|
||||
var urlPattern = new RegExp('^(https?:\\/\\/)?'+ // validate protocol
|
||||
@ -66,13 +54,13 @@ function consoleLog(log) {
|
||||
var hostmask = null
|
||||
|
||||
function checkConfigValidity() {
|
||||
consoleLog(`[bot.checkConfigValidity] Opening config validator`)
|
||||
consoleLog(`[bot.checkConfigValidity] Opening cvc worker`)
|
||||
const worker = new Worker(`./commands/cvc.js`, {});
|
||||
worker.once('message', (string) => {
|
||||
if (string == 'kill') {
|
||||
process.exit()
|
||||
} else if (string == 'allg') {
|
||||
consoleLog('[bot.checkConfigValidity] Config seems valid, continuing')
|
||||
consoleLog('[bot.checkConfigValidity] Config validity checked, seems all good, continuing with initialisation')
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -222,6 +210,9 @@ bot.addListener('error', function(message) {
|
||||
});
|
||||
|
||||
async function init() {
|
||||
consoleLog('[bot.init] Checking config validity')
|
||||
checkConfigValidity()
|
||||
await timer(1500)
|
||||
consoleLog('[bot.init] Checking if user settings file exists')
|
||||
fs.open('./config/usersettings.json','r',function(err, fd){
|
||||
if (err) {
|
||||
@ -231,6 +222,7 @@ async function init() {
|
||||
consoleLog('[bot.init] [FATAL] User settings file could not be created. Mercury can not start')
|
||||
process.exit()
|
||||
}
|
||||
consoleLog("[bot.init] User settings does not exist, please hold...");
|
||||
});
|
||||
try {
|
||||
fs.writeFileSync('./config/usersettings.json', "\{\n\}")
|
||||
@ -239,22 +231,12 @@ async function init() {
|
||||
consoleLog('[bot.init] [FATAL] User settings file was created but is not writable, could be a permissions issue. Mercury can not start')
|
||||
process.exit()
|
||||
}
|
||||
timer(100)
|
||||
consoleLog('[bot.init] User settings file has been created')
|
||||
} else {
|
||||
consoleLog("[bot.init] User settings file exists");
|
||||
}
|
||||
});
|
||||
await timer(500)
|
||||
try {
|
||||
if (config.errorhandling.validity_override === "TRUE") {
|
||||
consoleLog('[bot.init] Config validity override switch enabled, will not check for validity')
|
||||
}
|
||||
} catch(e) {
|
||||
consoleLog('[bot.init] Checking config validity')
|
||||
checkConfigValidity()
|
||||
}
|
||||
await timer(2000)
|
||||
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 {
|
||||
|
@ -45,7 +45,7 @@ function checkValuesExist() {
|
||||
config.floodprotect.flood_protection, config.floodprotect.flood_protection_delay,
|
||||
config.errorhandling.error_logging, config.errorhandling.error_channel, config.errorhandling.error_channel_pass,
|
||||
config.colours.date, config.colours.brackets, config.colours.title, config.colours.author, config.colours.body, config.colours.link, config.colours.help_logo, config.colours.help_motd, config.colours.warning, config.colours.error,
|
||||
config.feed.useragent, config.feed.body_max_chars, config.feed.time_format, config.feed.timezone, config.feed.default_amount, config.feed.show_feed_title,
|
||||
config.feed.useragent, config.feed.body_max_chars, config.feed.time_format, config.feed.timezone, config.feed.default_amount,
|
||||
config.twitter.nitter_instances, config.twitter.default_amount,
|
||||
config.misc.display_help_logo, config.misc.logging,
|
||||
config.motd.enable, config.motd.list, config.motd.version
|
||||
@ -55,7 +55,7 @@ function checkValuesExist() {
|
||||
"config.floodprotect.flood_protection", "config.floodprotect.flood_protection_delay",
|
||||
"config.errorhandling.error_logging","config.errorhandling.error_channel","config.errorhandling.error_channel_pass",
|
||||
"config.colours.date","config.colours.brackets","config.colours.title","config.colours.author","config.colours.body","config.colours.link","config.colours.help_logo","config.colours.help_motd","config.colours.warning","config.colours.error",
|
||||
"config.feed.useragent","config.feed.body_max_chars","config.feed.time_format","config.feed.timezone","config.feed.default_amount", "config.feed.show_feed_title",
|
||||
"config.feed.useragent","config.feed.body_max_chars","config.feed.time_format","config.feed.timezone","config.feed.default_amount",
|
||||
"config.twitter.nitter_instances","config.twitter.default_amount",
|
||||
"config.misc.display_help_logo","config.misc.logging",
|
||||
"config.motd.enable","config.motd.list","config.motd.version"
|
||||
@ -72,7 +72,6 @@ function checkValuesExist() {
|
||||
|
||||
})
|
||||
if (fatalConfigError.has('kill') == true ){
|
||||
timer(10)
|
||||
consoleLog('[cvc.checkValuesExist] [FATAL] Config is improperly configured, Mercury can not start')
|
||||
sendUpstream('kill')
|
||||
} else {
|
||||
|
@ -41,8 +41,7 @@
|
||||
"body_max_chars": "200",
|
||||
"time_format": "DD MMM YYYY HH:mm:ss ZZ",
|
||||
"timezone": "Pacific/Auckland",
|
||||
"default_amount": "5",
|
||||
"show_feed_title": "true"
|
||||
"default_amount": "5"
|
||||
},
|
||||
"twitter": {
|
||||
"nitter_instances": [
|
||||
|
Loading…
Reference in New Issue
Block a user