From a8dc09e90c957047ab6e7f2516cfbdb8bb4d590a Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Wed, 19 Jun 2024 23:21:52 +0900 Subject: [PATCH] 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 --- activity.go | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 activity.go diff --git a/activity.go b/activity.go new file mode 100644 index 0000000..3a10a5f --- /dev/null +++ b/activity.go @@ -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 +} diff --git a/go.mod b/go.mod index c51f5b5..9fc1b98 100644 --- a/go.mod +++ b/go.mod @@ -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