-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc.go
94 lines (86 loc) · 1.89 KB
/
rpc.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
// Created by EldersJavas(EldersJavas&gmail.com)
package ebiten_rpc
import (
"github.com/hugolgst/rich-go/client"
"time"
)
type GameRPC struct {
AppID string
GameName string
State string
LargeImageID string
LargeImageText string
SmallImageID string
SmallImageText string
Party *client.Party
JoinID string
StartTime time.Time
Button []*client.Button
Secret *client.Secrets
}
func (g *GameRPC) Start() error {
g.StartTime = time.Now()
err := client.Login(g.AppID)
if err != nil {
return err
}
err = client.SetActivity(client.Activity{
Details: "Playing " + g.GameName,
State: g.State,
LargeImage: g.LargeImageID,
LargeText: g.LargeImageText,
SmallImage: g.SmallImageID,
SmallText: g.SmallImageText,
Party: g.Party,
Timestamps: &client.Timestamps{Start: &g.StartTime},
Secrets: g.Secret,
Buttons: g.Button,
})
if err != nil {
return err
}
return nil
}
func (g *GameRPC) AddButton(Label, Url string) error {
b := &client.Button{Label: Label, Url: Url}
g.Button = append(g.Button, b)
err := g.Update()
if err != nil {
return err
}
return nil
}
func (g *GameRPC) AddSecret(Match, Join, Spectate string) error {
b := &client.Secrets{
Match: Match,
Join: Join,
Spectate: Spectate,
}
g.Secret = b
err := g.Update()
if err != nil {
return err
}
return nil
}
func (g *GameRPC) Update() error {
err := client.SetActivity(client.Activity{
Details: "Playing " + g.GameName,
State: g.State,
LargeImage: g.LargeImageID,
LargeText: g.LargeImageText,
SmallImage: g.SmallImageID,
SmallText: g.SmallImageText,
Party: g.Party,
Timestamps: &client.Timestamps{Start: &g.StartTime},
Secrets: g.Secret,
Buttons: g.Button,
})
if err != nil {
return err
}
return nil
}
func NewGameRPC(AppID string) *GameRPC {
return &GameRPC{AppID: AppID}
}