-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 1005 Bytes
/
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
require('dotenv').config()
const checkIfTrackIsNew = require('./lib/checkIfTrackIsNew')
const fetchLastPlayedTrack = require('./lib/fetchLastPlayedTrack')
// Parse args
const commander = require('commander')
commander
.version('1.0.0')
.usage('[options] <username>')
// eslint-disable-next-line quotes
.option('-q, --quiet', "Don't send message to Slack")
.parse(process.argv)
if (!commander.args.length) {
commander.help()
}
const sendMessageToSlack = require('./lib/sendMessageToSlack')
const { fetchDelay } = require('./config/app').lastfm
const app = async username => {
const lastPlayedTrack = await fetchLastPlayedTrack(username)
const track = await checkIfTrackIsNew(lastPlayedTrack)
if (track) {
if (!commander.quiet) {
sendMessageToSlack(
track.url,
track.name,
track.artist['#text'],
track.image['3']['#text'],
track.album['#text']
)
}
}
setTimeout(() => app(username), fetchDelay)
}
app(commander.args[0])