-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtpp-botcheck.js
240 lines (205 loc) · 12.1 KB
/
tpp-botcheck.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// define configuration options
require('dotenv').config()
const args = process.argv.slice(2)
const fetch = require('node-fetch')
const tmi = require('tmi.js')
const fs = require('fs')
// create a client with our options
const client = new tmi.Client({
identity: { username: "justinfan1986", password: "kappa" },
channels: [ "twitchplayspokemon" ],
})
function addToList(name) {
if (/^\w+$/.test(name) && !name.startsWith("_") && !botList.includes(name)) botList.push(name)
}
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
}
function checkPayload(data) {
if (!data.ok) printMessage(`WARN ${data.url} returned Error ${data.status} ${data.statusText}`)
return data.text()
}
// ensure our token is valid
function validateToken(first) {
if (first) printMessage(`Validating OAuth token...`)
// https://dev.twitch.tv/docs/authentication/validate-tokens/
fetch(`https://id.twitch.tv/oauth2/validate`, { method: 'GET', headers: { 'Authorization': `OAuth ${process.env.TWITCH_OAUTH}` }})
.then(async data => {
if (data.ok) return await data.json()
else printMessage(`WARN during .validateToken() - ${data.status} ${data.statusText}`)
})
.then(data => {
if (data.login && first) {
if (data.expires_in > 0) printMessage(`OAuth token is valid and will expire on ${new Date(Date.now() + (data.expires_in * 1000))}`)
else printMessage(`OAuth token is valid and but Twitch did not provide an expiry date.`)
fetchFromTwitchInsights()
} else if (data.status == 401) {
printMessage(`OAuth token is invalid or has expired. Please create a new one and update env file.`)
setTimeout(process.exit, 1000)
}
})
.catch(err => printMessage(`ERROR during .validateToken() - ${err}`))
}
// build our bot list
const safeList = []
const notified = []
const botList = []
if (!args.includes("--ignore-safe")) {
fs.readFile("botcheck-safe.txt", 'utf8', (err, data) => {
if (err) throw err
data.split(/\r?\n/i).forEach(row => { if (row != "") safeList.push(row.toLowerCase().trim()) })
})
}
if (!args.includes("--ignore-marked")) {
fs.readFile("botcheck-marked.txt", 'utf8', (err, data) => {
if (err) throw err
data.split(/\r?\n/i).forEach(row => { if (row != "") notified.push(row.toLowerCase().trim()) })
})
}
function beginScan() {
printMessage(`There are ${numberWithCommas(botList.length)} names in the master bot list.`)
printMessage(`There are ${numberWithCommas(notified.length)} names in the marked list.`)
printMessage(`There are ${numberWithCommas(safeList.length)} names in the safe list.`)
queryTwitch()
setInterval(queryTwitch, 30000)
}
function fetchFromTwitchInsights() {
fetch(`https://api.twitchinsights.net/v1/bots/all`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'User-Agent': 'github.com/ravendwyr/tpp-scripts' } })
.then(data => data.json())
.then(data => {
data["bots"].forEach(row => {
const name = row[0].toLowerCase().trim()
addToList(name)
})
printMessage("Finished downloading from TwitchInsights.")
fetchFromGitHub()
})
.catch(err => printMessage(`Error while downloading TwitchInsights list -- ${err}`))
}
function fetchFromGitHub() {
Promise.all([
fetch('https://raw.githubusercontent.com/arrowgent/Twitchtv-Bots-List/main/list.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/arrowgent/Twitchtv-Bots-List/main/goodbot.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/paret0x/Twitch-Bot-Finder/main/botlist.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/paret0x/Twitch-Bot-Finder/main/whitelist.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/fake_scam_list.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/follower_bot_list.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/greylisted_bots.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/hate_troll_list_0_g.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/hate_troll_list_h_m.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/hate_troll_list_n_z.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/mad_tos_list.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/porn_bot_acc_list.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/security_ban_list.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/seller_advertising_list.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/spam_bot_list.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/streamsniper_list.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/viewer_bot_list.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/isdsdataarchive/twitch_ban_lists/main/whitelisted_bots.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/Even%20more%20bots').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/LATEST').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/SelfPromoBots').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/andagain').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/asd').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/botraid_list.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/bots%20part%202').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/bots2.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/bruh').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/bruhmoment').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/caleb').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/common-bots').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/couple_o_hosses').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/every_bot_ever').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/herewegoagain').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/idek').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/literally-every-lurkbot').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/luvserena').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/more-bots').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/new%20bots').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/newbots').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/new-hate-raids').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/nuh-uh').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/papa').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/script-kiddies-2-ban-hammer-boogaloo').then(checkPayload),
fetch('https://raw.githubusercontent.com/16-ATLAS-16/botlist/main/why_god').then(checkPayload),
fetch('https://raw.githubusercontent.com/Maouniel/temp/main/TwitchChatFilter/.bots.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/nugrunonly/banBot-v2/main/binarybouncer-main/banlist.txt').then(checkPayload),
fetch('https://raw.githubusercontent.com/Twitchmods/hateraid-master.txt/main/Hater%20Master.txt').then(checkPayload),
])
.then(data => {
// 'data' is an array and its .length is equivalent to the number number of queries in .all() above
data.forEach(names => {
names.split(/\r?\n/i).forEach(row => {
const name = row.toLowerCase().trim()
addToList(name)
})
})
printMessage("Finished downloading from GitHub.")
fetchFromFrankerFaceZ()
})
.catch(err => printMessage(`Error while downloading GitHub list -- ${err}`))
}
function fetchFromFrankerFaceZ() {
fetch(`https://api.frankerfacez.com/v1/badge/bot`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'User-Agent': 'github.com/ravendwyr/tpp-scripts' } })
.then(data => data.json())
.then(data => {
data["users"][2].forEach(row => {
const name = row.toLowerCase().trim()
addToList(name)
})
printMessage("Finished downloading from FrankerFaceZ.")
fetchFromPaauulli()
})
.catch(err => printMessage(`Error while downloading FrankerFaceZ's list -- ${err}`))
}
function fetchFromPaauulli() {
fetch(`https://api.paauulli.me/bot/bots`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'User-Agent': 'github.com/ravendwyr/tpp-scripts' } })
.then(data => data.json())
.then(data => {
data.forEach(row => {
const name = row.Name.toLowerCase().trim()
addToList(name)
})
printMessage("Finished downloading from Paauulli.")
beginScan()
})
.catch(err => printMessage(`Error while downloading Paauulli's list -- ${err}`))
}
// gather the goods
function queryTwitch(cursor) {
let pagination = ""
if (cursor) pagination = `&after=${cursor}`
fetch(`https://api.twitch.tv/helix/chat/chatters?moderator_id=44322184&broadcaster_id=56648155&first=1000${pagination}`, {
method: 'GET', headers: { 'Authorization': `Bearer ${process.env.TWITCH_OAUTH}`, 'Client-Id': process.env.TWITCH_CLIENTID },
})
.then(data => { if (data.ok) return data.json(); else printMessage(`Helix endpoint returned Error ${data.status} ${data.statusText}`)})
.then(data => {
if (!data) return
for (let i = 0; i < data.data.length; i++) {
const name = data.data[i].user_login
if (safeList.includes(name) || notified.includes(name)) continue
else if (botList.includes(name)) {
printMessage(`"${name}" is in the master bot list. Please verify before marking.`)
notified.push(name)
}
}
if (data.pagination.cursor) setTimeout(() => queryTwitch(data.pagination.cursor), 100)
})
.catch(err => printMessage(`Error while downloading chatter list -- ${err}`))
}
// our pretty printer
function printMessage(message) {
console.log(new Date().toLocaleTimeString(), message)
}
// event handlers
function onMessageHandler(channel, userdata, message, self) {
const name = userdata.username
if (safeList.includes(name)) return
else if (notified.includes(name)) printMessage(`"${name}" is marked as a bot but they just sent a message.`)
else if (botList.includes(name)) printMessage(`"${name}" is in the master bot list but they just sent a message.`)
}
// engage
validateToken(true)
setInterval(validateToken, 3600000, false)
client.on('message', onMessageHandler)
client.connect().catch(err => printMessage(`Unable to connect to chat. ${err}`))