forked from hugolgst/rich-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputMapper.go
110 lines (99 loc) 路 2.76 KB
/
inputMapper.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
102
103
104
105
106
107
108
109
110
package client
import (
"time"
)
// Activity holds the data for discord rich presence
type Activity struct {
// What the player is currently doing
Details string
// The user's current party status
State string
// The id for a large asset of the activity, usually a snowflake
LargeImage string
// Text displayed when hovering over the large image of the activity
LargeText string
// The id for a small asset of the activity, usually a snowflake
SmallImage string
// Text displayed when hovering over the small image of the activity
SmallText string
// Information for the current party of the player
Party *Party
// Unix timestamps for start and/or end of the game
Timestamps *Timestamps
// Secrets for Rich Presence joining and spectating
Secrets *Secrets
}
// Party holds information for the current party of the player
type Party struct {
// The ID of the party
ID string
// Used to show the party's current size
Players int
// Used to show the party's maximum size
MaxPlayers int
}
// Timestamps holds unix timestamps for start and/or end of the game
type Timestamps struct {
// unix time (in milliseconds) of when the activity started
Start *time.Time
// unix time (in milliseconds) of when the activity ends
End *time.Time
}
// Secrets holds secrets for Rich Presence joining and spectating
type Secrets struct {
// The secret for a specific instanced match
Match string
// The secret for joining a party
Join string
// The secret for spectating a game
Spectate string
}
func mapActivity(activity *Activity) *PayloadActivity {
// Replace empty fields by "none"
if activity.LargeImage == "" {
activity.LargeImage = "none"
}
if activity.LargeText == "" {
activity.LargeText = "none"
}
if activity.SmallImage == "" {
activity.SmallImage = "none"
}
if activity.SmallText == "" {
activity.SmallText = "none"
}
final := &PayloadActivity{
Details: activity.Details,
State: activity.State,
Assets: PayloadAssets{
LargeImage: activity.LargeImage,
LargeText: activity.LargeText,
SmallImage: activity.SmallImage,
SmallText: activity.SmallText,
},
}
if activity.Timestamps != nil && activity.Timestamps.Start != nil {
start := uint64(activity.Timestamps.Start.UnixNano() / 1e6)
final.Timestamps = &PayloadTimestamps{
Start: &start,
}
if activity.Timestamps.End != nil {
end := uint64(activity.Timestamps.End.UnixNano() / 1e6)
final.Timestamps.End = &end
}
}
if activity.Party != nil {
final.Party = &PayloadParty{
ID: activity.Party.ID,
Size: [2]int{activity.Party.Players, activity.Party.MaxPlayers},
}
}
if activity.Secrets != nil {
final.Secrets = &PayloadSecrets{
Join: activity.Secrets.Join,
Match: activity.Secrets.Match,
Spectate: activity.Secrets.Spectate,
}
}
return final
}