colour customisation + big bug fix
This commit is contained in:
parent
b0a8a81491
commit
d2d896667c
9
bot.js
9
bot.js
@ -5,6 +5,9 @@ var readline = require('readline');
|
|||||||
const { Worker } = require('worker_threads');
|
const { Worker } = require('worker_threads');
|
||||||
//var randomWords = require('better-random-words');
|
//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, {
|
var bot = new irc.Client(config.irc.server, config.irc.nickname, {
|
||||||
channels: config.irc.channels,
|
channels: config.irc.channels,
|
||||||
secure: config.irc.ssl,
|
secure: config.irc.ssl,
|
||||||
@ -36,7 +39,8 @@ async function help(chan, sub) {
|
|||||||
|
|
||||||
async function feed(chan, provfeed, n) {
|
async function feed(chan, provfeed, n) {
|
||||||
if (provfeed === undefined) {
|
if (provfeed === undefined) {
|
||||||
bot.say(chan, "No feed has been provided.")
|
bot.say(chan, errorMsg+" No feed has been provided.")
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (n === undefined) {
|
if (n === undefined) {
|
||||||
var n = 5;
|
var n = 5;
|
||||||
@ -55,7 +59,8 @@ async function feed(chan, provfeed, n) {
|
|||||||
|
|
||||||
async function twitter(chan, provfeed, n) {
|
async function twitter(chan, provfeed, n) {
|
||||||
if (provfeed === undefined) {
|
if (provfeed === undefined) {
|
||||||
bot.say(chan, "No account has been provided.")
|
bot.say(chan, errorMsg+" No account has been provided.")
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (n === undefined) {
|
if (n === undefined) {
|
||||||
var n = 5;
|
var n = 5;
|
||||||
|
@ -10,6 +10,9 @@ const moment = require('moment');
|
|||||||
const tz = require('moment-timezone');
|
const tz = require('moment-timezone');
|
||||||
const timer = ms => new Promise(res => setTimeout(res, ms))
|
const timer = ms => new Promise(res => setTimeout(res, ms))
|
||||||
|
|
||||||
|
warningMsg = '['+config.colours.warning+'WARNING]'
|
||||||
|
errorMsg = '['+config.colours.error+'ERROR]'
|
||||||
|
|
||||||
async function sendUpstream(content) {
|
async function sendUpstream(content) {
|
||||||
var output = content.join("\n")
|
var output = content.join("\n")
|
||||||
parentPort.postMessage(output);
|
parentPort.postMessage(output);
|
||||||
@ -19,13 +22,13 @@ async function sendUpstream(content) {
|
|||||||
function errorMessage(error, code, extra) {
|
function errorMessage(error, code, extra) {
|
||||||
console.log(error.code)
|
console.log(error.code)
|
||||||
if (code == "404") {
|
if (code == "404") {
|
||||||
var error = "[04ERROR] 404: " + extra + " not found"
|
var error = errorMsg+" 404: " + extra + " not found"
|
||||||
} else if (error.code == "ECONNREFUSED") {
|
} else if (error.code == "ECONNREFUSED") {
|
||||||
var error = "[04ERROR] Connection Refused"
|
var error = errorMsg+" Connection Refused"
|
||||||
} else if (error.code == "ERR_UNESCAPED_CHARACTERS"){
|
} else if (error.code == "ERR_UNESCAPED_CHARACTERS"){
|
||||||
var error = "[04ERROR] Unescaped Characters"
|
var error = errorMsg+" Unescaped Characters"
|
||||||
} else {
|
} else {
|
||||||
var error = "[04ERROR] Unknown error"
|
var error = errorMsg+" Unknown error"
|
||||||
}
|
}
|
||||||
|
|
||||||
parentPort.postMessage(error);
|
parentPort.postMessage(error);
|
||||||
@ -45,10 +48,10 @@ async function fetchFeed(feedURL, n) {
|
|||||||
}
|
}
|
||||||
if (n > newFeed.items.length) {
|
if (n > newFeed.items.length) {
|
||||||
var 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) {
|
} else if (n < 1) {
|
||||||
var n = 5
|
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 < newFeed.items.length; i++) {
|
||||||
for (let i = 0; i < n; 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 truncatedString = body.substring(0,config.feed.body_max_chars);
|
||||||
var body = truncatedString + "..."
|
var body = truncatedString + "..."
|
||||||
}
|
}
|
||||||
console.log(data);
|
|
||||||
var string = "15[11" + date + "15] 08" + title + " " + body + " " + data.link;
|
date = ''+config.colours.date_brackets+'['+config.colours.date+date+''+config.colours.date_brackets+'] '
|
||||||
var output = string;
|
title = ''+config.colours.title+title+' '
|
||||||
content.push(output)
|
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);
|
sendUpstream(content);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,9 @@ const moment = require('moment');
|
|||||||
const tz = require('moment-timezone');
|
const tz = require('moment-timezone');
|
||||||
const timer = ms => new Promise(res => setTimeout(res, ms))
|
const timer = ms => new Promise(res => setTimeout(res, ms))
|
||||||
|
|
||||||
|
warningMsg = '['+config.colours.warning+'WARNING]'
|
||||||
|
errorMsg = '['+config.colours.error+'ERROR]'
|
||||||
|
|
||||||
async function sendUpstream(content) {
|
async function sendUpstream(content) {
|
||||||
var output = content.join("\n")
|
var output = content.join("\n")
|
||||||
parentPort.postMessage(output);
|
parentPort.postMessage(output);
|
||||||
@ -19,13 +22,13 @@ async function sendUpstream(content) {
|
|||||||
function errorMessage(error, code, extra) {
|
function errorMessage(error, code, extra) {
|
||||||
console.log(error.code)
|
console.log(error.code)
|
||||||
if (code == "404") {
|
if (code == "404") {
|
||||||
var error = "[04ERROR] 404: " + extra + " not found"
|
var error = errorMsg+" 404: " + extra + " not found"
|
||||||
} else if (error.code == "ECONNREFUSED") {
|
} else if (error.code == "ECONNREFUSED") {
|
||||||
var error = "[04ERROR] Connection Refused"
|
var error = errorMsg+" Connection Refused"
|
||||||
} else if (error.code == "ERR_UNESCAPED_CHARACTERS"){
|
} else if (error.code == "ERR_UNESCAPED_CHARACTERS"){
|
||||||
var error = "[04ERROR] Unescaped Characters"
|
var error = errorMsg+" Unescaped Characters"
|
||||||
} else {
|
} else {
|
||||||
var error = "[04ERROR] Unknown error"
|
var error = errorMsg+" Unknown error"
|
||||||
}
|
}
|
||||||
|
|
||||||
parentPort.postMessage(error);
|
parentPort.postMessage(error);
|
||||||
@ -52,10 +55,10 @@ async function fetchFeed(feedURL, n) {
|
|||||||
|
|
||||||
if (n > newFeed.items.length) {
|
if (n > newFeed.items.length) {
|
||||||
var 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) {
|
} else if (n < 1) {
|
||||||
var n = 5
|
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++) {
|
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 truncatedString = body.substring(0,config.feed.body_max_chars);
|
||||||
var body = truncatedString + "..."
|
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);
|
//console.log(data);
|
||||||
var string = "15[11" + date + "15] 08" + data.creator + " " + body + " " + data.link;
|
//var string = "15[11" + date + "15] 08" + data.creator + " " + body + " " + data.link;
|
||||||
var output = string;
|
var string = date+author+body+link
|
||||||
content.push(output)
|
content.push(string)
|
||||||
}
|
}
|
||||||
sendUpstream(content);
|
sendUpstream(content);
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,16 @@
|
|||||||
"floodprotection": "false",
|
"floodprotection": "false",
|
||||||
"floodprotectiondelay": "0"
|
"floodprotectiondelay": "0"
|
||||||
},
|
},
|
||||||
|
"colours": {
|
||||||
|
"date": "11",
|
||||||
|
"date_brackets": "15",
|
||||||
|
"title": "08",
|
||||||
|
"author": "08",
|
||||||
|
"body": "00",
|
||||||
|
"link": "02",
|
||||||
|
"warning": "08",
|
||||||
|
"error": "05"
|
||||||
|
},
|
||||||
"feed": {
|
"feed": {
|
||||||
"useragent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 13.4; rv:109.0) Gecko/20100101 Firefox/114.0",
|
"useragent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 13.4; rv:109.0) Gecko/20100101 Firefox/114.0",
|
||||||
"body_max_chars": "200",
|
"body_max_chars": "200",
|
||||||
|
Loading…
Reference in New Issue
Block a user