Skip to content

Commit

Permalink
stats: precise seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
saiteja-madha committed Feb 12, 2024
1 parent 825ce35 commit b1a3cc0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/handlers/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ module.exports = {
async trackVoiceStats(oldState, newState) {
const oldChannel = oldState.channel;
const newChannel = newState.channel;
const now = Date.now();

if (!oldChannel && !newChannel) return;
if (!newState.member) return;
Expand All @@ -103,14 +104,14 @@ module.exports = {
const statsDb = await getMemberStats(member.guild.id, member.id);
statsDb.voice.connections += 1;
await statsDb.save();
voiceStates.set(member.id, Date.now());
voiceStates.set(member.id, now);
}

// Member left a voice channel
if (oldChannel && !newChannel) {
const statsDb = await getMemberStats(member.guild.id, member.id);
if (voiceStates.has(member.id)) {
const time = Date.now() - voiceStates.get(member.id);
const time = now - voiceStates.get(member.id);
statsDb.voice.time += time / 1000; // add time in seconds
await statsDb.save();
voiceStates.delete(member.id);
Expand Down

0 comments on commit b1a3cc0

Please sign in to comment.