-
Notifications
You must be signed in to change notification settings - Fork 1
/
discordIntegration.js
154 lines (126 loc) · 3.78 KB
/
discordIntegration.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
let electron = require("electron")
let discord = electron.remote.require("discord-rpc")
let clientId = "620780964494442500"
// dynamyc's section
let currentRawMode = "easy"
let currentMode = "Easy"
let currentScore = "0"
let username = null
let preUsername = document.querySelector("input#loginUsername").value
if (preUsername == "") {
username = "null"
} else {
username = preUsername
}
// Sleeping function (needed for leaving things to initialize properly)
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
const fs = require('fs');
const clientID = JSON.parse(fs.readFileSync(__dirname + "/scripts/electron/discordID.json", "utf-8")).clientId
let path = require("path")
discord.register(clientId)
const rpc = new discord.Client({
transport: "ipc"
})
rpc.login({
clientId: clientId
})
//Updating the RPC on certain stuff
//WARNING: Really fucking spaghetti
window.addEventListener("g4statechange", (e) => {
let activityData
let modeAlias = {
easy: "Easy",
normal: "Normal",
hard: "Hard",
hell: "Hell",
hades: "Hades",
denise: "Chaos",
reverse: "Reverse",
nox: "Nox",
polar: "Polar",
shook: "Shook",
custom: "Custom"
}
currentMode = modeAlias[e.detail.mode]
currentScore = e.detail.levelIndex
currentRawMode = [e.detail.mode]
if(username != "null") {
activityData = {
details: "Playing on: " + currentMode,
state: "Score: " + currentScore,
largeImageKey: "g4" + currentRawMode,
largeImageText: "Currently playing as " + username + "!",
smallImageKey: "g4",
instance: false
}
}else{
activityData = {
details: "Playing on: " + currentMode,
state: "Score: " + currentScore,
largeImageKey: "g4" + currentRawMode,
largeImageText: "Not logged in yet.",
smallImageKey: "g4",
instance: false
}
}
rpc.setActivity(activityData)
})
window.addEventListener("g4login", (e) => {
//Update username
preUsername = e.detail.username
if (preUsername == "") {
username = "null"
} else {
username = preUsername
}
let activityData = {
details: "Playing on: " + currentMode,
state: "Score: " + currentScore,
largeImageKey: "g4" + currentRawMode,
largeImageText: "Currently playing as " + username + "!",
smallImageKey: "g4",
instance: false
}
rpc.setActivity(activityData)
})
window.addEventListener("g4logout", (e) => {
// Update username
username = "null"
let activityData = {
details: "Playing on: " + currentMode,
state: "Score: " + currentScore,
largeImageKey: "g4" + currentRawMode,
largeImageText: "Not logged in yet.",
smallImageKey: "g4",
instance: false
}
rpc.setActivity(activityData)
})
// END
// OF
// THIS
// SHITTY
// PART
function setRPC() {
// Random strings while loading (state inside the RPC)
let rpcLoadStrings = JSON.parse(fs.readFileSync(__dirname + "/scripts/electron/discordRPCLoadStrings.json", "utf-8")).loadStrings
let rpcLoadRNDNMBR = Math.floor(Math.random()*rpcLoadStrings.length);
let activityData = {
details: "Loading...",
state: rpcLoadStrings[rpcLoadRNDNMBR],
largeImageKey: "g4_logo",
largeImageText: "Logging in...",
smallImageKey: "g4",
instance: false
}
rpc.setActivity(activityData)
}
sleep(300) // Sleep for 300ms - Needed to leave time for everything to initialize everything properly
setRPC() // Starting up RPC