-
Notifications
You must be signed in to change notification settings - Fork 1
/
discord.go
65 lines (59 loc) · 1.29 KB
/
discord.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
64
65
package main
import (
"time"
"github.com/hugolgst/rich-go/client"
"github.com/redraskal/star-citizen-rich-presence/rsi"
"github.com/redraskal/star-citizen-rich-presence/utils"
)
var (
DefaultActivity = client.Activity{
Details: "Starting Game",
LargeImage: "logo",
Timestamps: &client.Timestamps{},
}
)
func UpdateStartTimestamp(a *client.Activity) {
time := time.Now()
a.Timestamps = &client.Timestamps{
Start: &time,
}
}
func UpdateProfile(a *client.Activity) error {
username, err := rsi.Username()
if err != nil {
return err
}
println("Username:", username)
a.Buttons = []*client.Button{
{
Label: "Profile",
Url: rsi.ProfileEndpoint + username,
},
{
Label: "Download Mod",
Url: "https://github.com/redraskal/star-citizen-rich-presence#installation",
},
}
return nil
}
func UpdateActivity(a client.Activity, s utils.SessionInfo) error {
if len(s.Location.IDs) == 0 {
return nil
}
if s.Details == a.Details {
return nil
}
if s.Location.Image != "" {
a.LargeImage = s.Location.Image
a.SmallImage = DefaultActivity.LargeImage
} else {
a.LargeImage = DefaultActivity.LargeImage
a.SmallImage = ""
}
if err := UpdateProfile(&a); err != nil {
println(err)
}
println("Activity:", s.Details)
a.Details = s.Details
return client.SetActivity(a)
}