-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
89 lines (63 loc) · 2.2 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
// WEBSOCKET CONNECTION
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const fs = require('fs');
const data = "This is the new content of the file.";
const WebSocket = require('ws');
var CONFIG = require('./config.json');
var kickUser = CONFIG.kick;
var twitchUser = CONFIG.twitch;
function saveLog (platform, chat) {
var file = 'public/tmp/' + platform + '.log';
var file2 = 'public/tmp/' + 'chat.log';
var text = '[' + platform + '] ' + chat + '\r\n';
fs.appendFile(file, text, function (err) {
if (err) return console.log(err);
});
fs.appendFile(file2, text, function (err) {
if (err) return console.log(err);
});
}
//KICK CONNECTION
const kickWS = new WebSocket(
"wss://ws-us2.pusher.com/app/eb1d5f283081a78b932c?protocol=7&client=js&version=7.6.0&flash=false"
);
console.log("RandomZ Chat Linker")
kickWS.on("message", (req) => {
const data = JSON.parse(req);
//console.log(data.data.toString());
if (data.event == "pusher:connection_established"){
saveLog("SERVER", "KICK SCRIPT WROKING")
console.log("connection established to KickAPI!");
kickWS.send(
JSON.stringify({
event: "pusher:subscribe",
data: { auth: "", channel: kickUser },
})
);
}
if (data.event == "App\\Events\\ChatMessageEvent") {
const msgData = JSON.parse(data.data);
//console.log(msgData);
//WHAT I SEE
console.log("[KICK]", msgData.sender.username, ": " ,msgData.content);
saveLog("KICK", msgData.sender.username + ": " + msgData.content)
//fs.writeFileSync('/tmp/chat', "[KICK]", msgData.sender.username, ": " ,msgData.content);
}
});
//TWITCH
const tmi = require('tmi.js');
const TwitchClient = new tmi.Client({
connection: {
secure: true,
reconnect: true
},
channels: [ twitchUser ]
});
TwitchClient.connect();
saveLog("SERVER", "TWITCH SCRIPT WORKING")
console.log('TWITCH API CONNECTED')
TwitchClient.on('message', (channel, tags, message, self) => {
console.log("[TWITCH]", `${tags['display-name']}: ${message}`);
saveLog("TWITCH", `${tags['display-name']}: ${message}`)
});