add more detailed logging
This commit is contained in:
parent
2fc39ca86f
commit
f08878e990
32
bot.js
32
bot.js
@ -33,14 +33,23 @@ const isValidUrl = urlString=> {
|
|||||||
return !!urlPattern.test(urlString);
|
return !!urlPattern.test(urlString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function consoleLog(log) {
|
||||||
|
if (config.misc.logging === "true") {
|
||||||
|
console.log(log)
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function openPostWorker(chan, command, d1, d2, d3, d4, d5) {
|
function openPostWorker(chan, command, d1, d2, d3, d4, d5) {
|
||||||
|
consoleLog(`[bot.openPostWorker] Opening ${command} worker`)
|
||||||
const worker = new Worker(`./commands/${command}.js`, {
|
const worker = new Worker(`./commands/${command}.js`, {
|
||||||
workerData: {
|
workerData: {
|
||||||
d1, d2, d3, d4, d5
|
d1, d2, d3, d4, d5
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
worker.once('message', (string) => {
|
worker.once('message', (string) => {
|
||||||
console.log(`${command} worker has signalled it has completed, sending output to IRC`);
|
consoleLog(`[bot.openPostWorker] Got output from ${command}, sending to `+chan);
|
||||||
bot.say(chan, string);
|
bot.say(chan, string);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -56,24 +65,23 @@ async function opt(chan, user, setting, setting2, value, value2) {
|
|||||||
async function feed(chan, nick, provfeed, n) {
|
async function feed(chan, nick, provfeed, n) {
|
||||||
var userconf = fs.readFileSync('./config/usersettings.json')
|
var userconf = fs.readFileSync('./config/usersettings.json')
|
||||||
var uconfig = JSON.parse(userconf)
|
var uconfig = JSON.parse(userconf)
|
||||||
|
|
||||||
if (provfeed === undefined) {
|
if (provfeed === undefined) {
|
||||||
|
consoleLog('[bot.feed] No feed provided')
|
||||||
bot.say(chan, errorMsg+" No feed has been provided.")
|
bot.say(chan, errorMsg+" No feed has been provided.")
|
||||||
return;
|
return;
|
||||||
} else if (provfeed === 'me' ) {
|
} else if (provfeed === 'me' ) {
|
||||||
|
consoleLog('[bot.feed] \"me\" was passed, correcting to '+nick)
|
||||||
var provfeed = nick;
|
var provfeed = nick;
|
||||||
}
|
}
|
||||||
if (n === undefined) {
|
if (n === undefined) {
|
||||||
|
consoleLog('[bot.feed] no amount was passed, reverting to default')
|
||||||
var n = config.feed.default_amount;
|
var n = config.feed.default_amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(isValidUrl(provfeed))
|
|
||||||
console.log(provfeed === nick)
|
|
||||||
console.log(uconfig[nick].alias !== undefined)
|
|
||||||
|
|
||||||
if (isValidUrl(provfeed) === true) { //URL Lookup
|
if (isValidUrl(provfeed) === true) { //URL Lookup
|
||||||
|
consoleLog('[bot.feed] Valid URL requested')
|
||||||
openPostWorker(chan, 'feed-preset', provfeed, n);
|
openPostWorker(chan, 'feed-preset', provfeed, n);
|
||||||
} else if (provfeed === nick) { //User Feed Lookup
|
} else if (provfeed === nick) { //User Feed Lookup
|
||||||
|
consoleLog('[bot.feed] User feed requested')
|
||||||
if ( uconfig[nick] !== undefined ) { //If users nickname exists in json file
|
if ( uconfig[nick] !== undefined ) { //If users nickname exists in json file
|
||||||
openPostWorker(chan, 'feed-list', provfeed, n, nick);
|
openPostWorker(chan, 'feed-list', provfeed, n, nick);
|
||||||
} else { //If it does not
|
} else { //If it does not
|
||||||
@ -81,15 +89,18 @@ async function feed(chan, nick, provfeed, n) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (uconfig[nick].alias !== undefined ) { //Alias Lookup
|
} else if (uconfig[nick].alias !== undefined ) { //Alias Lookup
|
||||||
|
consoleLog('[bot.feed] Alias requested')
|
||||||
var provfeed = uconfig[nick].alias[provfeed]
|
var provfeed = uconfig[nick].alias[provfeed]
|
||||||
openPostWorker(chan, "feed-preset", provfeed, n);
|
openPostWorker(chan, "feed-preset", provfeed, n);
|
||||||
} else {
|
} else {
|
||||||
bot.say(chan, 'Not sure how you managed to get this error, but good job')
|
consoleLog('[bot.feed] No valid feed entered')
|
||||||
|
bot.say(chan, errorMsg+" Your chosen feed or alias is not valid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function twitter(chan, provfeed, n) {
|
async function twitter(chan, provfeed, n) {
|
||||||
if (provfeed === undefined) {
|
if (provfeed === undefined) {
|
||||||
|
consoleLog('[bot.twitter] No twitter account provided')
|
||||||
bot.say(chan, errorMsg+" No account has been provided.")
|
bot.say(chan, errorMsg+" No account has been provided.")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -113,7 +124,8 @@ bot.addListener('message', function(nick, to, text, from) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
bot.addListener('error', function(message) {
|
bot.addListener('error', function(message) {
|
||||||
console.log('error: ', message);
|
consoleLog('[ERROR]' +message)
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Starting Mercury');
|
console.log('[main] Starting Mercury');
|
||||||
|
console.log('[main.irc] Connecting to '+config.irc.server+'/'+config.irc.port+' as '+config.irc.nickname)
|
@ -17,14 +17,23 @@ const timer = ms => new Promise(res => setTimeout(res, ms))
|
|||||||
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
||||||
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
|
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
|
||||||
|
|
||||||
|
function consoleLog(log) {
|
||||||
|
if (config.misc.logging === "true") {
|
||||||
|
console.log(log)
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function sendUpstream(content) {
|
async function sendUpstream(content) {
|
||||||
var output = content.join("\n")
|
var output = content.join("\n")
|
||||||
|
consoleLog('[feed-list] All done.')
|
||||||
parentPort.postMessage(output);
|
parentPort.postMessage(output);
|
||||||
process.exit()
|
process.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
function errorMessage(error, code, extra) {
|
function errorMessage(error, code, extra) {
|
||||||
console.log(error.code)
|
consoleLog('[feed-list.errorMessage] '+error.code)
|
||||||
if (code == "404") {
|
if (code == "404") {
|
||||||
var error = errorMsg+" 404: " + extra + " not found"
|
var error = errorMsg+" 404: " + extra + " not found"
|
||||||
} else if (error.code == "ECONNREFUSED") {
|
} else if (error.code == "ECONNREFUSED") {
|
||||||
@ -55,6 +64,7 @@ async function fetchFeed(feedURL, n, nick) {
|
|||||||
var n = n/feedsArr.length
|
var n = n/feedsArr.length
|
||||||
}
|
}
|
||||||
for (let i = 0; i < feedsArr.length; i++) {
|
for (let i = 0; i < feedsArr.length; i++) {
|
||||||
|
consoleLog('[feed-list.fetchFeed] Fetching '+feedsArr[i])
|
||||||
try {
|
try {
|
||||||
var newFeed = await parser.parseURL(feedsArr[i]);
|
var newFeed = await parser.parseURL(feedsArr[i]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -83,7 +93,6 @@ async function fetchFeed(feedURL, n, nick) {
|
|||||||
if (data.isoDate !== undefined) {
|
if (data.isoDate !== undefined) {
|
||||||
var date = moment(data.isoDate)
|
var date = moment(data.isoDate)
|
||||||
var syncDate = date.tz(config.feed.timezone)
|
var syncDate = date.tz(config.feed.timezone)
|
||||||
console.log(syncDate.format())
|
|
||||||
var date = syncDate.format(config.feed.time_format)
|
var date = syncDate.format(config.feed.time_format)
|
||||||
} else {
|
} else {
|
||||||
var date = data.pubDate
|
var date = data.pubDate
|
||||||
@ -97,31 +106,12 @@ async function fetchFeed(feedURL, n, nick) {
|
|||||||
author = ''+config.colours.author+data.creator+' '
|
author = ''+config.colours.author+data.creator+' '
|
||||||
body = ''+config.colours.body+body+' '
|
body = ''+config.colours.body+body+' '
|
||||||
link = ''+config.colours.link+data.link+' '
|
link = ''+config.colours.link+data.link+' '
|
||||||
//console.log(data);
|
|
||||||
//var string = "15[11" + date + "15] 08" + title + " " + body + " " + data.link;
|
|
||||||
var string = date+title+body+link;
|
var string = date+title+body+link;
|
||||||
content.push(string)
|
content.push(string)
|
||||||
console.log(content)
|
|
||||||
}
|
}
|
||||||
//sendUpstream(content);
|
|
||||||
}
|
}
|
||||||
sendUpstream(content);
|
sendUpstream(content);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//var file = editJsonFile('/home/node/app/config/usersettings.json');
|
|
||||||
//async function getAllFeeds(nick, n) {
|
|
||||||
// console.log(nick)
|
|
||||||
// var feedsArr = uconfig[nick].feeds
|
|
||||||
// console.log(feedsArr)
|
|
||||||
// var num = n/feedsArr.length
|
|
||||||
// for (let i = 0; i < feedsArr.length; i++) {
|
|
||||||
// fetchFeed(feedsArr[i], num);
|
|
||||||
// }
|
|
||||||
// await sendUpstream(content);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//getAllFeeds(nick, n)
|
|
||||||
fetchFeed(provfeed, n, provfeed);
|
fetchFeed(provfeed, n, provfeed);
|
||||||
|
@ -15,14 +15,23 @@ const timer = ms => new Promise(res => setTimeout(res, ms))
|
|||||||
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
||||||
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
|
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
|
||||||
|
|
||||||
|
function consoleLog(log) {
|
||||||
|
if (config.misc.logging === "true") {
|
||||||
|
console.log(log)
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function sendUpstream(content) {
|
async function sendUpstream(content) {
|
||||||
var output = content.join("\n")
|
var output = content.join("\n")
|
||||||
|
consoleLog('[feed-preset] All done.')
|
||||||
parentPort.postMessage(output);
|
parentPort.postMessage(output);
|
||||||
process.exit()
|
process.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
function errorMessage(error, code, extra) {
|
function errorMessage(error, code, extra) {
|
||||||
console.log(error.code)
|
consoleLog('[feed-preset.errorMessage] '+error.code)
|
||||||
if (code == "404") {
|
if (code == "404") {
|
||||||
var error = errorMsg+" 404: " + extra + " not found"
|
var error = errorMsg+" 404: " + extra + " not found"
|
||||||
} else if (error.code == "ECONNREFUSED") {
|
} else if (error.code == "ECONNREFUSED") {
|
||||||
@ -39,6 +48,7 @@ function errorMessage(error, code, extra) {
|
|||||||
|
|
||||||
async function fetchFeed(feedURL, n) {
|
async function fetchFeed(feedURL, n) {
|
||||||
var content = [];
|
var content = [];
|
||||||
|
consoleLog('[feed-preset.fetchFeed] Fetching '+feedURL)
|
||||||
try {
|
try {
|
||||||
var newFeed = await parser.parseURL(feedURL);
|
var newFeed = await parser.parseURL(feedURL);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -67,7 +77,6 @@ async function fetchFeed(feedURL, n) {
|
|||||||
if (data.isoDate !== undefined) {
|
if (data.isoDate !== undefined) {
|
||||||
var date = moment(data.isoDate)
|
var date = moment(data.isoDate)
|
||||||
var syncDate = date.tz(config.feed.timezone)
|
var syncDate = date.tz(config.feed.timezone)
|
||||||
console.log(syncDate.format())
|
|
||||||
var date = syncDate.format(config.feed.time_format)
|
var date = syncDate.format(config.feed.time_format)
|
||||||
} else {
|
} else {
|
||||||
var date = data.pubDate
|
var date = data.pubDate
|
||||||
|
@ -8,15 +8,23 @@ const timer = ms => new Promise(res => setTimeout(res, ms))
|
|||||||
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
||||||
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
|
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
|
||||||
|
|
||||||
|
function consoleLog(log) {
|
||||||
|
if (config.misc.logging === "true") {
|
||||||
|
console.log(log)
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function sendUpstream(content) {
|
async function sendUpstream(content) {
|
||||||
var output = content.join("\n")
|
var output = content.join("\n")
|
||||||
|
consoleLog('[help] All done.')
|
||||||
parentPort.postMessage(output);
|
parentPort.postMessage(output);
|
||||||
process.exit()
|
process.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
function errorMessage(error, code, extra) {
|
function errorMessage(error, code, extra) {
|
||||||
console.log(error.code)
|
consoleLog('[help.errorMessage] '+error.code)
|
||||||
if (code == "404") {
|
if (code == "404") {
|
||||||
var error = errorMsg+" 404: " + extra + " not found"
|
var error = errorMsg+" 404: " + extra + " not found"
|
||||||
} else if (error.code == "ECONNREFUSED") {
|
} else if (error.code == "ECONNREFUSED") {
|
||||||
@ -37,13 +45,15 @@ async function help(sub) {
|
|||||||
var sub = "default"
|
var sub = "default"
|
||||||
}
|
}
|
||||||
if (sub === "default") {
|
if (sub === "default") {
|
||||||
console.log(config.misc.display_help_logo)
|
|
||||||
if (config.misc.display_help_logo === 'true' ) {
|
if (config.misc.display_help_logo === 'true' ) {
|
||||||
|
consoleLog('[help.default] Logo enabled, including in output')
|
||||||
content.push(''+config.colours.help_logo+' ____ ___ ___ ____________ _________ __')
|
content.push(''+config.colours.help_logo+' ____ ___ ___ ____________ _________ __')
|
||||||
content.push(''+config.colours.help_logo+' / __ `__ \\/ _ \\/ ___/ ___/ / / / ___/ / / /')
|
content.push(''+config.colours.help_logo+' / __ `__ \\/ _ \\/ ___/ ___/ / / / ___/ / / /')
|
||||||
content.push(''+config.colours.help_logo+' / / / / / / __/ / / /__/ /_/ / / / /_/ / ')
|
content.push(''+config.colours.help_logo+' / / / / / / __/ / / /__/ /_/ / / / /_/ / ')
|
||||||
content.push(''+config.colours.help_logo+'/_/ /_/ /_/\\___/_/ \\___/\\__,_/_/ \\__, / ')
|
content.push(''+config.colours.help_logo+'/_/ /_/ /_/\\___/_/ \\___/\\__,_/_/ \\__, / ')
|
||||||
content.push(''+config.colours.help_logo+' /____/ ')
|
content.push(''+config.colours.help_logo+' /____/ ')
|
||||||
|
} else if (config.misc.display_help_logo !== 'true') {
|
||||||
|
consoleLog('[help.default] Logo disabled, not including in output')
|
||||||
}
|
}
|
||||||
content.push('Mercury RSS Client - https://git.supernets.org/hogwart7/mercury')
|
content.push('Mercury RSS Client - https://git.supernets.org/hogwart7/mercury')
|
||||||
content.push('m!feed [USER/FEED/ALIAS] [ENTRIES] - Return the last x amount of entries from any RSS feed or your own saved feeds (if you have saved feeds)')
|
content.push('m!feed [USER/FEED/ALIAS] [ENTRIES] - Return the last x amount of entries from any RSS feed or your own saved feeds (if you have saved feeds)')
|
||||||
|
@ -18,13 +18,22 @@ const timer = ms => new Promise(res => setTimeout(res, ms))
|
|||||||
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
||||||
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
|
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
|
||||||
|
|
||||||
|
function consoleLog(log) {
|
||||||
|
if (config.misc.logging === "true") {
|
||||||
|
console.log(log)
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function sendUpstream(content) {
|
async function sendUpstream(content) {
|
||||||
parentPort.postMessage(content);
|
parentPort.postMessage(content);
|
||||||
|
consoleLog('[options] All done.')
|
||||||
process.exit()
|
process.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
function errorMessage(error, code, extra) {
|
function errorMessage(error, code, extra) {
|
||||||
console.log(error.code)
|
consoleLog('[options.errorMessage] '+error.code)
|
||||||
if (code == "404") {
|
if (code == "404") {
|
||||||
var error = errorMsg+" 404: " + extra + " not found"
|
var error = errorMsg+" 404: " + extra + " not found"
|
||||||
} else if (error.code == "ECONNREFUSED") {
|
} else if (error.code == "ECONNREFUSED") {
|
||||||
@ -46,18 +55,18 @@ function errorMessage(error, code, extra) {
|
|||||||
|
|
||||||
async function testFeed(feedURL) {
|
async function testFeed(feedURL) {
|
||||||
try {
|
try {
|
||||||
console.log('Testing feed')
|
consoleLog('[options.testFeed] Testing '+feed)
|
||||||
var feed = await parser.parseURL(feedURL);
|
var feed = await parser.parseURL(feedURL);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
consoleLog('[options.testFeed] '+e)
|
||||||
errorMessage(e, "INVALID", feedURL);
|
errorMessage(e, "INVALID", feedURL);
|
||||||
}
|
}
|
||||||
console.log(feed)
|
consoleLog("[options.testFeed] Feed is valid, continuing")
|
||||||
console.log("Feed is good, saving")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function feed(nick, setting, value) {
|
async function feed(nick, setting, value) {
|
||||||
if (setting === 'add') {
|
if (setting === 'add') {
|
||||||
|
consoleLog('[options.feed] '+nick+' is adding '+value)
|
||||||
await testFeed(value);
|
await testFeed(value);
|
||||||
var file = editJsonFile('/home/node/app/config/usersettings.json');
|
var file = editJsonFile('/home/node/app/config/usersettings.json');
|
||||||
var feedsArr = uconfig[nick].feeds
|
var feedsArr = uconfig[nick].feeds
|
||||||
@ -73,7 +82,7 @@ async function feed(nick, setting, value) {
|
|||||||
content = [];
|
content = [];
|
||||||
try {
|
try {
|
||||||
var feedsArr = uconfig[nick].feeds
|
var feedsArr = uconfig[nick].feeds
|
||||||
console.log(feedsArr)
|
consoleLog('[options.feed] Listing existing feeds for '+nick+': '+feedsArr)
|
||||||
content.push("These are your added feeds:")
|
content.push("These are your added feeds:")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorMessage(e, "NOFEEDS", nick);
|
errorMessage(e, "NOFEEDS", nick);
|
||||||
@ -88,6 +97,7 @@ async function feed(nick, setting, value) {
|
|||||||
|
|
||||||
async function alias(setting, value, url, nick) {
|
async function alias(setting, value, url, nick) {
|
||||||
if (setting === 'add') {
|
if (setting === 'add') {
|
||||||
|
consoleLog('[options.alias] Adding/editing an alias for'+nick+': '+value+' ==> '+url)
|
||||||
await testFeed(url);
|
await testFeed(url);
|
||||||
var file = editJsonFile('/home/node/app/config/usersettings.json');
|
var file = editJsonFile('/home/node/app/config/usersettings.json');
|
||||||
file.set(nick+'.alias.'+value, url);
|
file.set(nick+'.alias.'+value, url);
|
||||||
@ -95,6 +105,7 @@ async function alias(setting, value, url, nick) {
|
|||||||
sendUpstream('Alias added ('+value+' ==> '+url+')')
|
sendUpstream('Alias added ('+value+' ==> '+url+')')
|
||||||
}
|
}
|
||||||
if (setting === 'del') {
|
if (setting === 'del') {
|
||||||
|
consoleLog('[options.alias] Removing an alias for '+nick+': '+value+' ==> \"\"')
|
||||||
var file = editJsonFile('/home/node/app/config/usersettings.json');
|
var file = editJsonFile('/home/node/app/config/usersettings.json');
|
||||||
file.set(nick+'.alias.'+value, "");
|
file.set(nick+'.alias.'+value, "");
|
||||||
file.save();
|
file.save();
|
||||||
@ -103,6 +114,7 @@ async function alias(setting, value, url, nick) {
|
|||||||
if (setting === 'list') {
|
if (setting === 'list') {
|
||||||
content = [];
|
content = [];
|
||||||
var obj = uconfig[nick].alias
|
var obj = uconfig[nick].alias
|
||||||
|
consoleLog('[options.alias] Listing aliases for '+nick+': '+obj)
|
||||||
console.log(obj)
|
console.log(obj)
|
||||||
for (const [key, val] of Object.entries(obj)) {
|
for (const [key, val] of Object.entries(obj)) {
|
||||||
if (val !== "") {
|
if (val !== "") {
|
||||||
@ -115,6 +127,7 @@ async function alias(setting, value, url, nick) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function get(setting) {
|
async function get(setting) {
|
||||||
|
consoleLog('[options.get] Getting value of '+setting)
|
||||||
var file = editJsonFile('/home/node/app/config/default.json')
|
var file = editJsonFile('/home/node/app/config/default.json')
|
||||||
console.log(file.get(setting));
|
console.log(file.get(setting));
|
||||||
sendUpstream(file.get(setting))
|
sendUpstream(file.get(setting))
|
||||||
|
@ -15,15 +15,23 @@ const timer = ms => new Promise(res => setTimeout(res, ms))
|
|||||||
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
||||||
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
|
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
|
||||||
|
|
||||||
|
function consoleLog(log) {
|
||||||
|
if (config.misc.logging === "true") {
|
||||||
|
console.log(log)
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function sendUpstream(content) {
|
async function sendUpstream(content) {
|
||||||
var output = content.join("\n")
|
var output = content.join("\n")
|
||||||
|
consoleLog('[twitter] All done.')
|
||||||
parentPort.postMessage(output);
|
parentPort.postMessage(output);
|
||||||
process.exit()
|
process.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
function errorMessage(error, code, extra) {
|
function errorMessage(error, code, extra) {
|
||||||
console.log(error.code)
|
consoleLog('[twitter.errorMessage] '+error.code)
|
||||||
if (code == "404") {
|
if (code == "404") {
|
||||||
var error = errorMsg+" 404: " + extra + " not found"
|
var error = errorMsg+" 404: " + extra + " not found"
|
||||||
} else if (error.code == "ECONNREFUSED") {
|
} else if (error.code == "ECONNREFUSED") {
|
||||||
@ -40,8 +48,10 @@ function errorMessage(error, code, extra) {
|
|||||||
|
|
||||||
async function fetchFeed(feedURL, n) {
|
async function fetchFeed(feedURL, n) {
|
||||||
var content = [];
|
var content = [];
|
||||||
|
consoleLog('[twitter.fetchFeed] fetching @'+feedURL)
|
||||||
|
|
||||||
if (feedURL.startsWith('@') == true) {
|
if (feedURL.startsWith('@') == true) {
|
||||||
|
consoleLog('[twitter.fetchFeed] User passed @ in input, removing')
|
||||||
var feedURL = feedURL.substring(1,feedURL.length);
|
var feedURL = feedURL.substring(1,feedURL.length);
|
||||||
}
|
}
|
||||||
var randomNitter = config.twitter.nitter_instances[Math.floor(Math.random() * config.twitter.nitter_instances.length)];
|
var randomNitter = config.twitter.nitter_instances[Math.floor(Math.random() * config.twitter.nitter_instances.length)];
|
||||||
|
Loading…
Reference in New Issue
Block a user