Skip to content

Commit 87461c3

Browse files
committed
changes
* requested changes * update config to include tagsToIgnore * refactor tag update logic * update sql script * add tagsToIgnore list to config
1 parent 6d2848e commit 87461c3

File tree

6 files changed

+72
-15
lines changed

6 files changed

+72
-15
lines changed

application/config.json.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"Together Java Bot",
4646
"Other"
4747
],
48-
"categoryRoleSuffix": " - Helper"
48+
"categoryRoleSuffix": " - Helper",
49+
"tagsToIgnore": ["Nobody helped yet", "Needs attention", "Active"]
4950
},
5051
"mediaOnlyChannelPattern": "memes",
5152
"blacklistedFileExtension": [

application/src/main/java/org/togetherjava/tjbot/config/HelpSystemConfig.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ public final class HelpSystemConfig {
1818
private final String helpForumPattern;
1919
private final List<String> categories;
2020
private final String categoryRoleSuffix;
21+
private final List<String> tagsToIgnore;
2122

2223
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
2324
private HelpSystemConfig(
2425
@JsonProperty(value = "helpForumPattern", required = true) String helpForumPattern,
2526
@JsonProperty(value = "categories", required = true) List<String> categories,
26-
@JsonProperty(value = "categoryRoleSuffix",
27-
required = true) String categoryRoleSuffix) {
27+
@JsonProperty(value = "categoryRoleSuffix", required = true) String categoryRoleSuffix,
28+
@JsonProperty(value = "tagsToIgnore", required = true) List<String> tagsToIgnore) {
2829
this.helpForumPattern = Objects.requireNonNull(helpForumPattern);
2930
this.categories = new ArrayList<>(Objects.requireNonNull(categories));
3031
this.categoryRoleSuffix = Objects.requireNonNull(categoryRoleSuffix);
32+
this.tagsToIgnore = new ArrayList<>(Objects.requireNonNull(tagsToIgnore));
3133
}
3234

3335
/**
@@ -62,4 +64,13 @@ public List<String> getCategories() {
6264
public String getCategoryRoleSuffix() {
6365
return categoryRoleSuffix;
6466
}
67+
68+
/**
69+
* Retrieves all tags that needs to be ignored during collection of meta data in
70+
* {@link org.togetherjava.tjbot.features.help.HelpThreadLifecycleListener} and
71+
* {@link org.togetherjava.tjbot.features.help.HelpThreadCreatedListener}
72+
*/
73+
public List<String> getTagsToIgnore() {
74+
return tagsToIgnore;
75+
}
6576
}

application/src/main/java/org/togetherjava/tjbot/features/Features.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import org.togetherjava.tjbot.features.help.HelpThreadCreatedListener;
3232
import org.togetherjava.tjbot.features.help.HelpThreadMetadataPurger;
3333
import org.togetherjava.tjbot.features.help.PinnedNotificationRemover;
34+
import org.togetherjava.tjbot.features.help.HelpThreadLifecycleListener;
35+
import org.togetherjava.tjbot.features.help.MarkHelpThreadCloseInDBRoutine;
3436
import org.togetherjava.tjbot.features.javamail.RSSHandlerRoutine;
3537
import org.togetherjava.tjbot.features.jshell.JShellCommand;
3638
import org.togetherjava.tjbot.features.jshell.JShellEval;

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import org.togetherjava.tjbot.features.chatgpt.ChatGptService;
2929
import org.togetherjava.tjbot.features.componentids.ComponentIdInteractor;
3030

31-
import java.time.Instant;
3231
import java.awt.Color;
32+
import java.time.Instant;
3333
import java.util.ArrayList;
3434
import java.util.Arrays;
3535
import java.util.Collection;
@@ -67,6 +67,8 @@ public final class HelpSystemHelper {
6767
private final Set<String> categories;
6868
private final Set<String> threadActivityTagNames;
6969
private final String categoryRoleSuffix;
70+
71+
private final Set<String> tagsToIgnore;
7072
private final Database database;
7173
private final ChatGptService chatGptService;
7274
private static final int MAX_QUESTION_LENGTH = 200;
@@ -105,6 +107,10 @@ public HelpSystemHelper(Config config, Database database, ChatGptService chatGpt
105107
threadActivityTagNames = Arrays.stream(ThreadActivity.values())
106108
.map(ThreadActivity::getTagName)
107109
.collect(Collectors.toSet());
110+
111+
List<String> tagsToIgnoreList = helpConfig.getTagsToIgnore();
112+
tagsToIgnore = new HashSet<>(tagsToIgnoreList);
113+
108114
}
109115

110116
/**
@@ -224,8 +230,12 @@ private RestAction<Message> useChatGptFallbackMessage(ThreadChannel threadChanne
224230
void writeHelpThreadToDatabase(long authorId, ThreadChannel threadChannel) {
225231

226232
Instant createdAt = threadChannel.getTimeCreated().toInstant();
227-
List<String> tagsList =
228-
threadChannel.getAppliedTags().stream().map(ForumTag::getName).toList();
233+
234+
List<String> tagsList = threadChannel.getAppliedTags()
235+
.stream()
236+
.filter(this::shouldIgnoreTag)
237+
.map(ForumTag::getName)
238+
.toList();
229239

230240
String tags = String.join(", ", tagsList);
231241

@@ -234,7 +244,7 @@ void writeHelpThreadToDatabase(long authorId, ThreadChannel threadChannel) {
234244
.setAuthorId(authorId)
235245
.setChannelId(threadChannel.getIdLong())
236246
.setCreatedAt(createdAt)
237-
.setTag(tags)
247+
.setTags(tags)
238248
.setTicketStatus(TicketStatus.ACTIVE.val);
239249
if (helpThreadsRecord.update() == 0) {
240250
helpThreadsRecord.insert();
@@ -405,4 +415,15 @@ Optional<Long> getAuthorByHelpThreadId(final long channelId) {
405415
.where(HelpThreads.HELP_THREADS.CHANNEL_ID.eq(channelId))
406416
.fetchOptional(HelpThreads.HELP_THREADS.AUTHOR_ID));
407417
}
418+
419+
420+
/**
421+
* will be used to filter a tag based on tagsToIgnore config list
422+
*
423+
* @param tag applied tag
424+
* @return boolean result whether to ignore this tag or not
425+
*/
426+
boolean shouldIgnoreTag(ForumTag tag) {
427+
return !this.tagsToIgnore.contains(tag.getName());
428+
}
408429
}

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.togetherjava.tjbot.features.help;
22

33
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
4+
import net.dv8tion.jda.api.entities.channel.forums.ForumTag;
45
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateAppliedTagsEvent;
56
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateArchivedEvent;
67
import net.dv8tion.jda.api.hooks.ListenerAdapter;
@@ -12,6 +13,7 @@
1213
import org.togetherjava.tjbot.features.EventReceiver;
1314

1415
import java.time.Instant;
16+
import java.util.List;
1517

1618
import static org.togetherjava.tjbot.db.generated.tables.HelpThreads.HELP_THREADS;
1719

@@ -38,9 +40,6 @@ public HelpThreadLifecycleListener(HelpSystemHelper helper, Database database) {
3840

3941
@Override
4042
public void onChannelUpdateArchived(@NotNull ChannelUpdateArchivedEvent event) {
41-
if (!event.getChannelType().isThread()) {
42-
return;
43-
}
4443
ThreadChannel threadChannel = event.getChannel().asThreadChannel();
4544

4645
if (!helper.isHelpForumName(threadChannel.getParentChannel().getName())) {
@@ -53,14 +52,22 @@ public void onChannelUpdateArchived(@NotNull ChannelUpdateArchivedEvent event) {
5352
public void onChannelUpdateAppliedTags(@NotNull ChannelUpdateAppliedTagsEvent event) {
5453
ThreadChannel threadChannel = event.getChannel().asThreadChannel();
5554

56-
if (!helper.isHelpForumName(threadChannel.getParentChannel().getName())) {
55+
if (!helper.isHelpForumName(threadChannel.getParentChannel().getName())
56+
|| shouldIgnoreUpdatedTagEvent(event)) {
5757
return;
5858
}
5959

60-
String updatedTag = event.getAddedTags().getFirst().getName();
60+
61+
List<String> updatedTagList = threadChannel.getAppliedTags()
62+
.stream()
63+
.filter(helper::shouldIgnoreTag)
64+
.map(ForumTag::getName)
65+
.toList();
66+
String tags = String.join(", ", updatedTagList);
67+
6168
long threadId = threadChannel.getIdLong();
6269

63-
handleTagsUpdate(threadId, updatedTag);
70+
handleTagsUpdate(threadId, tags);
6471
}
6572

6673
private void handleThreadStatus(ThreadChannel threadChannel) {
@@ -103,10 +110,25 @@ private void updateThreadStatusToActive(long threadId) {
103110

104111
private void handleTagsUpdate(long threadId, String updatedTag) {
105112
database.write(context -> context.update(HELP_THREADS)
106-
.set(HELP_THREADS.TAG, updatedTag)
113+
.set(HELP_THREADS.TAGS, updatedTag)
107114
.where(HELP_THREADS.CHANNEL_ID.eq(threadId))
108115
.execute());
109116

110117
logger.info("Updated tag for thread with id: {} in database", threadId);
111118
}
119+
120+
/**
121+
* will ignore updated tag event if all new tags belong to tagsToIgnore config list
122+
*
123+
* @param event updated tags event
124+
* @return boolean
125+
*/
126+
private boolean shouldIgnoreUpdatedTagEvent(ChannelUpdateAppliedTagsEvent event) {
127+
List<String> newTags = event.getNewTags()
128+
.stream()
129+
.filter(helper::shouldIgnoreTag)
130+
.map(ForumTag::getName)
131+
.toList();
132+
return newTags.isEmpty();
133+
}
112134
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ALTER TABLE help_threads ADD ticket_status INTEGER DEFAULT 0;
2-
ALTER TABLE help_threads ADD tag TEXT DEFAULT 'none';
2+
ALTER TABLE help_threads ADD tags TEXT DEFAULT 'none';
33
ALTER TABLE help_threads ADD closed_at TIMESTAMP NULL;
44
ALTER TABLE help_threads ADD participants INTEGER DEFAULT 1;
55
ALTER TABLE help_threads ADD message_count INTEGER DEFAULT 0;

0 commit comments

Comments
 (0)