-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathserver.js
48 lines (42 loc) · 1.15 KB
/
server.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
const version = "0.3.0";
const discord = require('./Server/presence');
const WebSocket = require('ws');
process.on('uncaughtException', function(e) {
console.log('Uncaught Exception...');
console.log(e.stack);
setTimeout(function(){
process.exit(99);
}, 10000);
});
console.log("Starting", version);
const wss = new WebSocket.Server({
port: 6969
});
wss.on('connection', function connection(ws) {
console.log('Connected');
ws.on('message', function incoming(data) {
data = JSON.parse(data);
console.log('Recived', data);
if(typeof data.action !== 'undefined'){
switch (data.action) {
case 'disconnect':
discord.disconnect();
break;
case 'party':
data.listener.forEach((el) => {
discord.connect(el.clientId, el.extId);
});
break;
case 'reply':
discord.reply(data.user, data.clientId, data.response);
break;
}
}else{
discord.send(data.clientId, data.presence, data.extId);
}
});
ws.send(JSON.stringify({version: version}));
discord.init(ws);
});
console.log('WebSocket created');
process.stdin.resume();