-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetpresence.go
101 lines (83 loc) · 1.89 KB
/
setpresence.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"net/http"
"time"
"github.com/Haydz6/rich-go/client"
"github.com/gin-gonic/gin"
)
var LastGameId = 0
var LastGameIcon = ""
var LastPresenceUpdate = time.Now().Unix()
var GameElapsed = time.Now()
var LoggedIn = false
type SetPresenceBodyStruct struct {
UserId int
PlaceId int
GameId int
State string
Details string
GameName string
}
func Login() {
if LoggedIn {
return
}
client.Login("1050943341212217344")
LoggedIn = true
}
func SetPresence(c *gin.Context) {
var Body SetPresenceBodyStruct
if err := c.BindJSON(&Body); err != nil {
c.String(http.StatusBadRequest, err.Error())
return
}
LastPresenceUpdate = time.Now().Unix()
if LastGameId != Body.GameId {
GameElapsed = time.Now()
Success, NewGameIcon := GetGameIcon(Body.GameId)
if Success {
LastGameIcon = NewGameIcon
LastGameId = Body.GameId
}
}
Login()
err := client.SetActivity(client.Activity{
State: Body.State,
Details: Body.Details,
LargeImage: LastGameIcon,
LargeText: Body.GameName,
SmallImage: "https://cdn.discordapp.com/app-icons/1050943341212217344/96e49f383082fb14b482911d50ff6261.png?size=512",
SmallText: "Roblox Studio",
Timestamps: &client.Timestamps{
Start: &GameElapsed,
},
Buttons: []*client.Button{
&client.Button{Label: "View Game", Url: fmt.Sprintf("https://roblox.com/games/%d", Body.PlaceId)},
&client.Button{Label: "Join Game", Url: fmt.Sprintf("roblox://placeId=%d&launchData=", Body.PlaceId)},
},
})
if err != nil {
c.String(http.StatusBadRequest, err.Error())
}
c.String(http.StatusOK, "")
}
func KillActivity() {
err := client.SetActivity(client.Activity{
State: "end",
})
if err != nil {
println(err)
}
}
func TimeoutCheck() {
for range time.Tick(time.Second) {
if time.Now().Unix()-LastPresenceUpdate >= 3 {
if LoggedIn {
LoggedIn = false
KillActivity()
client.Logout()
}
}
}
}