-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkick-chat-capture.js
77 lines (75 loc) · 2.14 KB
/
kick-chat-capture.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
// only tested on site in devtools console
// i can imagine CORS not allowing it anywhere else
// based on what i had to do to get yt-dl working for it
// got CORS error after 2 days of chats from capturing one user's chat
// watch list:
// log[log.length-1].content
// cursor_preview
// log
// JSON.stringify(log)
var _break = false;
var _continue = false;
var interval = 200;
var timeout = 5000;
if (!_continue) {
var cursor_preview;
var log = [];
}
var username = '';
const endpoint = 'https://kick.com/api/v2/channels/';
const delay = ms => new Promise(res => setTimeout(res, ms));
(async function() {
var user = await (await fetch(endpoint+username)).json();
var start_time = new Date(user.chatroom.created_at);
console.log(user);
var current_time = new Date();
var cursor = _continue ? cursor_preview : current_time;
if (!_continue) {
var latest_msg = (await (await fetch(endpoint+user.chatroom.chatable_id+'/messages')).json());
if (latest_msg.data.messages.length > 0) {
cursor = new Date(latest_msg.data.messages[latest_msg.data.messages.length-1].created_at);
console.log(cursor);
latest_msg.data.messages.forEach(
msg => {
console.log(msg);
if (!log.find(x => x.id === msg.id))
log.push(msg);
}
);
console.log(latest_msg);
}
}
for (; cursor > start_time;) {
if (_break)
return;
cursor_preview = cursor;
try {
var obj = (await (
await fetch('https://kick.com/api/v2/channels/'+
user.chatroom.chatable_id+'/messages?start_time='+
cursor.toISOString())).json());
if (obj.status.code === 200)
{
if (obj.data.messages.length > 0)
{
console.log(cursor.toISOString()+':');
obj.data.messages.forEach(
msg => {
console.log(msg);
if (!log.find(x => x.id === msg.id))
log.push(msg); else console.warn('dupe msg');
}
);
}
}
else
console.error(obj);
await delay(interval);
cursor = new Date(cursor.getTime() - 60000)
} catch {
//console.error('rate limited??!?!! >:( '+obj.status.code);
await delay(timeout);
}
}
console.log('done');
})();