Skip to content

Commit 39a7fc6

Browse files
committed
add uptime command
1 parent a61d128 commit 39a7fc6

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

Commands/General/uptime.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
};

commands.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ General:
2626
Data:
2727
Name: ping
2828
Description: "Displays Bot Pings"
29+
Uptime:
30+
Description: "View Your Bot's Current Uptime"
31+
Usage: "uptime"
32+
Aliases: []
33+
Permission:
34+
- "@everyone"
35+
SlashCommand:
36+
Enabled: true
37+
Data:
38+
Name: uptime
39+
Description: "View Your Bot's Current Uptime"
2940
ServerInfo:
3041
Description: "View Server's Information"
3142
Usage: "serverinfo"

lang.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ General:
2323
Footer: "{user-tag}"
2424
FooterIcon: "{user-pfp}"
2525
Timestamp: true
26+
Uptime:
27+
Embeds:
28+
- Author: "{bot-tag}'s Uptime"
29+
AuthorIcon: "{bot-pfp}"
30+
Description: |-
31+
**Current Uptime**: {uptime}
32+
Footer: "{user-tag}"
33+
FooterIcon: "{user-pfp}"
34+
Timestamp: true
2635
ServerInfo:
2736
Embeds:
2837
- Title: "💭 Server Info - {guild-name} [1/2]"

0 commit comments

Comments
 (0)