Add bot age info
This commit is contained in:
parent
7ac72f9e38
commit
52fe279f35
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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<String> getCommandLabels() {
|
||||
return new LinkedList<>(Collections.singletonList("botinfo"));
|
||||
return new LinkedList<>(Arrays.asList("botinfo", "info"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user