|
| 1 | +const Discord = require("discord.js"), |
| 2 | + Utils = require("../../Modules/Utils"), |
| 3 | + { lang, config, commands } = require("../../index"), |
| 4 | + { SlashCommandBuilder } = require("@discordjs/builders"), |
| 5 | + moment = require("moment"); |
| 6 | + |
| 7 | +// Receive client uptime in miliseconds |
| 8 | +// and break the number into days, hours, minutes and seconds |
| 9 | +const duration = (ms) => { |
| 10 | + const sec = Math.floor((ms / 1000) % 60).toString(); |
| 11 | + const min = Math.floor((ms / (1000 * 60)) % 60).toString(); |
| 12 | + const hrs = Math.floor((ms / (1000 * 60 * 60)) % 60).toString(); |
| 13 | + const days = Math.floor((ms / (1000 * 60 * 60 * 24)) % 60).toString(); |
| 14 | + return days.padStart(1, "0") + " " + "days" + " " + |
| 15 | + hrs.padStart(2, "0") + " " + "hours" + " " + |
| 16 | + min.padStart(2, "0") + " " + "minutes" + " " + |
| 17 | + sec.padStart(2, "0") + " " + "seconds" + " "; |
| 18 | +}; |
| 19 | + |
| 20 | +module.exports = { |
| 21 | + name: "uptime", |
| 22 | + type: "general", |
| 23 | + commandData: commands.General.Uptime, |
| 24 | +}; |
| 25 | + |
| 26 | +/** |
| 27 | + * |
| 28 | + * @param {Discord.Client} bot |
| 29 | + * @param {Discord.Message} message |
| 30 | + * @param {Array} args |
| 31 | + * @param {Object} config |
| 32 | + */ |
| 33 | +module.exports.run = async (bot, message, args, config) => { |
| 34 | + message.channel |
| 35 | + .send({ |
| 36 | + embeds: [ |
| 37 | + { |
| 38 | + title: "Fetching uptime...", |
| 39 | + }, |
| 40 | + ], |
| 41 | + }) |
| 42 | + .then(async (msg) => { |
| 43 | + msg.delete(); |
| 44 | + msg.channel.send( |
| 45 | + Utils.setupMessage({ |
| 46 | + configPath: lang.General.Uptime, |
| 47 | + variables: [ |
| 48 | + ...Utils.userVariables(message.member), |
| 49 | + ...Utils.botVariables(bot), |
| 50 | + { searchFor: /{uptime}/g, replaceWith: duration(bot.uptime) }, |
| 51 | + ], |
| 52 | + }) |
| 53 | + ); |
| 54 | + }); |
| 55 | +}; |
| 56 | + |
| 57 | +/** |
| 58 | + * |
| 59 | + * @param {Discord.Client} bot |
| 60 | + * @param {Discord.Interaction} interaction |
| 61 | + */ |
| 62 | +module.exports.runSlash = async (bot, interaction) => { |
| 63 | + interaction.reply( |
| 64 | + Utils.setupMessage( |
| 65 | + { |
| 66 | + configPath: lang.General.Uptime, |
| 67 | + variables: [ |
| 68 | + ...Utils.userVariables(interaction.member), |
| 69 | + ...Utils.botVariables(bot), |
| 70 | + { searchFor: /{uptime}/g, replaceWith: duration(bot.uptime) }, |
| 71 | + ], |
| 72 | + }, |
| 73 | + true |
| 74 | + ) |
| 75 | + ); |
| 76 | +}; |
0 commit comments