colour customisation + big bug fix

This commit is contained in:
hgw 2023-10-02 02:11:25 +00:00
parent b0a8a81491
commit d2d896667c
4 changed files with 56 additions and 21 deletions

9
bot.js
View File

@ -5,6 +5,9 @@ var readline = require('readline');
const { Worker } = require('worker_threads');
//var randomWords = require('better-random-words');
warningMsg = '['+config.colours.warning+'WARNING]'
errorMsg = '['+config.colours.error+'ERROR]'
var bot = new irc.Client(config.irc.server, config.irc.nickname, {
channels: config.irc.channels,
secure: config.irc.ssl,
@ -36,7 +39,8 @@ async function help(chan, sub) {
async function feed(chan, provfeed, n) {
if (provfeed === undefined) {
bot.say(chan, "No feed has been provided.")
bot.say(chan, errorMsg+" No feed has been provided.")
return;
}
if (n === undefined) {
var n = 5;
@ -55,7 +59,8 @@ async function feed(chan, provfeed, n) {
async function twitter(chan, provfeed, n) {
if (provfeed === undefined) {
bot.say(chan, "No account has been provided.")
bot.say(chan, errorMsg+" No account has been provided.")
return;
}
if (n === undefined) {
var n = 5;

View File

@ -10,6 +10,9 @@ const moment = require('moment');
const tz = require('moment-timezone');
const timer = ms => new Promise(res => setTimeout(res, ms))
warningMsg = '['+config.colours.warning+'WARNING]'
errorMsg = '['+config.colours.error+'ERROR]'
async function sendUpstream(content) {
var output = content.join("\n")
parentPort.postMessage(output);
@ -19,13 +22,13 @@ async function sendUpstream(content) {
function errorMessage(error, code, extra) {
console.log(error.code)
if (code == "404") {
var error = "[04ERROR] 404: " + extra + " not found"
var error = errorMsg+" 404: " + extra + " not found"
} else if (error.code == "ECONNREFUSED") {
var error = "[04ERROR] Connection Refused"
var error = errorMsg+" Connection Refused"
} else if (error.code == "ERR_UNESCAPED_CHARACTERS"){
var error = "[04ERROR] Unescaped Characters"
var error = errorMsg+" Unescaped Characters"
} else {
var error = "[04ERROR] Unknown error"
var error = errorMsg+" Unknown error"
}
parentPort.postMessage(error);
@ -45,10 +48,10 @@ async function fetchFeed(feedURL, n) {
}
if (n > newFeed.items.length) {
var n = newFeed.items.length;
content.push("[08WARNING] Your requested post amount exceeded the total available. Reverting to " + newFeed.items.length);
content.push(warningMsg+" Your requested post amount exceeded the total available. Reverting to " + newFeed.items.length);
} else if (n < 1) {
var n = 5
content.push("[08WARNING] You requested a number less than 1. Reverting to 5");
content.push(warningMsg+" You requested a number less than 1. Reverting to 5");
}
//for (let i = 0; i < newFeed.items.length; i++) {
for (let i = 0; i < n; i++) {
@ -71,10 +74,17 @@ async function fetchFeed(feedURL, n) {
var truncatedString = body.substring(0,config.feed.body_max_chars);
var body = truncatedString + "..."
}
console.log(data);
var string = "15[11" + date + "15] 08" + title + " " + body + " " + data.link;
var output = string;
content.push(output)
date = ''+config.colours.date_brackets+'['+config.colours.date+date+''+config.colours.date_brackets+'] '
title = ''+config.colours.title+title+' '
author = ''+config.colours.author+data.creator+' '
body = ''+config.colours.body+body+' '
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;
content.push(string)
}
sendUpstream(content);
}

View File

@ -10,6 +10,9 @@ const moment = require('moment');
const tz = require('moment-timezone');
const timer = ms => new Promise(res => setTimeout(res, ms))
warningMsg = '['+config.colours.warning+'WARNING]'
errorMsg = '['+config.colours.error+'ERROR]'
async function sendUpstream(content) {
var output = content.join("\n")
parentPort.postMessage(output);
@ -19,13 +22,13 @@ async function sendUpstream(content) {
function errorMessage(error, code, extra) {
console.log(error.code)
if (code == "404") {
var error = "[04ERROR] 404: " + extra + " not found"
var error = errorMsg+" 404: " + extra + " not found"
} else if (error.code == "ECONNREFUSED") {
var error = "[04ERROR] Connection Refused"
var error = errorMsg+" Connection Refused"
} else if (error.code == "ERR_UNESCAPED_CHARACTERS"){
var error = "[04ERROR] Unescaped Characters"
var error = errorMsg+" Unescaped Characters"
} else {
var error = "[04ERROR] Unknown error"
var error = errorMsg+" Unknown error"
}
parentPort.postMessage(error);
@ -52,10 +55,10 @@ async function fetchFeed(feedURL, n) {
if (n > newFeed.items.length) {
var n = newFeed.items.length;
content.push("[08WARNING] Your requested post amount exceeded the total available. Reverting to " + newFeed.items.length);
content.push(warningMsg+" Your requested post amount exceeded the total available. Reverting to " + newFeed.items.length);
} else if (n < 1) {
var n = 5
content.push("[08WARNING] You requested a number less than 1. Reverting to 5");
content.push(warningMsg+" You requested a number less than 1. Reverting to 5");
}
for (let i = 0; i < n; i++) {
@ -83,10 +86,17 @@ async function fetchFeed(feedURL, n) {
var truncatedString = body.substring(0,config.feed.body_max_chars);
var body = truncatedString + "..."
}
date = ''+config.colours.date_brackets+'['+config.colours.date+date+''+config.colours.date_brackets+'] '
title = ''+config.colours.title+title+' '
author = ''+config.colours.author+data.creator+' '
body = ''+config.colours.body+body+' '
link = ''+config.colours.link+data.link+' '
//console.log(data);
var string = "15[11" + date + "15] 08" + data.creator + " " + body + " " + data.link;
var output = string;
content.push(output)
//var string = "15[11" + date + "15] 08" + data.creator + " " + body + " " + data.link;
var string = date+author+body+link
content.push(string)
}
sendUpstream(content);
}

View File

@ -13,6 +13,16 @@
"floodprotection": "false",
"floodprotectiondelay": "0"
},
"colours": {
"date": "11",
"date_brackets": "15",
"title": "08",
"author": "08",
"body": "00",
"link": "02",
"warning": "08",
"error": "05"
},
"feed": {
"useragent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 13.4; rv:109.0) Gecko/20100101 Firefox/114.0",
"body_max_chars": "200",