library: rpc: activity data types and set method

Activity data types come from Discord documentation examples as the documented field optionality is inaccurate.

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
Ophestra Umiker 2024-06-19 23:21:52 +09:00
parent 7074a1a950
commit a8dc09e90c
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
2 changed files with 85 additions and 1 deletions

84
activity.go Normal file
View File

@ -0,0 +1,84 @@
package rpcfetch
import (
"os"
"github.com/google/uuid"
)
type Activity struct {
// State is the user's current party status, or text used for a custom status
State string `json:"state,omitempty"`
// Details is what the player is currently doing
Details string `json:"details,omitempty"`
// Timestamps are Unix timestamps for start and/or end of the game
Timestamps *ActivityTimestamps `json:"timestamps,omitempty"`
// Assets are images for the presence and their hover texts
Assets *ActivityAssets `json:"assets,omitempty"`
// Party is information for the current party of the player
Party *ActivityParty `json:"party,omitempty"`
// Secrets for Rich Presence joining and spectating
Secrets *ActivitySecrets `json:"secrets,omitempty"`
// Instance is whether or not the activity is an instanced game session
Instance bool `json:"instance,omitempty"`
}
type ActivityTimestamps struct {
// Start is the Unix time (in milliseconds) of when the activity started
Start *int64 `json:"start,omitempty"`
// End is the Unix time (in milliseconds) of when the activity ends
End *int64 `json:"end,omitempty"`
}
type ActivityAssets struct {
// LargeImage is the large image asset
LargeImage string `json:"large_image,omitempty"`
// LargeText is the text displayed when hovering over the large image of the activity
LargeText string `json:"large_text,omitempty"`
// SmallImage is the small image asset
SmallImage string `json:"small_image,omitempty"`
// SmallText is the text displayed when hovering over the small image of the activity
SmallText string `json:"small_text,omitempty"`
}
type ActivityParty struct {
// ID of the party
ID string `json:"id,omitempty"`
// Size is used to show the party's current and maximum size
Size *[2]int `json:"size,omitempty"`
}
type ActivitySecrets struct {
// Join is the secret for joining a party
Join string `json:"join,omitempty"`
// Spectate is the secret for spectating a game
Spectate string `json:"spectate,omitempty"`
// Match is the secret for a specific instanced match
Match string `json:"match,omitempty"`
}
type activityArgs struct {
PID int `json:"pid"`
Activity *Activity `json:"activity"`
}
func (d *Client) SetActivity(act *Activity) error {
if err := d.activate(); err != nil {
return err
}
nonce := uuid.New().String()
_, _, err := validateRaw[Response[[]byte]](Heartbeat, "", "SET_ACTIVITY", nonce)(
d, Heartbeat, Command[activityArgs]{
Arguments: activityArgs{
PID: os.Getpid(),
Activity: act,
},
payload: payload{
Command: "SET_ACTIVITY",
Nonce: nonce,
},
})
return err
}

2
go.mod
View File

@ -2,4 +2,4 @@ module git.ophivana.moe/cat/rpcfetch
go 1.22
require github.com/google/uuid v1.6.0 // indirect
require github.com/google/uuid v1.6.0