-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (43 loc) · 1.54 KB
/
index.js
File metadata and controls
50 lines (43 loc) · 1.54 KB
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 DiscordRPC = require('discord-rpc'),
nodeSpotifyWebhelper = require('node-spotify-webhelper'),
spotify = new nodeSpotifyWebhelper.SpotifyWebHelper(),
config = require('./config.json');
const ClientId = config.clientId || "384286107036155904";
const imageKey = config.largeImageKey || "spotify";
const imageText = config.largeImageText || undefined;
const rpc = new DiscordRPC.Client({
transport: 'ipc'
});
const timeMode = config.time || 'overall';
var startTimestamp = new Date();
var songName = undefined;
async function updateActivity() {
if (!rpc) return;
if (startTimestamp && config.time === 'none') startTimestamp = undefined;
spotify.getStatus(function(err, res) {
if (err) return console.error(err);
if (res.track.track_resource && res.track.track_resource.name && res.track.track_resource.name != songName) {
if (config.time === 'song-time') {
startTimestamp = new Date(new Date() - (res.playing_position * 1000));
}
songName = res.track.track_resource.name;
rpc.setActivity({
details: `Playing ${res.track.track_resource.name}`,
state: `By ${res.track.artist_resource.name}`,
startTimestamp,
largeImageKey: imageKey,
largeImageText: imageText,
instance: false,
});
console.log(`[${new Date().toLocaleTimeString()}] Updated Rich Presence - ${res.track.track_resource.name}`)
}
})
}
rpc.on('ready', () => {
console.log(`Starting with clientId ${ClientId}`);
updateActivity();
setInterval(() => {
updateActivity();
}, 10e3);
});
rpc.login({ clientId: ClientId }).catch(console.error);