forked from nations/spoticord
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapp.js
More file actions
59 lines (48 loc) · 1.5 KB
/
app.js
File metadata and controls
59 lines (48 loc) · 1.5 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
51
52
53
54
55
56
57
58
59
const DiscordRPC = require('discord-rpc'),
{ LastFmNode } = require('lastfm'),
fs = require('fs'),
log = require("fancy-log");
if(fs.existsSync('keys.json')) {
fs.renameSync('keys.json', 'config.json');
log.info('Renamed keys.json to config.json');
}
if(!fs.existsSync('config.json')) {
fs.copyFileSync('config.example.json', 'config.json')
log.info('Created config.json. Please enter your username in the value of `lastFmUsername`.');
return;
}
const {
appClientID,
imageKeys,
rpcTransportType: transport,
lastFmKey,
lastFmUsername,
} = require('./config');
const rpc = new DiscordRPC.Client({ transport }),
clientId = appClientID,
lastFm = new LastFmNode({ api_key: lastFmKey, useragent: 'fmcord v1.0.0' });
if(!lastFmUsername) {
log.error("Your last.fm username isn't set! Please set it in your config.json file.");
process.exit(1);
}
const trackStream = lastFm.stream(lastFmUsername);
trackStream.on('nowPlaying', song => {
if(!song) return;
rpc.setActivity({
details: `🎵 ${song.name}`,
state: `👤 ${song.artist["#text"]}`,
largeImageKey: imageKeys.large,
smallImageKey: imageKeys.small,
smallImageText: `💿 ${song.album["#text"]}`,
instance: false,
});
log.info(`Updated song to: ${song.artist["#text"]} - ${song.name}`);
});
trackStream.on('error', error => {
log.error(error)
})
rpc.on('ready', () => {
log(`Connected to Discord! (${clientId})`);
trackStream.start();
});
rpc.login({ clientId }).catch(log.error);