update/track-longest-session-time

This commit is contained in:
SowinskiBraeden committed 2023-09-02 22:14:29 -07:00
1 parent 55fb1ec593
commit f451817416
5 files changed
+25 -17

No files matched your search

+2 -4
View File
@@ -60,17 +60,15 @@ module.exports = {
let playerStat = stats.find(stat => stat.playerID == info.playerID)
let playerStatIndex = stats.indexOf(playerStat);
if (playerStat == undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
if (!client.exists(playerStat.totalSessionTime)) playerStat.totalSessionTime = 0;
let newDt = await client.getDateEST(info.time);
let unixTime = Math.floor(newDt.getTime()/1000);
if (!client.exists(playerStat.lastConnectionDate)) playerStat.lastConnectionDate = await client.getDateEST(info.time);
let oldUnixTime = Math.floor(playerStat.lastConnectionDate.getTime()/1000);
let seconds = unixTime - oldUnixTime;
let sessionTime = client.secondsToDhms(seconds);
playerStat.totalSessionTime = playerStat.totalSessionTime + seconds;
playerStat.lastSessionTime = sessionTime;
playerStat.lastSessionTime = seconds;
playerStat.longestSessionTime = seconds > playerStat.longestSessionTime ? seconds : playerStat.longestSessionTime;
if (playerStatIndex == -1) stats.push(playerStat);
else stats[playerStatIndex] = playerStat;