Skip to content

Commit

Permalink
Merge pull request #27 from Satoqz/buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
hugolgst authored Feb 20, 2021
2 parents 0310d44 + 5f442d5 commit 7960b99
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions client/inputMapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ type Activity struct {
Timestamps *Timestamps
// Secrets for Rich Presence joining and spectating
Secrets *Secrets
// Clickable buttons that open a URL in the browser
Buttons []*Button
}

// Button holds a label and the corresponding URL that is opened on press
type Button struct {
// The label of the button
Label string
// The URL of the button
Url string
}

// Party holds information for the current party of the player
Expand Down Expand Up @@ -106,5 +116,14 @@ func mapActivity(activity *Activity) *PayloadActivity {
}
}

if len(activity.Buttons) > 0 {
for _, btn := range activity.Buttons {
final.Buttons = append(final.Buttons, &PayloadButton{
Label: btn.Label,
Url: btn.Url,
})
}
}

return final
}
6 changes: 6 additions & 0 deletions client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type PayloadActivity struct {
Party *PayloadParty `json:"party,omitempty"`
Timestamps *PayloadTimestamps `json:"timestamps,omitempty"`
Secrets *PayloadSecrets `json:"secrets,omitempty"`
Buttons []*PayloadButton `json:"buttons,omitempty"`
}

type PayloadAssets struct {
Expand All @@ -47,3 +48,8 @@ type PayloadSecrets struct {
Join string `json:"join,omitempty"`
Spectate string `json:"spectate,omitempty"`
}

type PayloadButton struct {
Label string `json:"label,omitempty"`
Url string `json:"url,omitempty"`
}
6 changes: 6 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func main() {
Timestamps: &client.Timestamps{
Start: &now,
},
Buttons: []*client.Button{
&client.Button{
Label: "GitHub",
Url: "https://github.com/hugolgst/rich-go",
},
},
})

if err != nil {
Expand Down

0 comments on commit 7960b99

Please sign in to comment.