-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
50 lines (40 loc) · 1.36 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
const EventEmitter = require('events');
const DiscordIPC = require('./DiscordIPC.js');
const uuid = require('uuid/v4');
class DiscordRPC extends EventEmitter {
constructor({ clientID, debug }) {
super();
this.debug = debug;
this.discordIPC = new DiscordIPC(clientID);
this.discordIPC.on('open', () => {
if (this.debug)
console.log('[Discord IPC] Status: open');
});
this.discordIPC.on('close', (event) => {
if (this.debug)
console.log('[Discord IPC] Status: close', event);
});
this.discordIPC.on('error', (event) => {
if (this.debug)
console.log('[Discord IPC] Error', event);
});
this.discordIPC.on('message', (event) => {
switch (event.evt) {
case 'READY':
if (this.debug)
console.log('[Discord RPC] Status: ready');
this.emit('ready');
break;
default:
if (this.debug)
console.log('[Discord IPC] Message', event);
break;
}
});
this.discordIPC.connect();
}
send(cmd, args) {
this.discordIPC.send({ cmd, args, nonce: uuid() });
}
}
module.exports = DiscordRPC;