-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
58 lines (47 loc) · 1.03 KB
/
main.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
57
58
const electron = require('electron');
const request = require('request');
const playback = require('playback');
const app = electron.app;
const token = process.env.SLACK_API_TOKEN;
const sendToSlack = (message) => {
request({
url: 'https://slack.com/api/users.profile.set',
method: 'POST',
form: {
token,
profile: JSON.stringify({
status_text: message,
status_emoji: ':musical_note:',
}),
},
}, (error, response, body) => {
if (!error) {
return;
}
console.error(error, response, body);
});
};
const watchiTunes = () => {
let nowplaying;
setInterval(() => {
playback.currentTrack((res) => {
if (!res) {
return;
}
const message = `${res.name} - ${res.artist}`;
if (nowplaying === message) {
return;
}
console.log(message);
sendToSlack(message);
nowplaying = message;
});
}, 3000);
};
app.on('ready', () => {
if (!token) {
console.log('token ga naiyo');
return;
}
watchiTunes();
});