Move uptime string generator to config class
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
6998cc92e5
commit
cdc45d62f2
@ -6,7 +6,9 @@ import wtf.beatrice.hidekobot.database.DatabaseManager;
|
|||||||
import wtf.beatrice.hidekobot.listeners.MessageLogger;
|
import wtf.beatrice.hidekobot.listeners.MessageLogger;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -211,4 +213,43 @@ public class Configuration
|
|||||||
*/
|
*/
|
||||||
public static LocalDateTime getStartupTime() { return startupTime; }
|
public static LocalDateTime getStartupTime() { return startupTime; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a nicely formatted uptime String that omits unnecessary data
|
||||||
|
* (eg. 0 days, 0 hours, 4 minutes, 32 seconds -> 4m 32s)
|
||||||
|
*
|
||||||
|
* @return the formatter String
|
||||||
|
*/
|
||||||
|
public static String getNiceUptime()
|
||||||
|
{
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
long uptimeSeconds = ChronoUnit.SECONDS.between(Configuration.getStartupTime(), now);
|
||||||
|
Duration uptime = Duration.ofSeconds(uptimeSeconds);
|
||||||
|
long seconds = uptime.toSecondsPart();
|
||||||
|
long minutes = uptime.toMinutesPart();
|
||||||
|
long hours = uptime.toHoursPart();
|
||||||
|
long days = uptime.toDays();
|
||||||
|
|
||||||
|
StringBuilder uptimeStringBuilder = new StringBuilder();
|
||||||
|
if(days == 0)
|
||||||
|
{
|
||||||
|
if(hours == 0)
|
||||||
|
{
|
||||||
|
if(minutes == 0)
|
||||||
|
{} else {
|
||||||
|
uptimeStringBuilder.append(minutes).append("m ");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uptimeStringBuilder.append(hours).append("h ");
|
||||||
|
uptimeStringBuilder.append(minutes).append("m ");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uptimeStringBuilder.append(days).append("d ");
|
||||||
|
uptimeStringBuilder.append(hours).append("h ");
|
||||||
|
uptimeStringBuilder.append(minutes).append("m ");
|
||||||
|
}
|
||||||
|
uptimeStringBuilder.append(seconds).append("s ");
|
||||||
|
|
||||||
|
return uptimeStringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -74,35 +74,7 @@ public class BotInfoCommand
|
|||||||
embedBuilder.addField("Author", authorMention, true);
|
embedBuilder.addField("Author", authorMention, true);
|
||||||
|
|
||||||
// uptime field
|
// uptime field
|
||||||
LocalDateTime now = LocalDateTime.now();
|
embedBuilder.addField("Uptime", Configuration.getNiceUptime(), true);
|
||||||
long uptimeSeconds = ChronoUnit.SECONDS.between(Configuration.getStartupTime(), now);
|
|
||||||
Duration uptime = Duration.ofSeconds(uptimeSeconds);
|
|
||||||
long seconds = uptime.toSecondsPart();
|
|
||||||
long minutes = uptime.toMinutesPart();
|
|
||||||
long hours = uptime.toHoursPart();
|
|
||||||
long days = uptime.toDays();
|
|
||||||
|
|
||||||
StringBuilder uptimeStringBuilder = new StringBuilder();
|
|
||||||
if(days == 0)
|
|
||||||
{
|
|
||||||
if(hours == 0)
|
|
||||||
{
|
|
||||||
if(minutes == 0)
|
|
||||||
{} else {
|
|
||||||
uptimeStringBuilder.append(minutes).append("m ");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
uptimeStringBuilder.append(hours).append("h ");
|
|
||||||
uptimeStringBuilder.append(minutes).append("m ");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
uptimeStringBuilder.append(days).append("d ");
|
|
||||||
uptimeStringBuilder.append(hours).append("h ");
|
|
||||||
uptimeStringBuilder.append(minutes).append("m ");
|
|
||||||
}
|
|
||||||
uptimeStringBuilder.append(seconds).append("s ");
|
|
||||||
|
|
||||||
embedBuilder.addField("Uptime", uptimeStringBuilder.toString(), true);
|
|
||||||
|
|
||||||
// issue tracker field
|
// issue tracker field
|
||||||
embedBuilder.addField("Support",
|
embedBuilder.addField("Support",
|
||||||
|
Loading…
Reference in New Issue
Block a user