Add setdiscorddetails

This commit is contained in:
Federico Cecchetto 2022-06-19 03:32:37 +02:00
parent 25aac40a4f
commit 16f181bda4
2 changed files with 29 additions and 1 deletions

View File

@ -16,6 +16,7 @@ namespace discord
{ {
DiscordRichPresence discord_presence; DiscordRichPresence discord_presence;
std::string state; std::string state;
std::optional<std::string> details{};
void update_discord() void update_discord()
{ {
@ -23,6 +24,9 @@ namespace discord
if (!game::CL_IsCgameInitialized()) if (!game::CL_IsCgameInitialized())
{ {
state = {};
details.reset();
discord_presence.details = "Main Menu"; discord_presence.details = "Main Menu";
discord_presence.state = ""; discord_presence.state = "";
@ -37,7 +41,16 @@ namespace discord
const auto mapname = game::UI_SafeTranslateString(utils::string::va("PRESENCE_SP_%s", map)); const auto mapname = game::UI_SafeTranslateString(utils::string::va("PRESENCE_SP_%s", map));
discord_presence.largeImageKey = map; discord_presence.largeImageKey = map;
discord_presence.details = mapname;
if (details.has_value())
{
discord_presence.details = utils::string::va("%s", details.value().data());
}
else
{
discord_presence.details = mapname;
}
discord_presence.state = state.data(); discord_presence.state = state.data();
if (!discord_presence.startTimestamp) if (!discord_presence.startTimestamp)
@ -81,6 +94,16 @@ namespace discord
update_discord(); update_discord();
}, scheduler::pipeline::async); }, scheduler::pipeline::async);
}); });
command::add("setdiscorddetails", [](const command::params& params)
{
const std::string details_ = params.join(1);
scheduler::once([=]()
{
details = details_;
update_discord();
}, scheduler::pipeline::async);
});
} }
private: private:

View File

@ -376,6 +376,11 @@ namespace scripting::lua
command::execute(utils::string::va("setdiscordstate %s", state.data()), false); command::execute(utils::string::va("setdiscordstate %s", state.data()), false);
}; };
game_type["setdiscorddetails"] = [](const game&, const std::string& state)
{
command::execute(utils::string::va("setdiscorddetails %s", state.data()), false);
};
game_type["say"] = [](const game&) game_type["say"] = [](const game&)
{ {
}; };