Skip to content

Commit

Permalink
Update status
Browse files Browse the repository at this point in the history
  • Loading branch information
onepiecehung committed Jun 4, 2023
1 parent 21cfec2 commit bcad354
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/events/ready.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ActivityType, Client, Events } from "discord.js";

import botInfo from "../../package.json";
import { getNumberOfDays } from "../util/date/day";

export default {
name: Events.ClientReady,
Expand All @@ -20,10 +21,15 @@ export default {
console.log("Total users:", users.length);

console.log(`Ready! Logged in as ${client.user.tag}`);

const numberOfDays = getNumberOfDays(
new Date("2019/08/25"),
new Date()
);
client.user.setPresence({
activities: [
{
name: `/help v${botInfo.version}`,
name: `/help v${botInfo.version}, ${numberOfDays} days of uptime: `,
type: ActivityType.Watching,
},
],
Expand Down
15 changes: 15 additions & 0 deletions src/util/date/day.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function getNumberOfDays(start: Date, end: Date): number {
const date1 = new Date(start);
const date2 = new Date(end);

// One day in milliseconds
const oneDay = 1000 * 60 * 60 * 24;

// Calculating the time difference between two dates
const diffInTime = date2.getTime() - date1.getTime();

// Calculating the no. of days between two dates
const diffInDays = Math.round(diffInTime / oneDay);

return diffInDays;
}

0 comments on commit bcad354

Please sign in to comment.