Documentation ¶
Overview ¶
Package drpc implements the Discord RPC protocol.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrConnFailed = errors.New("drpc: connection failed")
)
Functions ¶
This section is empty.
Types ¶
type Activity ¶
type Activity struct { // What the player is currently doing. Details string `json:"details,omitempty"` // The user's current state. State string `json:"state,omitempty"` // Timestamps for the start and end of the activity. Timestamps *Timestamps `json:"timestamps,omitempty"` // Profile artworks. Assets *Assets `json:"assets,omitempty"` // Party information. Party *Party `json:"party,omitempty"` // Secrets data. It cannot be used with the Buttons field. Secrets *Secrets `json:"secrets,omitempty"` // Buttons to display. It cannot be used with the Secrets field. Buttons []Button `json:"buttons,omitempty"` }
Activity describes an user's current activity.
type Assets ¶
type Assets struct { // Name of the uploaded image for the large profile artwork. LargeImage string `json:"large_image,omitempty"` // Tooltip for the large profile artwork. LargeText string `json:"large_text,omitempty"` // Name of the uploaded image for the small profile artwork. SmallImage string `json:"small_image,omitempty"` // Tooltip for the small profile artwork. SmallText string `json:"small_text,omitempty"` }
Assets contains an user's profile artwork.
type Button ¶
type Button struct { // Name of the button. Label string `json:"label,omitempty"` // URL to open when the button is clicked. URL string `json:"url,omitempty"` }
Button contains a button data. Both fields are required.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Discord RPC client.
func New ¶
New creates a new Discord RPC client with the given application ID.
The application ID given must not be empty.
func (*Client) Connect ¶
Connect connects the client to the Discord RPC server and sends a handshake. It returns nil if the client is already connected.
func (*Client) Read ¶
Read reads a message from the connection. It automatically reconnects if the connection is closed.
func (*Client) SetActivity ¶
SetActivity sets the player's activity.
type FrameHeader ¶
type FrameHeader struct { Command string `json:"cmd"` Event string `json:"evt,omitempty"` Nonce string `json:"nonce,omitempty"` }
FrameHeader is a header for a frame.
func NewFrameHeader ¶
func NewFrameHeader(command string) FrameHeader
NewFrameHeader creates a new frame header with the given command.
func NewFrameHeaderWithEvent ¶
func NewFrameHeaderWithEvent(command, event string) FrameHeader
NewFrameHeaderWithEvent creates a new frame header with the given command and event.
type FrameSetActivity ¶
type FrameSetActivity struct { FrameHeader Args FrameSetActivityArgs `json:"args"` }
FrameSetActivity is a frame of the SetActivity message.
type FrameSetActivityArgs ¶
FrameSetActivityArgs is a set of arguments for the SetActivity message.
type Party ¶
type Party struct { // ID of the player's party, lobby, or group. ID string `json:"id,omitempty"` // The first element is the current party size, the second element is the max party size. Size [2]int `json:"size,omitempty"` }
Party contains party information.
type Secrets ¶
type Secrets struct { // Unique hashed string for chat invitations and Ask to Join. Join string `json:"join,omitempty"` // Unique hashed string for Spectate button. Spectate string `json:"spectate,omitempty"` // (For future use) Unique hashed string for a player's match. Match string `json:"match,omitempty"` }
Secrets contains secrets for joining and spectating.
type Timestamps ¶
type Timestamps struct { // Epoch seconds for game start - including will show time as "elapsed". Start time.Time `json:"start,omitempty"` // Epoch seconds for game end - including will show time as "remaining". End time.Time `json:"end,omitempty"` }
Timestamps contains timestamps for the start and end of the activity.
Sending End timestamp will always have the time displayed as "remaining" until the given time. Sending Start timestamp will show "elapsed" as long as there is no End sent.
func (Timestamps) MarshalJSON ¶
func (t Timestamps) MarshalJSON() ([]byte, error)
Custom marshal method for Timestamps. It is required because protocol accepts only epoch seconds.