Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buttons functional #391

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: '{build}'
install:
- python -m pip install click
- python -m pip install build.py

build_script:
- mkdir examples\unrealstatus\Plugins\discordrpc\Binaries\ThirdParty\discordrpcLibrary\Win64
Expand Down
22 changes: 14 additions & 8 deletions examples/send-presence/send-presence.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you commenting out the join secret and party? These are still used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, you can use that functionality, but in the discord itself you can use either buttons or joining (this happens on their side and does not depend on me)

Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,20 @@ static void updateDiscordPresence()
discordPresence.endTimestamp = time(0) + 5 * 60;
discordPresence.largeImageKey = "canary-large";
discordPresence.smallImageKey = "ptb-small";
discordPresence.partyId = "party1234";
discordPresence.partySize = 1;
discordPresence.partyMax = 6;
discordPresence.partyPrivacy = DISCORD_PARTY_PUBLIC;
discordPresence.matchSecret = "xyzzy";
discordPresence.joinSecret = "join";
discordPresence.spectateSecret = "look";
discordPresence.instance = 0;
// TEMP DISABLE (Join and Spectate)
//discordPresence.partyId = "party1234";
//discordPresence.partySize = 1;
//discordPresence.partyMax = 6;
//discordPresence.partyPrivacy = DISCORD_PARTY_PUBLIC;
//discordPresence.matchSecret = "xyzzy";
//discordPresence.joinSecret = "join";
//discordPresence.spectateSecret = "look";
//discordPresence.instance = 0;
// EXAMPLE BUTTONS
discordPresence.button1Label = "Example 1 button";
discordPresence.button1Url = "https://example.com";
discordPresence.button2Label = "Example 2 button";
discordPresence.button2Url = "https://example.com";
Discord_UpdatePresence(&discordPresence);
}
else {
Expand Down
4 changes: 4 additions & 0 deletions include/discord_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ typedef struct DiscordRichPresence {
const char* matchSecret; /* max 128 bytes */
const char* joinSecret; /* max 128 bytes */
const char* spectateSecret; /* max 128 bytes */
const char* button1Label; /* max 32 bytes */
const char* button1Url; /* max 512 bytes */
const char* button2Label; /* max 32 bytes */
const char* button2Url; /* max 512 bytes */
int8_t instance;
} DiscordRichPresence;

Expand Down
26 changes: 26 additions & 0 deletions src/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,33 @@ size_t JsonWriteRichPresenceObj(char* dest,
WriteOptionalString(writer, "join", presence->joinSecret);
WriteOptionalString(writer, "spectate", presence->spectateSecret);
}

// Add Custom buttons and links (2 Buttons)
if (((presence->button1Label && presence->button1Label[0]) &&
(presence->button1Url && presence->button1Url[0])) ||
((presence->button2Label && presence->button2Label[0]) &&
(presence->button2Url && presence->button2Url[0]))) {
WriteArray buttons(writer, "buttons");

if ((presence->button1Label && presence->button1Label[0]) &&
(presence->button1Url && presence->button1Url[0])) {
WriteObject button1(writer);
writer.Key("label");
writer.String(presence->button1Label);
writer.Key("url");
writer.String(presence->button1Url);
}

if ((presence->button2Label && presence->button2Label[0]) &&
(presence->button2Url && presence->button2Url[0])) {
WriteObject button2(writer);
writer.Key("label");
writer.String(presence->button2Label);
writer.Key("url");
writer.String(presence->button2Url);
}
}

writer.Key("instance");
writer.Bool(presence->instance != 0);
}
Expand Down