From 915466d9c58d6bed32610a8a6db8c4ac873d91d4 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 11 May 2023 17:34:56 +0700 Subject: [PATCH] actually add uptime.,.,., --- .../chomens_bot/commands/UptimeCommand.java | 57 +++++++++++++++++++ .../plugins/CommandHandlerPlugin.java | 1 + 2 files changed, 58 insertions(+) create mode 100644 src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UptimeCommand.java diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UptimeCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UptimeCommand.java new file mode 100644 index 0000000..91e1297 --- /dev/null +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UptimeCommand.java @@ -0,0 +1,57 @@ +package land.chipmunk.chayapak.chomens_bot.commands; + +import land.chipmunk.chayapak.chomens_bot.command.Command; +import land.chipmunk.chayapak.chomens_bot.command.CommandContext; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.lang.management.ManagementFactory; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +public class UptimeCommand implements Command { + public String name() { return "uptime"; } + + public String description() { + return "Shows the bot's uptime"; + } + + public List usage() { + final List usages = new ArrayList<>(); + usages.add(""); + + return usages; + } + + public List alias() { + final List aliases = new ArrayList<>(); + aliases.add(""); + + return aliases; + } + + public int trustLevel() { + return 0; + } + + public Component execute(CommandContext context, String[] args, String[] fullArgs) { + final long uptime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000; + + long days = TimeUnit.SECONDS.toDays(uptime); + long hours = TimeUnit.SECONDS.toHours(uptime) - (days * 24L); + long minutes = TimeUnit.SECONDS.toMinutes(uptime) - (TimeUnit.SECONDS.toHours(uptime) * 60); + long seconds = TimeUnit.SECONDS.toSeconds(uptime) - (TimeUnit.SECONDS.toMinutes(uptime) * 60); + + return Component.translatable( + "The bot's uptime is: %s", + Component.translatable( + "%s days, %s hours, %s minutes, %s seconds", + Component.text(days), + Component.text(hours), + Component.text(minutes), + Component.text(seconds) + ).color(NamedTextColor.GREEN) + ); + } +} diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java index d6d3af8..747cd04 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java @@ -60,6 +60,7 @@ public class CommandHandlerPlugin { registerCommand(new KickCommand()); registerCommand(new ClearChatQueueCommand()); registerCommand(new FilterCommand()); + registerCommand(new UptimeCommand()); } public void registerCommand (Command command) {