diff --git a/index.js b/index.js index 4724c5a..d7dcbfc 100644 --- a/index.js +++ b/index.js @@ -69,7 +69,7 @@ const runList = async (listData, listID, channel) => { break; } - clients[0].say(Config.Username, `Chunk ${Number(i) + 1} of ${listID} executed successfully on channel ${channel}`); + say(Config.Username, `Chunk ${Number(i) + 1} of ${listID} executed successfully on channel ${channel}`); await sleep(Config.DelayPerChunk); } } else { @@ -102,6 +102,10 @@ const getConnection = () => { return readyClients[++lastIndex % readyClients.length]; }; +const say = (channel, message) => { + getConnection().say(channel, message); +}; + const pnslWebSocket = new WS('wss://bot.tetyys.com/api/wss', [], {headers: {Authorization: `Bearer ${Config.PNSLToken}`}}); pnslWebSocket.on('open', () => { @@ -168,26 +172,26 @@ pnslWebSocket.on('message', async (data) => { if (command === 'ping') { const channel = args[0]; - return clients[0].say(channel || channelName, `${clients.filter((i) => i.ready).length} Clients from total of ${clients.length} are operational`); + return say(channel || channelName, `${clients.filter((i) => i.ready).length} Clients from total of ${clients.length} are operational`); } if (command === 'runlist') { const listID = args[0]; const channel = args[1]; - if (!listID) return clients[0].say(Config.Username, 'No list ID provided!'); + if (!listID) return say(Config.Username, 'No list ID provided!'); try { if (channel) { const mods = await clients[0].getMods(channel); - if (!mods.includes(Config.Username)) return clients[0].say(Config.Username, `I am not a moderator in channel ${channel}!`); + if (!mods.includes(Config.Username)) return say(Config.Username, `I am not a moderator in channel ${channel}!`); } const data = await fetchList(listID); await runList(data.listData, listID, channel || channelName); - clients[0].say(Config.Username, `List ${listID} executed successfully on channel ${channel || channelName}`); + say(Config.Username, `List ${listID} executed successfully on channel ${channel || channelName}`); } catch (error) { console.error(error); - return clients[0].say(Config.Username, `Error Occurred! ${error.message}`); + return say(Config.Username, `Error Occurred! ${error.message}`); } } });