Skip to content

Commit

Permalink
fix(memberLeave): fix nonsense timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
theimperious1 committed Dec 5, 2024
1 parent dd6bd41 commit 27243fb
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions src/discord/events/guildMemberRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,37 @@ export const guildMemberRemove: GuildMemberRemoveEvent = {
.setColor(Colors.Red);

if (joinedTimestamp) {
// log.debug(F, `Date.now(): ${Date.now()}`);
// display the difference between the two dates
// NOTE: Can simplify with luxon
const diff = Math.abs(Date.now() - joinedTimestamp);
// log.debug(F, `diff: ${diff}`);
const years = Math.floor(diff / (1000 * 60 * 60 * 24 * 365)) > 0
? `${Math.floor(diff / (1000 * 60 * 60 * 24 * 365))} years, `
: '';
const months = Math.floor(diff / (1000 * 60 * 60 * 24 * 30)) > 0
? `${Math.floor(diff / (1000 * 60 * 60 * 24 * 30))} months, `
: '';
const weeks = Math.floor(diff / (1000 * 60 * 60 * 24 * 7)) > 0
? `${Math.floor(diff / (1000 * 60 * 60 * 24 * 7))} weeks, `
: '';
const days = Math.floor(diff / (1000 * 60 * 60 * 24)) > 0
? `${Math.floor(diff / (1000 * 60 * 60 * 24))} days, `
: '';
const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)) > 0
? `${Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))} hours, `
: '';
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
? `${Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))} minutes, `
: '';
const seconds = Math.floor((diff % (1000 * 60)) / 1000)
? `${Math.floor((diff % (1000 * 60)) / 1000)} seconds`
: '';
const duration = `${years}${months}${weeks}${days}${hours}${minutes}${seconds}`;


Check failure on line 28 in src/discord/events/guildMemberRemove.ts

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
// Helper to calculate units and update remaining time
const getUnit = (time: number, unitMs: number) => {
const value = Math.floor(time / unitMs);
return [value, time % unitMs];
};

Check failure on line 34 in src/discord/events/guildMemberRemove.ts

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
let remaining = diff;

Check failure on line 35 in src/discord/events/guildMemberRemove.ts

View workflow job for this annotation

GitHub Actions / Lint

'remaining' is never reassigned. Use 'const' instead

Check failure on line 36 in src/discord/events/guildMemberRemove.ts

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
const [years, afterYears] = getUnit(remaining, 1000 * 60 * 60 * 24 * 365);
const [months, afterMonths] = getUnit(afterYears, 1000 * 60 * 60 * 24 * 30);
const [weeks, afterWeeks] = getUnit(afterMonths, 1000 * 60 * 60 * 24 * 7);
const [days, afterDays] = getUnit(afterWeeks, 1000 * 60 * 60 * 24);
const [hours, afterHours] = getUnit(afterDays, 1000 * 60 * 60);
const [minutes, afterMinutes] = getUnit(afterHours, 1000 * 60);
const [seconds] = getUnit(afterMinutes, 1000);

Check failure on line 44 in src/discord/events/guildMemberRemove.ts

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
// Build duration string dynamically
const duration = [
years && `${years} year${years > 1 ? 's' : ''}`,
months && `${months} month${months > 1 ? 's' : ''}`,
weeks && `${weeks} week${weeks > 1 ? 's' : ''}`,
days && `${days} day${days > 1 ? 's' : ''}`,
hours && `${hours} hour${hours > 1 ? 's' : ''}`,
minutes && `${minutes} minute${minutes > 1 ? 's' : ''}`,
seconds && `${seconds} second${seconds > 1 ? 's' : ''}`,
]
.filter(Boolean)
.join(', ');

Check failure on line 57 in src/discord/events/guildMemberRemove.ts

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
embed.setDescription(`${member} has left the guild after ${duration}`);
} else {
embed.setDescription(`${member} has left the guild`);
Expand Down

0 comments on commit 27243fb

Please sign in to comment.