From 17c7fbf1586bc31d861f6016da45724e3a768ed7 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Sun, 11 Dec 2022 13:09:38 +0700 Subject: [PATCH] use moment instead of secondToHms --- commands/uptime.js | 8 +++++--- util/secondToHms.js | 17 ----------------- 2 files changed, 5 insertions(+), 20 deletions(-) delete mode 100644 util/secondToHms.js diff --git a/commands/uptime.js b/commands/uptime.js index 0f01c0e..0be17de 100644 --- a/commands/uptime.js +++ b/commands/uptime.js @@ -1,5 +1,5 @@ const { MessageEmbed } = require('discord.js') -const { secondsToHms } = require('../util/secondToHms') +const moment = require('moment-timezone') module.exports = { name: 'uptime', alias: [], @@ -7,13 +7,15 @@ module.exports = { usage: '', trusted: 0, execute (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) { - bot.tellraw(selector, [{ text: 'The bot\'s uptime is ', color: 'white' }, { text: `${secondsToHms(Math.floor(performance.now() / 1000))}`, color: 'green' }]) + const time = moment.utc(Math.floor(performance.now())).format('H [hours], m [minutes], s [seconds]') + bot.tellraw(selector, [{ text: 'The bot\'s uptime is ', color: 'white' }, { text: time, color: 'green' }]) }, discordExecute (bot, username, usernameraw, sender, prefix, args, channeldc, message, config) { + const time = moment.utc(Math.floor(performance.now())).format('H [hours], m [minutes], s [seconds]') const Embed = new MessageEmbed() .setColor(config.discord.embedsColors.normal) .setTitle('Bot\'s Uptime') - .setDescription(`The bot's uptime is ${secondsToHms(Math.floor(performance.now() / 1000))}`) + .setDescription(`The bot's uptime is ${time}`) channeldc.send({ embeds: [Embed] }) } } diff --git a/util/secondToHms.js b/util/secondToHms.js deleted file mode 100644 index bfefb87..0000000 --- a/util/secondToHms.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * from codegrepper - * @param {Number} d seconds - * @return {String} X hour, X minute, X second - */ -function secondsToHms (d) { - d = Number(d) - const h = Math.floor(d / 3600) - const m = Math.floor(d % 3600 / 60) - const s = Math.floor(d % 3600 % 60) - const hDisplay = h > 0 ? h + (h === 1 ? ' hour, ' : ' hours, ') : '' - const mDisplay = m > 0 ? m + (m === 1 ? ' minute, ' : ' minutes, ') : '' - const sDisplay = s > 0 ? s + (s === 1 ? ' second' : ' seconds') : '' - return hDisplay + mDisplay + sDisplay -} - -module.exports = { secondsToHms }