shadPS4/src/common/discord.cpp

44 lines
985 B
C++
Raw Normal View History

2024-02-23 22:32:32 +01:00
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2023-08-11 19:22:26 +02:00
#include <cstring>
#include <ctime>
2024-02-23 22:32:32 +01:00
#include "common/discord.h"
2023-08-11 19:22:26 +02:00
2024-02-23 22:32:32 +01:00
namespace Discord {
void RPC::init() {
DiscordEventHandlers handlers{};
Discord_Initialize("1139939140494971051", &handlers, 1, nullptr);
2023-08-11 19:22:26 +02:00
startTimestamp = time(nullptr);
enabled = true;
2023-08-11 19:22:26 +02:00
}
2024-02-23 22:32:32 +01:00
void RPC::update(Discord::RPCStatus status, const std::string& game) {
DiscordRichPresence rpc{};
2023-08-11 19:22:26 +02:00
if (status == Discord::RPCStatus::Playing) {
rpc.details = "Playing a game";
rpc.state = game.c_str();
} else {
rpc.details = "Idle";
}
2023-08-11 19:22:26 +02:00
rpc.largeImageKey = "shadps4";
rpc.largeImageText = "ShadPS4 is a PS4 emulator";
rpc.startTimestamp = startTimestamp;
2023-08-11 19:22:26 +02:00
Discord_UpdatePresence(&rpc);
2023-08-11 19:22:26 +02:00
}
2024-02-23 22:32:32 +01:00
void RPC::stop() {
if (enabled) {
enabled = false;
Discord_ClearPresence();
Discord_Shutdown();
}
2023-08-11 19:22:26 +02:00
}
2024-02-23 22:32:32 +01:00
} // namespace Discord