-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
127 lines (96 loc) · 2.63 KB
/
main.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* eslint-disable no-console */
const DiscordRPC = require('discord-rpc');
const fs = require('fs');
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 1234 });
const ClientId = "391369077991538698";
var ltext = "Kantai Collection"
var details = "Loading Integration..."
var state = ["Rank data not loaded"]
var lkey = "kc_logo_512x512"
var last_time = 0
var skey = "idle_img"
var stext = "Idle"
var ts = -1;
var count = 0;
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
var x = JSON.parse(message);
console.log(x);
if (x["top"] != "none") {
details = x["top"];
}
if (x["bot"] != "none") {
state = x["bot"];
}
if (x["large"] != "none") {
ltext = x["large"];
}
if (x["small"] != "none") {
stext = x["small"];
}
if (x["timestamp"] != "none") {
if (parseInt(x["timestamp"]) > 0) {
ts = parseInt(x["timestamp"]);
} else {
ts = -1;
}
}
if (process.argv.indexOf("-v") > -1) {
console.log('received: %s', message);
}
last_time = Date.now(); //get timestamp
skey = "active_img";
//stext = "Currently Playing!";
});
});
function getDuration() {
}
DiscordRPC.register(ClientId);
const rpc = new DiscordRPC.Client({
transport: 'ipc'
});
async function setActivity() {
if (!rpc)
return;
var activity = {
details: details,
largeImageKey: lkey,
largeImageText: ltext,
instance: false
}
if (state[count%state.length] != "none") {
activity.state = state[count%state.length];
} else{
while (state[count%state.length] == "none") {
count = (count+1)%state.length;
}
activity.state = state[count%state.length];
}
count = (count+1)%state.length;
activity.state = activity.state.replace(":military_medal:","First Class Medals: ");
//check if idle
//1000 = second
//60000 = minute
//300000 = 5 mins
var elapsed = Date.now() - last_time;
if (elapsed > 300000) {
//idle
skey = "idle_img";
stext = "Idle for " + Math.floor(elapsed/60000) + " minutes";
}
if (ts > 0) {
// i dont know why i have to divide by 1000, but i do otherwise it sends in milliseconds or something
activity.startTimestamp = ts/1000.0;
}
activity.smallImageKey = skey;
activity.smallImageText = stext;
rpc.setActivity(activity);
}
rpc.on('ready', () => {
setActivity();
setInterval(() => {
setActivity();
}, 15e3);
});
rpc.login(ClientId).catch(console.error);