From 11d4b7fa56007a7516309d75d5f09c1a196bad44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Sun, 25 Dec 2022 02:12:39 +0100 Subject: [PATCH] Add bot age info --- src/main/java/wtf/beatrice/hidekobot/Cache.java | 10 ++++++++++ .../wtf/beatrice/hidekobot/commands/base/BotInfo.java | 7 ++++++- .../hidekobot/commands/message/BotInfoCommand.java | 3 ++- .../java/wtf/beatrice/hidekobot/util/FormatUtil.java | 6 +++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/wtf/beatrice/hidekobot/Cache.java b/src/main/java/wtf/beatrice/hidekobot/Cache.java index ef18916..6e10789 100644 --- a/src/main/java/wtf/beatrice/hidekobot/Cache.java +++ b/src/main/java/wtf/beatrice/hidekobot/Cache.java @@ -51,6 +51,9 @@ public class Cache // used to count e.g. uptime private static LocalDateTime startupTime = null; + // date of when the first bot commit was made (CEST time) + private static final LocalDateTime botBirthDate = LocalDateTime.of(2022, 8, 25, 21, 50); + // the scheduler that should always be used when running a scheduled task. private final static ScheduledExecutorService taskScheduler = Executors.newSingleThreadScheduledExecutor(); // todo: try-with-resources @@ -280,6 +283,13 @@ public class Cache */ public static LocalDateTime getStartupTime() { return startupTime; } + /** + * Get the time of when the bot was created. + * + * @return a LocalDateTime object of the first commit's instant. + */ + public static LocalDateTime getBotBirthDate() { return botBirthDate; } + public static String getFullHeartBeatLink() { return configurationSource == null ? null : (String) configurationSource.getConfigValue(ConfigurationEntry.HEARTBEAT_LINK); } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/BotInfo.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/BotInfo.java index 5fd0702..8b25c47 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/BotInfo.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/BotInfo.java @@ -91,13 +91,18 @@ public class BotInfo embedBuilder.addField("Maintainer", developerMention, true); // uptime field - embedBuilder.addField("Uptime", FormatUtil.getNiceUptime(), true); + embedBuilder.addField("Uptime", FormatUtil.getNiceTimeDiff(Cache.getStartupTime()), true); // issue tracker field embedBuilder.addField("Support", "[Issue tracker](https://git.beatrice.wtf/mind-overflow/HidekoBot/issues)", true); //todo: we should probably make this a final field in the config class + // bot birthday field + embedBuilder.addField("Bot age", + Cache.getBotName() + " was created " + FormatUtil.getNiceTimeDiff(Cache.getBotBirthDate()) + "ago!", + false); + return embedBuilder.build(); } } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/BotInfoCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/BotInfoCommand.java index 3a8665c..525af20 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/BotInfoCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/BotInfoCommand.java @@ -10,6 +10,7 @@ import wtf.beatrice.hidekobot.commands.base.BotInfo; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; +import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -19,7 +20,7 @@ public class BotInfoCommand implements MessageCommand @Override public LinkedList getCommandLabels() { - return new LinkedList<>(Collections.singletonList("botinfo")); + return new LinkedList<>(Arrays.asList("botinfo", "info")); } @Nullable diff --git a/src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java b/src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java index 1c9a11e..c1fd524 100644 --- a/src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java +++ b/src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java @@ -15,10 +15,10 @@ public class FormatUtil * * @return the formatter String */ - public static String getNiceUptime() + public static String getNiceTimeDiff(LocalDateTime start) { LocalDateTime now = LocalDateTime.now(); - long uptimeSeconds = ChronoUnit.SECONDS.between(Cache.getStartupTime(), now); + long uptimeSeconds = ChronoUnit.SECONDS.between(start, now); Duration uptime = Duration.ofSeconds(uptimeSeconds); long seconds = uptime.toSecondsPart(); long minutes = uptime.toMinutesPart(); @@ -31,7 +31,7 @@ public class FormatUtil if(hours == 0) { if(minutes == 0) - {} else { + {} else { // i know this if has an empty body but i feel like this reads better uptimeStringBuilder.append(minutes).append("m "); } } else {