-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
64 lines (53 loc) · 1.78 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
console.log("Launching KickBot Chat Connection...");
// WS - websocker opened to read chat messages.
import WebSocket from "ws";
//Kick.com channels to join and monitor. Array of values.
//To get a channel ID, load a pop-up chat of the channel you wish to monitor.
//Check that request labeled `101` and use that channel number listed there.
const chatroomList = [4598];
chatroomList.forEach((chatroomNumber) => {
// Open websocket to each streamer.
// Pusher is the service used for chatting.
const chat = new WebSocket(
"wss://ws-us2.pusher.com/app/eb1d5f283081a78b932c?protocol=7&client=js&version=7.6.0&flash=false"
);
chat.on("open", function open() {
chat.send(
JSON.stringify({
event: "pusher:subscribe",
data: { auth: "", channel: `chatrooms.${chatroomNumber}.v2` },
})
);
console.log(
"\x1b[33m%s\x1b[0m",
"Connected to Kick.com Streamer Chat: " + chatroomNumber
);
});
chat.on("error", console.error);
chat.on("close", function close() {
console.log("Connection closed for chatroom: " + chatroomNumber);
});
chat.on("message", function message(data) {
try {
// Order to get things.
// decode message to get components needed.
const dataString = data.toString();
//console.log(JSON.parse(dataString));
const jsonData = JSON.parse(dataString);
//console.log(jsonData.data);
const jsonDataSub = JSON.parse(jsonData.data);
// Log the message in console for tracker purposes.
console.log(
new Date().toLocaleTimeString() +
" - " +
jsonDataSub.chatroom_id +
" - " +
jsonDataSub.sender.username +
" - " +
jsonDataSub.content
);
} catch (error) {
//console.log(error);
}
});
});