-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (56 loc) · 1.62 KB
/
main.go
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
60
61
62
63
package main
import (
"fmt"
"time"
"github.com/andybrewer/mack"
"github.com/cloudinary/cloudinary-go"
"github.com/hugolgst/rich-go/client"
)
type ConfigCloud struct {
CloudId string `json:"cloudId"`
CloudToken string `json:"cloudToken"`
CloudTokenSecret string `json:"cloudTokenSecret"`
}
var cld *cloudinary.Cloudinary
func main() {
var config Config
config.loadConfig()
setup()
lastState := ""
lastTitle := ""
err := client.Login(config.DiscordAppId)
if err != nil {
alert := mack.AlertOptions{
Title: "Apple Music RPC",
Message: "Cant connect to discord",
Buttons: "OK",
}
mack.AlertBox(alert)
}
cld, err = cloudinary.NewFromParams(config.ConfigCloud.CloudId, config.ConfigCloud.CloudToken, config.ConfigCloud.CloudTokenSecret)
if err != nil {
alert := mack.AlertOptions{
Title: "Apple Music RPC",
Message: "Cant connect to cloud",
Buttons: "OK",
}
mack.AlertBox(alert)
panic(err)
}
mack.Notify("Service up and Running", "Apple Music RPC")
for {
player := getPlayer()
if player.State == "playing" || player.State == "paused" {
if player.Title != lastTitle {
go player.setRpc()
lastState, lastTitle = player.State, player.Title
fmt.Printf("------------------------------------------\nNow listening to : %s\nOn the album : %s\nBy : %s \n------------------------------------------\n", player.Title, player.Album, player.Artist)
} else if player.State != lastState {
go player.setRpc()
lastState, lastTitle = player.State, player.Title
fmt.Printf("State Change now : %s\n", player.State)
}
time.Sleep(time.Second * 2)
}
}
}