Accept full links as lists and fix timeout check

This commit is contained in:
Leppunen 2020-12-22 10:04:26 +02:00
parent 39c12f7d58
commit 9f37b43861

View file

@ -1,14 +1,14 @@
const {extend: createGotClient} = require('got'); const {extend: createGotClient} = require('got');
const {ConnectionError, SayError, PingTimeoutError, ChatClient} = require('dank-twitch-irc'); const {ConnectionError, SayError, TimeoutError, ChatClient} = require('dank-twitch-irc');
const chalk = require('chalk'); const chalk = require('chalk');
const WS = require('ws'); const WS = require('ws');
const Config = require('./config.json'); const Config = require('./config.json');
const clients = []; const clients = [];
const banChunks = []; const banChunks = [];
const pingInterval = 60e3; const pingInterval = 120e3;
let lastIndex = 0; let lastIndex = 0;
const uuidRegex = /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i; const uuidRegex = /[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}/i;
const msgRegex = /[\u034f\u2800\u{E0000}\u180e\ufeff\u2000-\u200d\u206D]/gu; const msgRegex = /[\u034f\u2800\u{E0000}\u180e\ufeff\u2000-\u200d\u206D]/gu;
const pnslClient = createGotClient({ const pnslClient = createGotClient({
@ -19,8 +19,9 @@ const pnslClient = createGotClient({
}, },
}); });
const fetchList = async (listID) => { const fetchList = async (list) => {
if (!uuidRegex.test(listID)) { const listID = uuidRegex.exec(list)?.[0];
if (!listID) {
throw new Error('Invalid List ID!'); throw new Error('Invalid List ID!');
} }
@ -145,9 +146,9 @@ pnslWebSocket.on('message', async (data) => {
clients[i].connect(); clients[i].connect();
return console.error(`Error in client ${i} -> ${error.name} || ${error.message}`); return console.error(`Error in client ${i} -> ${error.name} || ${error.message}`);
} }
if (error instanceof PingTimeoutError) { if (error instanceof TimeoutError) {
clients[i].connect(); clients[i].connect();
return console.error(`Ping Error in client ${i} -> ${error.name} || ${error.message}`); return console.error(`Timeout in client ${i} -> ${error.name} || ${error.message} | Trying to reconnect`);
} }
console.error(error); console.error(error);
}); });