forked from alairon/SwitchRP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscordConnect.js
56 lines (49 loc) · 1.4 KB
/
discordConnect.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
/** discordConnect.js
* Functions used to update the user's status
* For info on creating application IDs, visit
* https://discordapp.com/developers/applications/
*/
// Converts a number type into a string, if necessary
function checkAppID(appID) {
let clientAppID = appID;
if (typeof (clientAppID) === 'number') {
clientAppID = clientAppID.toString();
}
return (clientAppID);
}
// Checks if the details field was set
function checkDetails(details) {
if (details.length === 0) {
return (false);
}
return (true);
}
// An object that holds clientAppID, details, and largeImageKey
const appPresence = {
clientAppID: checkAppID(process.argv[2]),
details: process.argv[3],
largeImageKey: process.argv[4],
};
// Configures the user status with information passed in from the user
const client = require('discord-rich-presence')(appPresence.clientAppID);
function updatePresenceInit() {
if (!checkDetails(appPresence.details)) {
// No details set
client.updatePresence({
largeImageKey: appPresence.largeImageKey,
});
} else {
// Details is set
client.updatePresence({
details: appPresence.details,
largeImageKey: appPresence.largeImageKey,
});
}
}
// Update presence
updatePresenceInit();
/* Process Functions */
// Uncaught Rejection, in case of Discord Timeouts
process.on('unhandledRejection', (reason) => {
console.log(reason.stack || reason);
});