Skip to content

Commit 6148823

Browse files
committed
Added more logging
1 parent 806ff68 commit 6148823

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

application/src/main/java/org/togetherjava/tjbot/commands/help/BotMessageCleanup.java

+3
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,14 @@ private static boolean shouldMessageBeCleanedUp(@NotNull Message message) {
108108

109109
private static @NotNull RestAction<Void> cleanupBotMessages(
110110
@NotNull GuildMessageChannel channel, @NotNull Collection<? extends Message> messages) {
111+
logger.debug("Cleaning up old bot messages in the staging channel");
111112
List<String> messageIdsToDelete = messages.stream()
112113
.filter(BotMessageCleanup::shouldMessageBeCleanedUp)
113114
.map(Message::getId)
114115
.toList();
115116

117+
logger.debug("Found {} messages to delete", messageIdsToDelete.size());
118+
116119
if (messageIdsToDelete.isEmpty()) {
117120
return new CompletedRestAction<>(channel.getJDA(), null, null);
118121
}

application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadOverviewUpdater.java

+5
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,22 @@ private void updateOverviewForGuild(@NotNull Guild guild) {
122122

123123
private void updateOverview(@NotNull IThreadContainer stagingChannel,
124124
@NotNull MessageChannel overviewChannel) {
125+
logger.debug("Updating overview of active questions");
126+
125127
List<ThreadChannel> activeThreads = stagingChannel.getThreadChannels()
126128
.stream()
127129
.filter(Predicate.not(ThreadChannel::isArchived))
128130
.toList();
129131

132+
logger.debug("Found {} active questions", activeThreads.size());
133+
130134
MessageEmbed embed = new EmbedBuilder().setTitle(STATUS_TITLE)
131135
.setDescription(createDescription(activeThreads))
132136
.setColor(HelpSystemHelper.AMBIENT_COLOR)
133137
.build();
134138

135139
getStatusMessage(overviewChannel).flatMap(maybeStatusMessage -> {
140+
logger.debug("Sending the updated question overview");
136141
if (maybeStatusMessage.isEmpty()) {
137142
return overviewChannel.sendMessageEmbeds(embed);
138143
}

application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,19 @@ public BotCore(@NotNull JDA jda, @NotNull Database database, @NotNull Config con
9292
.filter(Routine.class::isInstance)
9393
.map(Routine.class::cast)
9494
.forEach(routine -> {
95+
Runnable command = () -> {
96+
String routineName = routine.getClass().getSimpleName();
97+
logger.debug("Running routine %s...".formatted(routineName));
98+
routine.runRoutine(jda);
99+
logger.debug("Finished routine %s.".formatted(routineName));
100+
};
101+
95102
Routine.Schedule schedule = routine.createSchedule();
96103
switch (schedule.mode()) {
97-
case FIXED_RATE -> ROUTINE_SERVICE.scheduleAtFixedRate(
98-
() -> routine.runRoutine(jda), schedule.initialDuration(),
99-
schedule.duration(), schedule.unit());
100-
case FIXED_DELAY -> ROUTINE_SERVICE.scheduleWithFixedDelay(
101-
() -> routine.runRoutine(jda), schedule.initialDuration(),
102-
schedule.duration(), schedule.unit());
104+
case FIXED_RATE -> ROUTINE_SERVICE.scheduleAtFixedRate(command,
105+
schedule.initialDuration(), schedule.duration(), schedule.unit());
106+
case FIXED_DELAY -> ROUTINE_SERVICE.scheduleWithFixedDelay(command,
107+
schedule.initialDuration(), schedule.duration(), schedule.unit());
103108
default -> throw new AssertionError("Unsupported schedule mode");
104109
}
105110
});

0 commit comments

Comments
 (0)