Experimental PU ban support

This commit is contained in:
Leppunen 2021-08-23 17:26:48 +03:00
parent 47a621f498
commit a64d7a1d5b
2 changed files with 19 additions and 5 deletions

View File

@ -3,6 +3,7 @@
"Password": "",
"PNSLToken": "",
"IgnorePNSL": false,
"UseParallelUniverse": true,
"Users": [],
"Prefix": "!!",
"MaxConnections": 30,

View File

@ -1,5 +1,5 @@
const { extend: createGotClient } = require('got');
const { ConnectionError, SayError, TimeoutError, UserBanError, ChatClient } = require('dank-twitch-irc');
const { ConnectionError, SayError, JoinError, TimeoutError, UserBanError, ChatClient } = require('dank-twitch-irc');
const chalk = require('chalk');
const WS = require('ws');
const Config = require('./config.json');
@ -80,12 +80,17 @@ const runList = async (listData, listID, channel) => {
continue;
}
[, user, ...reason] = entry.split(' ');
promises.push(getConnection().ban(channel, user, reason.join(' ')));
if (Config.UseParallelUniverse === true) {
const rawBanCommand = `PRIVMSG ${channel} :.ban ${user} ${reason.join(' ')}`;
promises.push(getConnection().sendRaw(rawBanCommand));
} else {
promises.push(getConnection().ban(channel, user, reason.join(' ')));
}
}
await Promise.allSettled(promises);
say(Config.Username, `Chunk ${currentChunk}/${chunkCount} of ${listID} executed successfully on channel ${channel}`);
say(Config.Username, `${Config.UseParallelUniverse === true ? '[PU]' : ''} Chunk ${currentChunk}/${chunkCount} of ${listID} executed successfully on channel ${channel}`);
if (currentChunk === chunkCount) {
break;
@ -103,7 +108,12 @@ const runList = async (listData, listID, channel) => {
continue;
}
[, user, ...reason] = entry.split(' ');
promises.push(getConnection().ban(channel, user, reason.join(' ')));
if (Config.UseParallelUniverse === true) {
const rawBanCommand = `PRIVMSG ${channel} :.ban ${user} ${reason.join(' ')}`;
promises.push(getConnection().sendRaw(rawBanCommand));
} else {
promises.push(getConnection().ban(channel, user, reason.join(' ')));
}
}
await Promise.allSettled(promises);
@ -168,6 +178,9 @@ if (!Config.IgnorePNSL) {
if (error instanceof SayError) {
return;
}
if (error instanceof JoinError) {
return;
}
if (error instanceof UserBanError) {
return console.warn(`Failed to ban user ${error.username} from ${error.channelName}`);
}
@ -233,7 +246,7 @@ if (!Config.IgnorePNSL) {
const data = await fetchUrlList(listID);
await runList(data, listID, channel || channelName);
}
say(Config.Username, `List ${listID} executed successfully on channel ${channel || channelName}`);
say(Config.Username, `${Config.UseParallelUniverse === true ? '[PU]' : ''} List ${listID} executed successfully on channel ${channel || channelName}`);
} catch (e) {
console.error(e);
return say(Config.Username, `Error Occurred! ${e.message}`);