diff --git a/application/config.json.template b/application/config.json.template index 0d3b1af6df..8238dba370 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -8,7 +8,6 @@ "heavyModerationRolePattern": "Moderator", "softModerationRolePattern": "Moderator|Staff Assistant", "tagManageRolePattern": "Moderator|Staff Assistant|Top Helpers .+", - "helpChannelPattern": "([a-zA-Z_]+_)?help(_\\d+)?", "suggestions": { "channelPattern": "tj_suggestions", "upVoteEmoteName": "peepo_yes", diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index 2b67bc6c85..95b69fbcae 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -109,7 +109,7 @@ private boolean handleIsValidTitle(@NotNull CharSequence title, @NotNull IReplyC } event.reply( - "Sorry, but the titel length (after removal of special characters) has to be between %d and %d." + "Sorry, but the title length (after removal of special characters) has to be between %d and %d." .formatted(TITLE_COMPACT_LENGTH_MIN, TITLE_COMPACT_LENGTH_MAX)) .setEphemeral(true) .queue(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/BotMessageCleanup.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/BotMessageCleanup.java index d3c90980b4..5678072773 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/BotMessageCleanup.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/BotMessageCleanup.java @@ -108,11 +108,14 @@ private static boolean shouldMessageBeCleanedUp(@NotNull Message message) { private static @NotNull RestAction cleanupBotMessages( @NotNull GuildMessageChannel channel, @NotNull Collection messages) { + logger.debug("Cleaning up old bot messages in the staging channel"); List messageIdsToDelete = messages.stream() .filter(BotMessageCleanup::shouldMessageBeCleanedUp) .map(Message::getId) .toList(); + logger.debug("Found {} messages to delete", messageIdsToDelete.size()); + if (messageIdsToDelete.isEmpty()) { return new CompletedRestAction<>(channel.getJDA(), null, null); } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpSystemHelper.java index 41fa901cc3..d30c8c8000 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpSystemHelper.java @@ -85,7 +85,7 @@ RestAction sendExplanationMessage(@NotNull MessageChannel threadChannel If nobody is calling back, that usually means that your question was **not well asked** and \ hence nobody feels confident enough answering. Try to use your time to elaborate, \ **provide details**, context, more code, examples and maybe some screenshots. \ - With enough info, someone knows the answer for sure .""")); + With enough info, someone knows the answer for sure.""")); MessageAction action = threadChannel.sendMessage(message); if (useCodeSyntaxExampleImage) { diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadOverviewUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadOverviewUpdater.java index ee947e2f56..3ffe0b6396 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadOverviewUpdater.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadOverviewUpdater.java @@ -32,6 +32,7 @@ public final class HelpThreadOverviewUpdater extends MessageReceiverAdapter impl private static final Logger logger = LoggerFactory.getLogger(HelpThreadOverviewUpdater.class); private static final String STATUS_TITLE = "Active questions"; + private static final int OVERVIEW_QUESTION_LIMIT = 150; private final HelpSystemHelper helper; private final List allCategories; @@ -121,17 +122,22 @@ private void updateOverviewForGuild(@NotNull Guild guild) { private void updateOverview(@NotNull IThreadContainer stagingChannel, @NotNull MessageChannel overviewChannel) { + logger.debug("Updating overview of active questions"); + List activeThreads = stagingChannel.getThreadChannels() .stream() .filter(Predicate.not(ThreadChannel::isArchived)) .toList(); + logger.debug("Found {} active questions", activeThreads.size()); + MessageEmbed embed = new EmbedBuilder().setTitle(STATUS_TITLE) .setDescription(createDescription(activeThreads)) .setColor(HelpSystemHelper.AMBIENT_COLOR) .build(); getStatusMessage(overviewChannel).flatMap(maybeStatusMessage -> { + logger.debug("Sending the updated question overview"); if (maybeStatusMessage.isEmpty()) { return overviewChannel.sendMessageEmbeds(embed); } @@ -148,6 +154,7 @@ private void updateOverview(@NotNull IThreadContainer stagingChannel, return activeThreads.stream() .sorted(Comparator.comparing(ThreadChannel::getTimeCreated).reversed()) + .limit(OVERVIEW_QUESTION_LIMIT) .collect(Collectors .groupingBy(thread -> helper.getCategoryOfChannel(thread).orElse("Uncategorized"))) .entrySet() diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java b/application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java index 11705448d8..b6847bc882 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java @@ -92,14 +92,19 @@ public BotCore(@NotNull JDA jda, @NotNull Database database, @NotNull Config con .filter(Routine.class::isInstance) .map(Routine.class::cast) .forEach(routine -> { + Runnable command = () -> { + String routineName = routine.getClass().getSimpleName(); + logger.debug("Running routine %s...".formatted(routineName)); + routine.runRoutine(jda); + logger.debug("Finished routine %s.".formatted(routineName)); + }; + Routine.Schedule schedule = routine.createSchedule(); switch (schedule.mode()) { - case FIXED_RATE -> ROUTINE_SERVICE.scheduleAtFixedRate( - () -> routine.runRoutine(jda), schedule.initialDuration(), - schedule.duration(), schedule.unit()); - case FIXED_DELAY -> ROUTINE_SERVICE.scheduleWithFixedDelay( - () -> routine.runRoutine(jda), schedule.initialDuration(), - schedule.duration(), schedule.unit()); + case FIXED_RATE -> ROUTINE_SERVICE.scheduleAtFixedRate(command, + schedule.initialDuration(), schedule.duration(), schedule.unit()); + case FIXED_DELAY -> ROUTINE_SERVICE.scheduleWithFixedDelay(command, + schedule.initialDuration(), schedule.duration(), schedule.unit()); default -> throw new AssertionError("Unsupported schedule mode"); } }); diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index 73534bb24e..fb4ef623b8 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -22,7 +22,6 @@ public final class Config { private final String heavyModerationRolePattern; private final String softModerationRolePattern; private final String tagManageRolePattern; - private final String helpChannelPattern; private final SuggestionsConfig suggestions; private final String quarantinedRolePattern; private final ScamBlockerConfig scamBlocker; @@ -40,7 +39,6 @@ private Config(@JsonProperty("token") String token, @JsonProperty("heavyModerationRolePattern") String heavyModerationRolePattern, @JsonProperty("softModerationRolePattern") String softModerationRolePattern, @JsonProperty("tagManageRolePattern") String tagManageRolePattern, - @JsonProperty("helpChannelPattern") String helpChannelPattern, @JsonProperty("suggestions") SuggestionsConfig suggestions, @JsonProperty("quarantinedRolePattern") String quarantinedRolePattern, @JsonProperty("scamBlocker") ScamBlockerConfig scamBlocker, @@ -55,7 +53,6 @@ private Config(@JsonProperty("token") String token, this.heavyModerationRolePattern = heavyModerationRolePattern; this.softModerationRolePattern = softModerationRolePattern; this.tagManageRolePattern = tagManageRolePattern; - this.helpChannelPattern = helpChannelPattern; this.suggestions = suggestions; this.quarantinedRolePattern = quarantinedRolePattern; this.scamBlocker = scamBlocker; @@ -160,16 +157,6 @@ public String getTagManageRolePattern() { return tagManageRolePattern; } - /** - * Gets the REGEX pattern used to identify channels that are used for helping people with their - * questions. - * - * @return the channel name pattern - */ - public @NotNull String getHelpChannelPattern() { - return helpChannelPattern; - } - /** * Gets the config for the suggestion system. * diff --git a/settings.gradle b/settings.gradle index 1dd56827f2..811b17ba0f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,4 +3,6 @@ rootProject.name = 'TJ-Bot' include 'application' include 'database' include 'formatter' -include 'logviewer' +// NOTE The logviewer does not properly work as of today. +// But it is causing major build slowdowns, so we exclude it for the time being. +// include 'logviewer'