-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
executable file
·173 lines (162 loc) · 6.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
require("dotenv").config({ path: "./auth.env" });
const signale_1 = require("signale");
const twitch_js_1 = __importDefault(require("twitch-js"));
const FS = __importStar(require("fs"));
const sleep = async (waitTimeInMs) => new Promise((resolve) => setTimeout(resolve, waitTimeInMs));
class TwitchMassBan {
constructor() {
this._self = this;
this.Logger = new signale_1.Signale({
interactive: false,
secrets: [
process.env.TWITCH_CLID,
process.env.TWITCH_TOKEN,
process.env.TWITCH_REFRESH,
],
});
this.Counters = {
total: {
count: 0,
log: new signale_1.Signale({ interactive: true, scope: "Total" }),
},
channel: {
count: 0,
log: new signale_1.Signale({ interactive: true, scope: "Channels" }),
},
};
this.options = {
clientId: process.env.TWITCH_CLID,
token: process.env.TWITCH_TOKEN,
username: process.env.TWITCH_USERNAME,
log: { destination: "./twitchjs.log" },
};
this.Twitch = new twitch_js_1.default({
token: this.options.token,
username: this.options.username,
clientId: this.options.clientId,
log: this.options.log,
});
this.flags = {
channel: "",
list: "",
};
this.readFlags()
.then(() => {
this.Logger.success("Read command line flags!");
this.Logger.pending("Connecting to Twitch Chat...");
this.Twitch.chat.connect().then(() => {
this.Logger.success("Connected to Twitch!");
this.Logger.disable();
this.Logger.time("timer");
this.Logger.enable();
this.process();
this.Logger.disable();
let timer = this.Logger.timeEnd("timer");
this.Logger.enable();
this.Logger.complete(`Done. Took ${timer.span}ms`);
this.resetCounters();
this.process(true);
process.exit();
});
})
.catch((e) => {
this.Logger.error("Missing required flags. -c channel -l listOfUsernames");
});
}
resetCounters() {
this.Counters.total.count = 0;
this.Counters.channel.count = 0;
}
getOptions() {
return this.options;
}
async readFlags() {
process.argv.forEach((value, index, array) => {
switch (value) {
case "-c":
this.flags.channel = array[index + 1];
case "-l":
this.flags.list = array[index + 1];
}
}, this._self);
}
getFlags() {
return this.flags;
}
getChannelFlag() {
return this.flags.channel;
}
getListFlag() {
return this.flags.list;
}
parseListFlag() {
return FS.readFileSync(this.getListFlag(), "utf8").split("\n");
}
parseChannelFlag() {
let a = this.getChannelFlag().split(",");
if (a[a.length - 1] == "")
delete a[a.length - 1];
return a;
}
process(undo = false) {
let list = this.parseListFlag();
let channels = this.parseChannelFlag();
let prefix = undo ? "Unbanning..." : "Banning...";
channels.forEach((channel) => {
list.forEach((user) => {
sleep("300").then(() => {
undo
? this.Twitch.chat.unban(channel, user)
: this.Twitch.chat.ban(channel, user);
});
this.Counters.total.count++;
this.Counters.total.log.pending(`${prefix} ${this.Counters.total.count}`);
}, this._self);
this.Counters.channel.count++;
this.Counters.channel.log.pending(`${prefix} ${this.Counters.channel.count}`);
}, this._self);
}
}
new TwitchMassBan();
/* Compilation Errors
node_modules/twitch-js/types/index.d.ts:1541:26 - error TS2304: Cannot find name 'RequestInit'.
1541 type FetchOptions = Omit<RequestInit, "headers"> & SearchOption & HeaderOption;
~~~~~~~~~~~
node_modules/twitch-js/types/index.d.ts:1634:84 - error TS2304: Cannot find name 'Response'.
1634 initialize(newOptions?: Partial<ApiOptions>): Promise<void | ApiRootResponse | Response>;
~~~~~~~~
node_modules/twitch-js/types/index.d.ts:1660:73 - error TS2304: Cannot find name 'Response'.
1660 get<T = any>(endpoint?: string, options?: ApiFetchOptions): Promise<Response | T>;
~~~~~~~~
node_modules/twitch-js/types/index.d.ts:1664:73 - error TS2304: Cannot find name 'Response'.
1664 post<T = any>(endpoint: string, options?: ApiFetchOptions): Promise<Response | T>;
~~~~~~~~
node_modules/twitch-js/types/index.d.ts:1668:72 - error TS2304: Cannot find name 'Response'.
1668 put<T = any>(endpoint: string, options?: ApiFetchOptions): Promise<Response | T>;
~~~~~~~~
Found 5 errors.
*/