Skip to content

Commit

Permalink
Add setDiscordRichPresenceEndTime
Browse files Browse the repository at this point in the history
  • Loading branch information
Lpsd committed Oct 12, 2023
1 parent 233211b commit 1fa482e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Client/core/CDiscordRichPresence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ void CDiscordRichPresence::SetDefaultData()
m_aButtons = {};
m_bUpdateRichPresence = true;
m_bDisallowCustomDetails = true;

m_uiDiscordAppStart = 0;
m_uiDiscordAppEnd = 0;
}

void CDiscordRichPresence::UpdatePresence()
Expand All @@ -89,6 +92,7 @@ void CDiscordRichPresence::UpdatePresence()

discordPresence.details = m_strDiscordAppDetails.c_str();
discordPresence.startTimestamp = m_uiDiscordAppStart;
discordPresence.endTimestamp = m_uiDiscordAppEnd;

DiscordButton buttons[2];
if (m_aButtons)
Expand All @@ -114,6 +118,13 @@ void CDiscordRichPresence::SetPresenceStartTimestamp(const unsigned long ulStart
m_bUpdateRichPresence = true;
}

void CDiscordRichPresence::SetPresenceEndTimestamp(const unsigned long ulEnd)
{
m_uiDiscordAppEnd = ulEnd;
m_bUpdateRichPresence = true;
}


void CDiscordRichPresence::SetAssetLargeData(const char* szAsset, const char* szAssetText)
{
SetAsset(szAsset, szAssetText, true);
Expand Down
1 change: 1 addition & 0 deletions Client/core/CDiscordRichPresence.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CDiscordRichPresence : public CDiscordInterface

void UpdatePresence();
void SetPresenceStartTimestamp(const unsigned long ulStart);
void SetPresenceEndTimestamp(const unsigned long ulEnd);
void SetAsset(const char* szAsset, const char* szAssetText, bool bIsLarge = false);
void SetAssetLargeData(const char* szAsset, const char* szAssetText);
void SetAssetSmallData(const char* szAsset, const char* szAssetText);
Expand Down
21 changes: 21 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void CLuaDiscordDefs::LoadFunctions()
{"setDiscordRichPresenceSmallAsset", ArgumentParser<SetSmallAsset>},
{"setDiscordRichPresenceButton", ArgumentParser<SetButtons>},
{"setDiscordRichPresenceStartTime", ArgumentParser<SetStartTime>},
{"setDiscordRichPresenceEndTime", ArgumentParser<SetEndTime>},
{"setDiscordRichPresencePartySize", ArgumentParser<SetPartySize>},
{"resetDiscordRichPresenceData", ArgumentParser<ResetData>},
{"isDiscordRichPresenceConnected", ArgumentParser < IsDiscordRPCConnected>},
Expand Down Expand Up @@ -137,6 +138,26 @@ bool CLuaDiscordDefs::SetStartTime(unsigned long ulTime)
discord->SetPresenceStartTimestamp(ulSecondsSinceEpoch);
return true;
}

bool CLuaDiscordDefs::SetEndTime(unsigned long ulTime)
{
unsigned long ulSecondsSinceEpoch = time(nullptr) + ulTime;

if (ulTime == 0)
ulSecondsSinceEpoch = 0;

auto discord = g_pCore->GetDiscord();

if (!discord || !discord->IsDiscordRPCEnabled())
return false;

if (discord->IsDiscordCustomDetailsDisallowed())
return false;

discord->SetPresenceEndTimestamp(ulSecondsSinceEpoch);
return true;
}

bool CLuaDiscordDefs::SetPartySize(int iSize, int iMax)
{
if (iSize > iMax)
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CLuaDiscordDefs : public CLuaDefs
static bool SetLargeAsset(std::string szAsset, std::string szAssetText);
static bool SetSmallAsset(std::string szAsset, std::string szAssetText);
static bool SetStartTime(unsigned long ulTime);
static bool SetEndTime(unsigned long ulTime);
static bool SetPartySize(int iMin, int iMax);
static bool IsDiscordRPCConnected();

Expand Down
1 change: 1 addition & 0 deletions Client/sdk/core/CDiscordInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CDiscordInterface
virtual void SetAssetLargeData(const char* szAsset, const char* szAssetText) = 0;
virtual void SetAssetSmallData(const char* szAsset, const char* szAssetText) = 0;
virtual void SetPresenceStartTimestamp(const unsigned long ulStart) = 0;
virtual void SetPresenceEndTimestamp(const unsigned long ulEnd) = 0;
virtual bool SetPresenceButtons(unsigned short int iIndex, const char* szName, const char* szUrl) = 0;
virtual void SetPresencePartySize(int iSize, int iMax) = 0;
//virtual void SetPresenceEndTimestamp(const unsigned long ulEnd) = 0;
Expand Down

0 comments on commit 1fa482e

Please sign in to comment.