From 6c1479a8fbff2aff2c553c9e1fb18e8cea8728c3 Mon Sep 17 00:00:00 2001 From: Leppunen Date: Tue, 15 Dec 2020 15:36:38 +0200 Subject: [PATCH] Move limit configs to config.json --- config_dist.json | 5 ++++- index.js | 11 ++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config_dist.json b/config_dist.json index 52ff4c8..3b03cc4 100644 --- a/config_dist.json +++ b/config_dist.json @@ -2,5 +2,8 @@ "Username": "", "Password": "", "PNSLToken": "", - "AdminID": "" + "AdminID": "", + "MaxConnections": 30, + "MaxChunkSize": 2000, + "DelayPerChunk": 30e3 } \ No newline at end of file diff --git a/index.js b/index.js index 306b589..297d503 100644 --- a/index.js +++ b/index.js @@ -6,9 +6,6 @@ const Config = require('./config.json'); const clients = []; let banChunks = []; let lastIndex = 0; -const maxClients = 30; -const maxChunkSize = 5000; -const delayPerChunk = 30e3; 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 pnslClient = createGotClient({ @@ -42,7 +39,7 @@ const getConnection = () => { }; (() => { - [...Array(maxClients)].map((_, i) => { + [...Array(Config.MaxConnections)].map((_, i) => { clients[i] = createTwitchClient(); clients[i].connect(); clients[i].on('ready', async () => { @@ -76,16 +73,16 @@ const getConnection = () => { const banArr = body.split('\n'); - if (banArr.length > maxChunkSize) { + if (banArr.length > Config.MaxChunkSize) { while (banArr.length > 0) { - banChunks.push(banArr.splice(0, maxChunkSize)); + banChunks.push(banArr.splice(0, Config.MaxChunkSize)); } for (const chunk of banChunks) { for (const entry of chunk) { getConnection().privmsg(channel || msg.channelName, entry); } - await sleep(delayPerChunk); + await sleep(Config.DelayPerChunk); } banChunks = []; } else {