Compare commits
3 Commits
4c27bd5a1e
...
ed3d18abfa
Author | SHA1 | Date | |
---|---|---|---|
ed3d18abfa | |||
3c755c0ba2 | |||
3300a0b34b |
36
bot.js
36
bot.js
@ -5,14 +5,27 @@
|
||||
// /_/ /_/ /_/\___/_/ \___/\__,_/_/ \__, /
|
||||
// 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+']'
|
||||
|
||||
@ -30,7 +43,6 @@ 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
|
||||
@ -54,13 +66,13 @@ function consoleLog(log) {
|
||||
var hostmask = null
|
||||
|
||||
function checkConfigValidity() {
|
||||
consoleLog(`[bot.checkConfigValidity] Opening cvc worker`)
|
||||
consoleLog(`[bot.checkConfigValidity] Opening config validator`)
|
||||
const worker = new Worker(`./commands/cvc.js`, {});
|
||||
worker.once('message', (string) => {
|
||||
if (string == 'kill') {
|
||||
process.exit()
|
||||
} else if (string == 'allg') {
|
||||
consoleLog('[bot.checkConfigValidity] Config validity checked, seems all good, continuing with initialisation')
|
||||
consoleLog('[bot.checkConfigValidity] Config seems valid, continuing')
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -210,9 +222,6 @@ 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) {
|
||||
@ -222,7 +231,6 @@ 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\}")
|
||||
@ -231,12 +239,22 @@ 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(100)
|
||||
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)
|
||||
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.useragent, config.feed.body_max_chars, config.feed.time_format, config.feed.timezone, config.feed.default_amount, config.feed.show_feed_title,
|
||||
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.useragent","config.feed.body_max_chars","config.feed.time_format","config.feed.timezone","config.feed.default_amount", "config.feed.show_feed_title",
|
||||
"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,6 +72,7 @@ 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,7 +41,8 @@
|
||||
"body_max_chars": "200",
|
||||
"time_format": "DD MMM YYYY HH:mm:ss ZZ",
|
||||
"timezone": "Pacific/Auckland",
|
||||
"default_amount": "5"
|
||||
"default_amount": "5",
|
||||
"show_feed_title": "true"
|
||||
},
|
||||
"twitter": {
|
||||
"nitter_instances": [
|
||||
|
Loading…
Reference in New Issue
Block a user