diff --git a/app/src/main/java/xyz/vallat/louis/App.java b/app/src/main/java/xyz/vallat/louis/App.java index cfd01aa..ab0bae9 100644 --- a/app/src/main/java/xyz/vallat/louis/App.java +++ b/app/src/main/java/xyz/vallat/louis/App.java @@ -11,7 +11,7 @@ public class App { public static final String PREFIX = "+"; public static final String NAME = "PrésencEirb"; public static final String DESCRIPTION = "Tu as pensé à pointer ?"; - public static final String VERSION = "0.3-SNAPSHOT"; + public static final String VERSION = "0.3.2-SNAPSHOT"; private static final Logger logger = LoggerFactory.getLogger(App.class.getCanonicalName()); public static void main(String[] args) { diff --git a/app/src/main/java/xyz/vallat/louis/commands/Version.java b/app/src/main/java/xyz/vallat/louis/commands/Version.java index ec64c66..336ae92 100644 --- a/app/src/main/java/xyz/vallat/louis/commands/Version.java +++ b/app/src/main/java/xyz/vallat/louis/commands/Version.java @@ -4,7 +4,9 @@ import discord4j.core.event.domain.message.MessageCreateEvent; import discord4j.rest.util.Color; import reactor.core.publisher.Mono; import xyz.vallat.louis.App; +import xyz.vallat.louis.managers.database.StudentManager; import xyz.vallat.louis.managers.discord.DiscordManager; +import xyz.vallat.louis.timer.TimerManager; import java.time.Instant; @@ -21,8 +23,12 @@ public class Version extends Command { .setTitle(App.NAME) .setDescription(App.DESCRIPTION) .setUrl("https://gitlab.com/lovallat/presenceirb") - .setTimestamp(Instant.now()) - .addField("Version", App.VERSION, false); + .addField("Au service de", StudentManager.getStudentsFromDatabase().size() + " étudiants", false) + .addField("Évènements programmés", String.valueOf(TimerManager.getTotalProgrammedEvents()), false); + if (event.getMessage().getAuthor().isPresent()) + embed.addField("Vos évènements programmés", + String.valueOf(TimerManager.getStudentsProgrammedEvents(event.getMessage().getAuthor().get().getId().asString())), false); + embed.setTimestamp(Instant.now()).addField("Version", App.VERSION, false); String imageURL = DiscordManager.getClientImage().block(); if (imageURL != null) embed.setThumbnail(imageURL); })).then().onErrorResume(t -> fatalError(event, t)); diff --git a/app/src/main/java/xyz/vallat/louis/timer/TimerManager.java b/app/src/main/java/xyz/vallat/louis/timer/TimerManager.java index 0bf8885..08df7b3 100644 --- a/app/src/main/java/xyz/vallat/louis/timer/TimerManager.java +++ b/app/src/main/java/xyz/vallat/louis/timer/TimerManager.java @@ -34,6 +34,7 @@ public final class TimerManager { midday.set(Calendar.HOUR, 1); midday.set(Calendar.MINUTE, 30); midday.set(Calendar.SECOND, 0); + if (midday.getTime().before(Calendar.getInstance().getTime())) midday.add(Calendar.HOUR, 12); Timer reimportCron = new Timer(); reimportCron.schedule(new AutoReimport(), midday.getTime(), @@ -48,6 +49,7 @@ public final class TimerManager { logger.debug("Stopping all {} timers for student '{}'.", entry.getValue().size(), entry.getKey()); for (Timer t : entry.getValue()) t.cancel(); } + studentsTimers.clear(); logger.debug("Done stopping all timers."); } @@ -80,4 +82,14 @@ public final class TimerManager { } logger.debug("All {} timers have been started.", timerStarted); } + + public static int getTotalProgrammedEvents() { + int total = 0; + for (Map.Entry> e : studentsTimers.entrySet()) total += e.getValue().size(); + return total; + } + + public static int getStudentsProgrammedEvents(String snowflake) { + return studentsTimers.getOrDefault(snowflake, new ArrayList<>()).size(); + } } diff --git a/app/src/main/java/xyz/vallat/louis/timer/tasks/AutoReimport.java b/app/src/main/java/xyz/vallat/louis/timer/tasks/AutoReimport.java index 9080d84..b147c8b 100644 --- a/app/src/main/java/xyz/vallat/louis/timer/tasks/AutoReimport.java +++ b/app/src/main/java/xyz/vallat/louis/timer/tasks/AutoReimport.java @@ -13,6 +13,7 @@ public class AutoReimport extends TimerTask { @Override public void run() { logger.info("Reimporting all events."); - logger.info("Done reimporting {} events.", EventManager.reimportAllEvents()); + int eventsImported = EventManager.reimportAllEvents(); + logger.info("Done reimporting {} events.", eventsImported); } }