From 9f37b4386115b0b69edaca08b2158e9cdb056538 Mon Sep 17 00:00:00 2001 From: Leppunen Date: Tue, 22 Dec 2020 10:04:26 +0200 Subject: [PATCH] Accept full links as lists and fix timeout check --- index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 85ed56e..4724c5a 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,14 @@ 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 WS = require('ws'); const Config = require('./config.json'); const clients = []; const banChunks = []; -const pingInterval = 60e3; +const pingInterval = 120e3; 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 pnslClient = createGotClient({ @@ -19,8 +19,9 @@ const pnslClient = createGotClient({ }, }); -const fetchList = async (listID) => { - if (!uuidRegex.test(listID)) { +const fetchList = async (list) => { + const listID = uuidRegex.exec(list)?.[0]; + if (!listID) { throw new Error('Invalid List ID!'); } @@ -145,9 +146,9 @@ pnslWebSocket.on('message', async (data) => { clients[i].connect(); return console.error(`Error in client ${i} -> ${error.name} || ${error.message}`); } - if (error instanceof PingTimeoutError) { + if (error instanceof TimeoutError) { 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); });