-
Notifications
You must be signed in to change notification settings - Fork 3
/
twitch-urls.js
executable file
·78 lines (64 loc) · 1.87 KB
/
twitch-urls.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
#!/usr/bin/env node
const {GoogleSpreadsheet} = require('google-spreadsheet')
const {ChatClient} = require('dank-twitch-irc')
const moment = require('moment-timezone')
const SHEET_ID = process.env.SHEET_ID
const TAB_NAME = process.env.TAB_NAME
const SHEET_CREDS = require('./gs-creds.json')
const {doWithRetry, sleep} = require('./utils')
const ignoreDisplayNames = new Set([
'StreamElements',
'wokenet',
])
const interestingPrefixes = [
'www.youtube.com',
'youtu.be',
'www.facebook.com',
'www.instagram.com',
'www.periscope.tv',
'www.pscp.tv',
'www.twitch.tv',
'twitter.com/i/broadcasts',
]
const urlRe = /https?:\/\/[^ ]+/g
async function main() {
const doc = new GoogleSpreadsheet(SHEET_ID)
await doc.useServiceAccountAuth(SHEET_CREDS)
await doc.loadInfo()
const sheet = Object.values(doc.sheetsById).find(s => s.title === TAB_NAME)
await sheet.loadHeaderRow()
const client = new ChatClient()
client.on('ready', () => console.log('connected'))
client.on('close', err => {
if (err != null) {
console.error('disconnected due to error', error)
}
})
client.on('PRIVMSG', async msg => {
const {messageText, displayName} = msg
if (ignoreDisplayNames.has(displayName)) {
return
}
for (const match of messageText.matchAll(urlRe)) {
let url
try {
url = new URL(match)
} catch (err) {
continue
}
const urlStart = url.host + url.pathname
if (interestingPrefixes.some(p => urlStart.startsWith(p))) {
console.log(`[${displayName}] ${messageText}`)
const row = doWithRetry(() => sheet.addRow({
URL: match.toString(),
'Timestamp (CST)': moment().tz("America/Chicago").format('M/D/YY HH:mm:ss'),
Message: messageText,
'Display Name': displayName,
}))
}
}
})
client.connect()
client.join('woke')
}
main()