From 772342ea5e8e4eeefeffcc21875bc196e2f0a86f Mon Sep 17 00:00:00 2001 From: baz Date: Sun, 11 Feb 2024 03:47:01 +0000 Subject: [PATCH] Add uptime command --- commands/testing/uptime.js | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 commands/testing/uptime.js diff --git a/commands/testing/uptime.js b/commands/testing/uptime.js new file mode 100644 index 0000000..6c01342 --- /dev/null +++ b/commands/testing/uptime.js @@ -0,0 +1,54 @@ +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('uptime') + .setDescription('Get the current application uptime'), + async execute(interaction) { + const uptimeInSeconds = process.uptime(); + + let currentUptime = ''; + let databaseBackup = ''; + + const days = Math.floor(uptimeInSeconds / (3600 * 24)); + if (days > 0) { + currentUptime = currentUptime.concat(`${days} days `); + } + + const hours = Math.floor((uptimeInSeconds % (3600 * 24)) / 3600); + if (hours > 0) { + currentUptime = currentUptime.concat(`${hours} hours `); + databaseBackup = databaseBackup.concat(`${hours} hours `); + } + + const minutes = Math.floor((uptimeInSeconds % 3600) / 60); + if (minutes > 0) { + currentUptime = currentUptime.concat(`${minutes} minutes `); + databaseBackup = databaseBackup.concat(`${minutes} minutes `); + } + + const seconds = Math.floor(uptimeInSeconds % 60); + if (seconds > 0) { + currentUptime = currentUptime.concat(`${seconds} seconds `); + databaseBackup = databaseBackup.concat(`${seconds} seconds `); + } + + const now = new Date(); + const currentYear = now.getFullYear(); + const currentMonth = now.getMonth() + 1; + const currentDay = now.getDate(); + const currentHour = now.getHours(); + const currentMinute = now.getMinutes(); + const currentSecond = now.getSeconds(); + const currentDate = `${currentYear}/${currentMonth}/${currentDay} ${currentHour}:${currentMinute}:${currentSecond}`; + + const embed = new EmbedBuilder() + .setColor(0xD36918) + .setTitle('Current Uptime') + .setThumbnail(interaction.client.user.avatarURL()) + .setDescription(`The current uptime is **${currentUptime}**.\nThe last database backup was **${databaseBackup}**.\nThe current local time is **${currentDate}**.`) + .setTimestamp(); + + await interaction.reply({ embeds: [embed] }); + }, +}; \ No newline at end of file