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 2b0c253e09..197cebde08 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 @@ -129,7 +129,9 @@ private RestAction handleEvent(InteractionHook eventHook, ThreadChannel return sendInitialMessage(guild, threadChannel, author, title, category) .flatMap(Message::pin) .flatMap(any -> notifyUser(eventHook, threadChannel)) - .flatMap(any -> helper.sendExplanationMessage(threadChannel)); + .flatMap(any -> helper.sendExplanationMessage(threadChannel)) + .onSuccess(any -> helper.scheduleNoActivityAdviceCheck(threadChannel.getIdLong(), + author.getIdLong())); } private RestAction sendInitialMessage(Guild guild, ThreadChannel threadChannel, 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 9f622837b1..078a8ee4e0 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 @@ -64,7 +64,8 @@ public final class HelpSystemHelper { private static final ScheduledExecutorService SERVICE = Executors.newScheduledThreadPool(3); private static final int SEND_UNCATEGORIZED_ADVICE_AFTER_MINUTES = 5; - + private static final int SEND_NO_ACTIVITY_ADVICE_AFTER_MINUTES = 5; + public static final int MAX_MESSAGES_TO_LOOK_BACK = 10; private final Predicate isOverviewChannelName; private final String overviewChannelPattern; private final Predicate isStagingChannelName; @@ -333,6 +334,61 @@ private void executeUncategorizedAdviceCheck(long threadChannelId, long authorId }).queue(); } + void scheduleNoActivityAdviceCheck(long threadChannelId, long authorId) { + SERVICE.schedule(() -> { + try { + executeNoActivityAdviceCheck(threadChannelId, authorId); + } catch (Exception e) { + logger.warn( + "Unknown error during a no activity advice check on thread {} by author {}.", + threadChannelId, authorId, e); + } + }, SEND_NO_ACTIVITY_ADVICE_AFTER_MINUTES, TimeUnit.MINUTES); + } + + private void executeNoActivityAdviceCheck(long threadChannelId, long authorId) { + logger.debug("Executing no activity advice check for thread {} by author {}.", + threadChannelId, authorId); + + ThreadChannel threadChannel = jda.getThreadChannelById(threadChannelId); + if (threadChannel == null) { + logger.debug( + "Channel for no activity advice check seems to be deleted (thread {} by author {}).", + threadChannelId, authorId); + return; + } + + if (threadChannel.isArchived()) { + logger.debug( + "Channel for no activity advice check is archived already (thread {} by author {}).", + threadChannelId, authorId); + return; + } + if (hasNoAuthorActivity(authorId, threadChannel)) { + MessageEmbed embed = HelpSystemHelper.embedWith( + """ + Hey there %s👋 It has been a bit after you created this thread and you still did not share any details of your question. + Helpers have seen your question already and are just waiting for you to elaborate on your problem and provide detailed information on it 👌 + """ + .formatted(User.fromId(authorId).getAsMention())); + threadChannel.sendMessageEmbeds(embed).queue(); + } + } + + private static boolean hasNoAuthorActivity(long authorId, ThreadChannel threadChannel) { + int messagesFromOthers = 0; + for (Message message : threadChannel.getIterableHistory()) { + if (messagesFromOthers == MAX_MESSAGES_TO_LOOK_BACK) { + return false; + } + if (message.getAuthor().getIdLong() == authorId) { + return false; + } + messagesFromOthers++; + } + return true; + } + record HelpThreadName(@Nullable ThreadActivity activity, @Nullable String category, String title) { static HelpThreadName ofChannelName(CharSequence channelName) { diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/ImplicitAskListener.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/ImplicitAskListener.java index 22ad2eca3f..75d1674856 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/ImplicitAskListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/ImplicitAskListener.java @@ -170,6 +170,8 @@ private RestAction handleEvent(ThreadChannel threadChannel, Message message, .flatMap(any -> message.delete()) .flatMap(any -> helper.sendExplanationMessage(threadChannel)) .onSuccess(any -> helper.scheduleUncategorizedAdviceCheck(threadChannel.getIdLong(), + author.getIdLong())) + .onSuccess(any -> helper.scheduleNoActivityAdviceCheck(threadChannel.getIdLong(), author.getIdLong())); }