feat: *info botlogintime
This commit is contained in:
parent
a45477ed1b
commit
832d6ee5fa
2 changed files with 42 additions and 6 deletions
|
@ -44,6 +44,7 @@ public class Bot {
|
|||
public boolean printDisconnectedCause = false;
|
||||
|
||||
public boolean loggedIn = false;
|
||||
public long loginTime;
|
||||
|
||||
public final ExecutorService executorService = Main.executorService;
|
||||
public final ScheduledExecutorService executor = Main.executor;
|
||||
|
@ -172,8 +173,10 @@ public class Bot {
|
|||
}
|
||||
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
loggedIn = true;
|
||||
loginTime = System.currentTimeMillis();
|
||||
|
||||
for (SessionListener listener : listeners) {
|
||||
loggedIn = true;
|
||||
listener.connected(new ConnectedEvent(session));
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,16 @@ import java.net.InetAddress;
|
|||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class InfoCommand extends Command {
|
||||
|
@ -36,11 +44,12 @@ public class InfoCommand extends Command {
|
|||
"Shows an info about various things",
|
||||
new String[] {
|
||||
"",
|
||||
"<creator>",
|
||||
"<discord>",
|
||||
"<server>",
|
||||
"<botuser>",
|
||||
"<uptime>"
|
||||
"creator",
|
||||
"discord",
|
||||
"server",
|
||||
"botuser",
|
||||
"botlogintime",
|
||||
"uptime"
|
||||
},
|
||||
new String[] {},
|
||||
TrustLevel.PUBLIC,
|
||||
|
@ -184,6 +193,30 @@ public class InfoCommand extends Command {
|
|||
.color(ColorUtilities.getColorByString(bot.config.colorPalette.uuid))
|
||||
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "botlogintime" -> {
|
||||
final long loginTime = bot.loginTime;
|
||||
|
||||
final Instant instant = Instant.ofEpochMilli(loginTime);
|
||||
final ZoneId zoneId = ZoneId.of("UTC");
|
||||
final OffsetDateTime localDateTime = OffsetDateTime.ofInstant(instant, zoneId);
|
||||
|
||||
final DateTimeFormatter loginTimeFormatter = DateTimeFormatter.ofPattern("MMMM d, yyyy, hh:mm:ss a Z");
|
||||
final String formattedLoginTime = localDateTime.format(loginTimeFormatter);
|
||||
|
||||
final DateFormat timeSinceFormatter = new SimpleDateFormat("HH 'hours' mm 'minutes' ss 'seconds'");
|
||||
timeSinceFormatter.setTimeZone(TimeZone.getTimeZone(zoneId)); // very important
|
||||
final String formattedTimeSince = timeSinceFormatter.format(new Date(System.currentTimeMillis() - loginTime));
|
||||
|
||||
return Component.translatable(
|
||||
"The bots login time is %s and has been on the server for %s",
|
||||
Component
|
||||
.text(formattedLoginTime)
|
||||
.color(ColorUtilities.getColorByString(bot.config.colorPalette.string)),
|
||||
Component
|
||||
.text(formattedTimeSince)
|
||||
.color(ColorUtilities.getColorByString(bot.config.colorPalette.string))
|
||||
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "uptime" -> {
|
||||
final long uptime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000;
|
||||
|
||||
|
|
Loading…
Reference in a new issue