Skip to content

Commit f4b5ebf

Browse files
authored
improve suggestion for archived thread due to inactivity (#957)
1 parent 5a23f9d commit f4b5ebf

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package org.togetherjava.tjbot.features.help;
22

3-
import net.dv8tion.jda.api.EmbedBuilder;
43
import net.dv8tion.jda.api.entities.*;
54
import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer;
65
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
76
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
87
import net.dv8tion.jda.api.entities.channel.forums.ForumTag;
98
import net.dv8tion.jda.api.entities.channel.forums.ForumTagSnowflake;
109
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
11-
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
1210
import net.dv8tion.jda.api.interactions.components.buttons.Button;
1311
import net.dv8tion.jda.api.requests.RestAction;
1412
import net.dv8tion.jda.api.requests.restaction.MessageCreateAction;
@@ -104,19 +102,6 @@ public HelpSystemHelper(Config config, Database database, ChatGptService chatGpt
104102
.collect(Collectors.toSet());
105103
}
106104

107-
RestAction<Message> sendExplanationMessage(GuildMessageChannel threadChannel) {
108-
MessageEmbed helpEmbed = new EmbedBuilder()
109-
.setDescription(
110-
"""
111-
If nobody is calling back, that usually means that your question was **not well asked** and \
112-
hence nobody feels confident enough answering. Try to use your time to elaborate, \
113-
**provide details**, context, more code, examples and maybe some screenshots. \
114-
With enough info, someone knows the answer for sure.""")
115-
.build();
116-
117-
return threadChannel.sendMessageEmbeds(helpEmbed);
118-
}
119-
120105
/**
121106
* Determine between the title of the thread and the first message which to send to the AI. It
122107
* uses a simple heuristic of length to determine if enough context exists in a question. If the

application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadAutoArchiver.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.dv8tion.jda.api.EmbedBuilder;
44
import net.dv8tion.jda.api.JDA;
55
import net.dv8tion.jda.api.entities.Guild;
6+
import net.dv8tion.jda.api.entities.Member;
67
import net.dv8tion.jda.api.entities.MessageEmbed;
78
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
89
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
@@ -65,28 +66,52 @@ private void autoArchiveForGuild(Guild guild) {
6566
logger.debug("Found {} active questions", activeThreads.size());
6667

6768
Instant archiveAfterMoment = computeArchiveAfterMoment();
68-
activeThreads
69-
.forEach(activeThread -> autoArchiveForThread(activeThread, archiveAfterMoment));
69+
activeThreads.forEach(activeThread -> autoArchiveForThread(activeThread, archiveAfterMoment,
70+
activeThread.getOwner()));
7071
}
7172

7273
private Instant computeArchiveAfterMoment() {
7374
return Instant.now().minus(ARCHIVE_AFTER_INACTIVITY_OF);
7475
}
7576

76-
private void autoArchiveForThread(ThreadChannel threadChannel, Instant archiveAfterMoment) {
77+
private void autoArchiveForThread(ThreadChannel threadChannel, Instant archiveAfterMoment,
78+
Member author) {
7779
if (shouldBeArchived(threadChannel, archiveAfterMoment)) {
7880
logger.debug("Auto archiving help thread {}", threadChannel.getId());
7981

80-
MessageEmbed embed = new EmbedBuilder().setDescription("""
81-
Closed the thread due to inactivity.
82+
String linkHowToAsk = "https://stackoverflow.com/help/how-to-ask";
8283

83-
If your question was not resolved yet, feel free to just post a message \
84-
to reopen it, or create a new thread. But try to improve the quality of \
85-
your question to make it easier to help you 👍""")
84+
MessageEmbed embed = new EmbedBuilder()
85+
.setDescription(
86+
"""
87+
Your question has been closed due to inactivity.
88+
89+
If it was not resolved yet, feel free to just post a message below
90+
to reopen it, or create a new thread.
91+
92+
Note that usually the reason for nobody calling back is that your
93+
question may have been not well asked and hence no one felt confident
94+
enough answering.
95+
96+
When you reopen the thread, try to use your time to **improve the quality**
97+
of the question by elaborating, providing **details**, context, all relevant code
98+
snippets, any **errors** you are getting, concrete **examples** and perhaps also some
99+
screenshots. Share your **attempt**, explain the **expected results** and compare
100+
them to the current results.
101+
102+
Also try to make the information **easily accessible** by sharing code
103+
or assignment descriptions directly on Discord, not behind a link or
104+
PDF-file; provide some guidance for long code snippets and ensure
105+
the **code is well formatted** and has syntax highlighting. Kindly read through
106+
%s for more.
107+
108+
With enough info, someone knows the answer for sure 👍"""
109+
.formatted(linkHowToAsk))
86110
.setColor(HelpSystemHelper.AMBIENT_COLOR)
87111
.build();
88112

89-
threadChannel.sendMessageEmbeds(embed)
113+
threadChannel.sendMessage(author.getAsMention())
114+
.addEmbeds(embed)
90115
.flatMap(any -> threadChannel.getManager().setArchived(true))
91116
.queue();
92117
}

application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ private RestAction<Void> pinOriginalQuestion(ThreadChannel threadChannel) {
102102
}
103103

104104
private RestAction<Message> createMessages(ThreadChannel threadChannel) {
105-
return sendHelperHeadsUp(threadChannel)
106-
.flatMap(any -> helper.sendExplanationMessage(threadChannel))
107-
.flatMap(any -> createAIResponse(threadChannel));
105+
return sendHelperHeadsUp(threadChannel).flatMap(any -> createAIResponse(threadChannel));
108106
}
109107

110108
private RestAction<Message> sendHelperHeadsUp(ThreadChannel threadChannel) {

0 commit comments

Comments
 (0)