-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
40 lines (32 loc) · 1.17 KB
/
index.php
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
<?php
require_once './nowplaying/nowplaying.class.php';
$lastfmApiKey = "";
$slackWebhook = "";
$nowPlaying = new NowPlaying('vrjoycestick', $lastfmApiKey);
$nowPlaying->setNoTrackPlayingMessage('no song');
if($nowPlaying->getNowPlaying() == "no song" && file_get_contents("./status.txt") == "active") {
file_put_contents("./status.txt", "not");
sendMessage("The den is empty.");
} else {
if($nowPlaying->getNowPlaying() != "no song" && file_get_contents("./status.txt") == "not") {
file_put_contents("./status.txt", "active");
sendMessage("Someone is in the den.");
}
}
echo $nowPlaying->getNowPlaying();
function sendMessage($message) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $slackWebhook);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"text\":\"$message\"}");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
}