Skip to content

Instantly share code, notes, and snippets.

@NepNep21
Last active December 4, 2021 13:03
Show Gist options
  • Save NepNep21/d604abeb7e4c90a04e37f697d6f6fa11 to your computer and use it in GitHub Desktop.
Save NepNep21/d604abeb7e4c90a04e37f697d6f6fa11 to your computer and use it in GitHub Desktop.
DiscordRPC testing program
#include "include/discord_rpc.h"
#include <chrono>
#include <cstdio>
#include <iostream>
#include <thread>
using namespace std::chrono;
void disconnected(int errorCode, const char *message) {
std::cout << "Disconnected with code " << errorCode << "and message " << message << std::endl;
}
void errored(int errorCode, const char *message) {
std::cout << "Errored with code " << errorCode << "and message " << message << std::endl;
}
int main() {
DiscordEventHandlers handlers {};
handlers.disconnected = &disconnected;
handlers.errored = &errored;
Discord_Initialize("<app id>", &handlers, 1, nullptr);
DiscordRichPresence presence {};
presence.state = "Testing";
seconds timestamp = duration_cast<seconds>(system_clock::now().time_since_epoch());
presence.startTimestamp = timestamp.count();
for (int i = 1; i <= 10; i++) {
char buffer[50];
if (!sprintf(buffer, "Finished %d iterations", i)) {
std::cout << "Failed hard\n";
return 1;
}
presence.details = buffer;
Discord_UpdatePresence(&presence);
Discord_RunCallbacks();
std::this_thread::sleep_for(seconds(5));
}
Discord_ClearPresence();
Discord_Shutdown();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment