From 744d8168d98dda9354ad6b022d4dab05bf06e45c Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Sun, 17 Dec 2023 17:37:06 +0530 Subject: [PATCH 01/27] alter help_thread table to add more meta data --- .../src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 application/src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql diff --git a/application/src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql b/application/src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql new file mode 100644 index 0000000000..12ed8850b1 --- /dev/null +++ b/application/src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql @@ -0,0 +1,3 @@ +ALTER TABLE help_threads ADD ticket_status INTEGER DEFAULT 0; +ALTER TABLE help_threads ADD tag TEXT DEFAULT 'none'; +ALTER TABLE help_threads ADD closed_at TIMESTAMP NULL; \ No newline at end of file From bc3fab1bdbce5b6463fc0cffd83279a91c26514a Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Sun, 17 Dec 2023 17:57:04 +0530 Subject: [PATCH 02/27] update write operation with extra fields --- .../tjbot/features/help/HelpSystemHelper.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java index aa64f10dcc..20d7f01b34 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java @@ -24,6 +24,7 @@ import org.togetherjava.tjbot.features.componentids.ComponentIdInteractor; import java.awt.*; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -202,11 +203,17 @@ private RestAction useChatGptFallbackMessage(ThreadChannel threadChanne } void writeHelpThreadToDatabase(long authorId, ThreadChannel threadChannel) { + + Instant createdAt = Instant.now(); + String tag = threadChannel.getAppliedTags().get(0).getName(); + database.write(content -> { HelpThreadsRecord helpThreadsRecord = content.newRecord(HelpThreads.HELP_THREADS) .setAuthorId(authorId) .setChannelId(threadChannel.getIdLong()) - .setCreatedAt(threadChannel.getTimeCreated().toInstant()); + .setCreatedAt(createdAt) + .setTag(tag) + .setTicketStatus(TicketStatus.ACTIVE.val); if (helpThreadsRecord.update() == 0) { helpThreadsRecord.insert(); } @@ -355,4 +362,15 @@ public String getTagName() { return tagName; } } + + enum TicketStatus { + ARCHIVED(0), + ACTIVE(1); + + private final int val; + + TicketStatus(int val) { + this.val = val; + } + } } From 0f5e116bd285d78ddf0e075ca280206da2915fc0 Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Sun, 17 Dec 2023 21:54:15 +0530 Subject: [PATCH 03/27] listener that updates meta data based on thread status --- .../togetherjava/tjbot/features/Features.java | 1 + .../tjbot/features/help/HelpSystemHelper.java | 2 +- .../help/HelpThreadArchivedListener.java | 80 +++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java diff --git a/application/src/main/java/org/togetherjava/tjbot/features/Features.java b/application/src/main/java/org/togetherjava/tjbot/features/Features.java index 67502eca2c..ad88e59fbd 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/Features.java @@ -125,6 +125,7 @@ public static Collection createFeatures(JDA jda, Database database, Con features.add(new GuildLeaveCloseThreadListener(config)); features.add(new LeftoverBookmarksListener(bookmarksSystem)); features.add(new HelpThreadCreatedListener(helpSystemHelper)); + features.add(new HelpThreadArchivedListener(helpSystemHelper, database)); // Message context commands features.add(new TransferQuestionCommand(config)); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java index 20d7f01b34..443fc4c82f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java @@ -367,7 +367,7 @@ enum TicketStatus { ARCHIVED(0), ACTIVE(1); - private final int val; + final int val; TicketStatus(int val) { this.val = val; diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java new file mode 100644 index 0000000000..8f25c6699c --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java @@ -0,0 +1,80 @@ +package org.togetherjava.tjbot.features.help; + +import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; +import net.dv8tion.jda.api.events.channel.update.ChannelUpdateArchivedEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.togetherjava.tjbot.db.Database; +import org.togetherjava.tjbot.features.EventReceiver; + +import java.time.Instant; + +import static org.togetherjava.tjbot.db.generated.tables.HelpThreads.HELP_THREADS; + +public final class HelpThreadArchivedListener extends ListenerAdapter implements EventReceiver { + + private final HelpSystemHelper helper; + private final Logger logger = LoggerFactory.getLogger(HelpThreadArchivedListener.class); + private final Database database; + + /** + * Creates a new instance. + * + * @param helper to work with the help threads + */ + public HelpThreadArchivedListener(HelpSystemHelper helper, Database database) { + this.helper = helper; + this.database = database; + } + + @Override + public void onChannelUpdateArchived(@NotNull ChannelUpdateArchivedEvent event) { + if (!event.getChannelType().isThread()) { + return; + } + ThreadChannel threadChannel = event.getChannel().asThreadChannel(); + + + if (!helper.isHelpForumName(threadChannel.getParentChannel().getName())) { + return; + } + handleThreadStatus(threadChannel); + } + + private void handleThreadStatus(ThreadChannel threadChannel) { + long threadId = threadChannel.getIdLong(); + Instant closedAt = Instant.now(); + + int status = database.read(context -> context.selectFrom(HELP_THREADS) + .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) + .fetchOne(HELP_THREADS.TICKET_STATUS)); + + if (status == HelpSystemHelper.TicketStatus.ACTIVE.val) { + changeStatusToArchive(closedAt, threadId); + } + + changeStatusToActive(threadId); + } + + private void changeStatusToArchive(Instant closedAt, long threadId) { + database.write(context -> context.update(HELP_THREADS) + .set(HELP_THREADS.CLOSED_AT, closedAt) + .set(HELP_THREADS.TICKET_STATUS, HelpSystemHelper.TicketStatus.ARCHIVED.val) + .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) + .execute()); + + logger.info("Thread with id: {}, updated to active in database", threadId); + } + + private void changeStatusToActive(long threadId) { + database.write(context -> context.update(HELP_THREADS) + .set(HELP_THREADS.TICKET_STATUS, HelpSystemHelper.TicketStatus.ACTIVE.val) + .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) + .execute()); + + logger.info("Thread with id: {}, updated to archive status in database", threadId); + } +} From ff7ec2fe9723bf2bd8dbeaa9e621a21231a0972b Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Sun, 17 Dec 2023 23:10:37 +0530 Subject: [PATCH 04/27] fix error in log messages --- .../tjbot/features/help/HelpThreadArchivedListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java index 8f25c6699c..fb987921ae 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java @@ -66,7 +66,7 @@ private void changeStatusToArchive(Instant closedAt, long threadId) { .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) .execute()); - logger.info("Thread with id: {}, updated to active in database", threadId); + logger.info("Thread with id: {}, updated to archived in database", threadId); } private void changeStatusToActive(long threadId) { @@ -75,6 +75,6 @@ private void changeStatusToActive(long threadId) { .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) .execute()); - logger.info("Thread with id: {}, updated to archive status in database", threadId); + logger.info("Thread with id: {}, updated to active status in database", threadId); } } From 85089775d9abf04ae693f274040cce3818390051 Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Sun, 17 Dec 2023 23:41:51 +0530 Subject: [PATCH 05/27] method to update tagName on change in db --- .../help/HelpThreadArchivedListener.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java index fb987921ae..9573a48a66 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java @@ -1,6 +1,7 @@ package org.togetherjava.tjbot.features.help; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; +import net.dv8tion.jda.api.events.channel.update.ChannelUpdateAppliedTagsEvent; import net.dv8tion.jda.api.events.channel.update.ChannelUpdateArchivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; @@ -37,15 +38,27 @@ public void onChannelUpdateArchived(@NotNull ChannelUpdateArchivedEvent event) { } ThreadChannel threadChannel = event.getChannel().asThreadChannel(); - if (!helper.isHelpForumName(threadChannel.getParentChannel().getName())) { return; } - handleThreadStatus(threadChannel); + handleThreadStatus(threadChannel.getIdLong()); } - private void handleThreadStatus(ThreadChannel threadChannel) { + @Override + public void onChannelUpdateAppliedTags(@NotNull ChannelUpdateAppliedTagsEvent event) { + ThreadChannel threadChannel = event.getChannel().asThreadChannel(); + + if(!helper.isHelpForumName(threadChannel.getParentChannel().getName())){ + return; + } + + String updatedTag = event.getAddedTags().getFirst().getName(); long threadId = threadChannel.getIdLong(); + + handleTagsUpdate(threadId,updatedTag); + } + + private void handleThreadStatus(long threadId) { Instant closedAt = Instant.now(); int status = database.read(context -> context.selectFrom(HELP_THREADS) @@ -77,4 +90,13 @@ private void changeStatusToActive(long threadId) { logger.info("Thread with id: {}, updated to active status in database", threadId); } + + private void handleTagsUpdate(long threadId, String updatedTag){ + database.write(context->context.update(HELP_THREADS) + .set(HELP_THREADS.TAG,updatedTag) + .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) + .execute()); + + logger.info("Updated tag for thread with id: {} in database",threadId); + } } From 198df3a53b98068339f2f6cb8fb3cbc88dd18b6b Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Sun, 17 Dec 2023 23:47:14 +0530 Subject: [PATCH 06/27] more suitable name for class and java doc --- .../togetherjava/tjbot/features/Features.java | 2 +- ...ner.java => HelpThreadEventsListener.java} | 26 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) rename application/src/main/java/org/togetherjava/tjbot/features/help/{HelpThreadArchivedListener.java => HelpThreadEventsListener.java} (82%) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/Features.java b/application/src/main/java/org/togetherjava/tjbot/features/Features.java index ad88e59fbd..ab0089786a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/Features.java @@ -125,7 +125,7 @@ public static Collection createFeatures(JDA jda, Database database, Con features.add(new GuildLeaveCloseThreadListener(config)); features.add(new LeftoverBookmarksListener(bookmarksSystem)); features.add(new HelpThreadCreatedListener(helpSystemHelper)); - features.add(new HelpThreadArchivedListener(helpSystemHelper, database)); + features.add(new HelpThreadEventsListener(helpSystemHelper, database)); // Message context commands features.add(new TransferQuestionCommand(config)); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadEventsListener.java similarity index 82% rename from application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java rename to application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadEventsListener.java index 9573a48a66..eab56a4435 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadArchivedListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadEventsListener.java @@ -15,10 +15,14 @@ import static org.togetherjava.tjbot.db.generated.tables.HelpThreads.HELP_THREADS; -public final class HelpThreadArchivedListener extends ListenerAdapter implements EventReceiver { +/** + * Listens for help thread events after creation of thread. Updates metadata based on those events + * in database. + */ +public final class HelpThreadEventsListener extends ListenerAdapter implements EventReceiver { private final HelpSystemHelper helper; - private final Logger logger = LoggerFactory.getLogger(HelpThreadArchivedListener.class); + private final Logger logger = LoggerFactory.getLogger(HelpThreadEventsListener.class); private final Database database; /** @@ -26,7 +30,7 @@ public final class HelpThreadArchivedListener extends ListenerAdapter implements * * @param helper to work with the help threads */ - public HelpThreadArchivedListener(HelpSystemHelper helper, Database database) { + public HelpThreadEventsListener(HelpSystemHelper helper, Database database) { this.helper = helper; this.database = database; } @@ -48,14 +52,14 @@ public void onChannelUpdateArchived(@NotNull ChannelUpdateArchivedEvent event) { public void onChannelUpdateAppliedTags(@NotNull ChannelUpdateAppliedTagsEvent event) { ThreadChannel threadChannel = event.getChannel().asThreadChannel(); - if(!helper.isHelpForumName(threadChannel.getParentChannel().getName())){ + if (!helper.isHelpForumName(threadChannel.getParentChannel().getName())) { return; } String updatedTag = event.getAddedTags().getFirst().getName(); long threadId = threadChannel.getIdLong(); - handleTagsUpdate(threadId,updatedTag); + handleTagsUpdate(threadId, updatedTag); } private void handleThreadStatus(long threadId) { @@ -91,12 +95,12 @@ private void changeStatusToActive(long threadId) { logger.info("Thread with id: {}, updated to active status in database", threadId); } - private void handleTagsUpdate(long threadId, String updatedTag){ - database.write(context->context.update(HELP_THREADS) - .set(HELP_THREADS.TAG,updatedTag) - .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) - .execute()); + private void handleTagsUpdate(long threadId, String updatedTag) { + database.write(context -> context.update(HELP_THREADS) + .set(HELP_THREADS.TAG, updatedTag) + .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) + .execute()); - logger.info("Updated tag for thread with id: {} in database",threadId); + logger.info("Updated tag for thread with id: {} in database", threadId); } } From 76b09e9e8548ae94974b78e107286be634f0747f Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Mon, 18 Dec 2023 03:26:30 +0530 Subject: [PATCH 07/27] change name to avoid confusion & update java doc --- .../java/org/togetherjava/tjbot/features/Features.java | 2 +- ...ventsListener.java => HelpThreadLifecycleListener.java} | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) rename application/src/main/java/org/togetherjava/tjbot/features/help/{HelpThreadEventsListener.java => HelpThreadLifecycleListener.java} (92%) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/Features.java b/application/src/main/java/org/togetherjava/tjbot/features/Features.java index ab0089786a..bfde92b2ca 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/Features.java @@ -125,7 +125,7 @@ public static Collection createFeatures(JDA jda, Database database, Con features.add(new GuildLeaveCloseThreadListener(config)); features.add(new LeftoverBookmarksListener(bookmarksSystem)); features.add(new HelpThreadCreatedListener(helpSystemHelper)); - features.add(new HelpThreadEventsListener(helpSystemHelper, database)); + features.add(new HelpThreadLifecycleListener(helpSystemHelper, database)); // Message context commands features.add(new TransferQuestionCommand(config)); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadEventsListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java similarity index 92% rename from application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadEventsListener.java rename to application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java index eab56a4435..354d0bc80b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadEventsListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java @@ -19,18 +19,19 @@ * Listens for help thread events after creation of thread. Updates metadata based on those events * in database. */ -public final class HelpThreadEventsListener extends ListenerAdapter implements EventReceiver { +public final class HelpThreadLifecycleListener extends ListenerAdapter implements EventReceiver { private final HelpSystemHelper helper; - private final Logger logger = LoggerFactory.getLogger(HelpThreadEventsListener.class); + private final Logger logger = LoggerFactory.getLogger(HelpThreadLifecycleListener.class); private final Database database; /** * Creates a new instance. * * @param helper to work with the help threads + * @param database the database to store help thread metadata in */ - public HelpThreadEventsListener(HelpSystemHelper helper, Database database) { + public HelpThreadLifecycleListener(HelpSystemHelper helper, Database database) { this.helper = helper; this.database = database; } From c2842cf95aeb3c828f3e6102c8f7ed8877af108d Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Mon, 18 Dec 2023 16:04:51 +0530 Subject: [PATCH 08/27] minor bug that would change status back to active again and log message update --- .../tjbot/features/help/HelpThreadLifecycleListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java index 354d0bc80b..39df1ba40e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java @@ -72,6 +72,7 @@ private void handleThreadStatus(long threadId) { if (status == HelpSystemHelper.TicketStatus.ACTIVE.val) { changeStatusToArchive(closedAt, threadId); + return; } changeStatusToActive(threadId); @@ -84,7 +85,7 @@ private void changeStatusToArchive(Instant closedAt, long threadId) { .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) .execute()); - logger.info("Thread with id: {}, updated to archived in database", threadId); + logger.info("Thread with id: {}, updated to archived status in database", threadId); } private void changeStatusToActive(long threadId) { From c5768c2a55ea07c15ca49639c39cdb15a814438a Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:03:25 +0530 Subject: [PATCH 09/27] more columns added for metadata --- .../src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/application/src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql b/application/src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql index 12ed8850b1..c8610a7c56 100644 --- a/application/src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql +++ b/application/src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql @@ -1,3 +1,5 @@ ALTER TABLE help_threads ADD ticket_status INTEGER DEFAULT 0; ALTER TABLE help_threads ADD tag TEXT DEFAULT 'none'; -ALTER TABLE help_threads ADD closed_at TIMESTAMP NULL; \ No newline at end of file +ALTER TABLE help_threads ADD closed_at TIMESTAMP NULL; +ALTER TABLE help_threads ADD participants INTEGER DEFAULT 1; +ALTER TABLE help_threads ADD message_count INTEGER DEFAULT 0; \ No newline at end of file From a1ecd95f314b17cead935de8a9422b9b06768f25 Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:14:59 +0530 Subject: [PATCH 10/27] update listener to record added metadata columns --- .../help/HelpThreadLifecycleListener.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java index 39df1ba40e..a131054844 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java @@ -46,7 +46,7 @@ public void onChannelUpdateArchived(@NotNull ChannelUpdateArchivedEvent event) { if (!helper.isHelpForumName(threadChannel.getParentChannel().getName())) { return; } - handleThreadStatus(threadChannel.getIdLong()); + handleThreadStatus(threadChannel); } @Override @@ -63,25 +63,32 @@ public void onChannelUpdateAppliedTags(@NotNull ChannelUpdateAppliedTagsEvent ev handleTagsUpdate(threadId, updatedTag); } - private void handleThreadStatus(long threadId) { + private void handleThreadStatus(ThreadChannel threadChannel) { Instant closedAt = Instant.now(); + long threadId = threadChannel.getIdLong(); int status = database.read(context -> context.selectFrom(HELP_THREADS) .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) .fetchOne(HELP_THREADS.TICKET_STATUS)); if (status == HelpSystemHelper.TicketStatus.ACTIVE.val) { - changeStatusToArchive(closedAt, threadId); + handleArchiveStatus(closedAt, threadChannel); return; } changeStatusToActive(threadId); } - private void changeStatusToArchive(Instant closedAt, long threadId) { + private void handleArchiveStatus(Instant closedAt, ThreadChannel threadChannel) { + long threadId = threadChannel.getIdLong(); + int messageCount = threadChannel.getMessageCount(); + int participantsExceptAuthor = threadChannel.getMemberCount() - 1; + database.write(context -> context.update(HELP_THREADS) .set(HELP_THREADS.CLOSED_AT, closedAt) .set(HELP_THREADS.TICKET_STATUS, HelpSystemHelper.TicketStatus.ARCHIVED.val) + .set(HELP_THREADS.MESSAGE_COUNT,messageCount) + .set(HELP_THREADS.PARTICIPANTS,participantsExceptAuthor) .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) .execute()); From 0bd0c13763538a618e15f2fbfb616e0f61fbd068 Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:23:36 +0530 Subject: [PATCH 11/27] spotless fix --- .../tjbot/features/help/HelpThreadLifecycleListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java index a131054844..c2e5632dbe 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java @@ -87,8 +87,8 @@ private void handleArchiveStatus(Instant closedAt, ThreadChannel threadChannel) database.write(context -> context.update(HELP_THREADS) .set(HELP_THREADS.CLOSED_AT, closedAt) .set(HELP_THREADS.TICKET_STATUS, HelpSystemHelper.TicketStatus.ARCHIVED.val) - .set(HELP_THREADS.MESSAGE_COUNT,messageCount) - .set(HELP_THREADS.PARTICIPANTS,participantsExceptAuthor) + .set(HELP_THREADS.MESSAGE_COUNT, messageCount) + .set(HELP_THREADS.PARTICIPANTS, participantsExceptAuthor) .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) .execute()); From 28c28b423e26c2926187f7f66bfdd558d8547dd8 Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Tue, 19 Dec 2023 01:21:32 +0530 Subject: [PATCH 12/27] replacing get(0) with getFirst() for list --- .../org/togetherjava/tjbot/features/help/HelpSystemHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java index 443fc4c82f..7c77f30bbf 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java @@ -205,7 +205,7 @@ private RestAction useChatGptFallbackMessage(ThreadChannel threadChanne void writeHelpThreadToDatabase(long authorId, ThreadChannel threadChannel) { Instant createdAt = Instant.now(); - String tag = threadChannel.getAppliedTags().get(0).getName(); + String tag = threadChannel.getAppliedTags().getFirst().getName(); database.write(content -> { HelpThreadsRecord helpThreadsRecord = content.newRecord(HelpThreads.HELP_THREADS) From 7708513ca44fb2181897e80056582f8b3ecb6cb1 Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Thu, 4 Jan 2024 05:01:27 +0530 Subject: [PATCH 13/27] add routine to settle thread status if was left open --- .../togetherjava/tjbot/features/Features.java | 1 + .../help/MarkHelpThreadCloseInDBRoutine.java | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java diff --git a/application/src/main/java/org/togetherjava/tjbot/features/Features.java b/application/src/main/java/org/togetherjava/tjbot/features/Features.java index bfde92b2ca..b2e2ad0273 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/Features.java @@ -106,6 +106,7 @@ public static Collection createFeatures(JDA jda, Database database, Con .add(new AutoPruneHelperRoutine(config, helpSystemHelper, modAuditLogWriter, database)); features.add(new HelpThreadAutoArchiver(helpSystemHelper)); features.add(new LeftoverBookmarksCleanupRoutine(bookmarksSystem)); + features.add(new MarkHelpThreadCloseInDBRoutine(database)); // Message receivers features.add(new TopHelpersMessageListener(database, config)); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java b/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java new file mode 100644 index 0000000000..40b3ea6b63 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java @@ -0,0 +1,51 @@ +package org.togetherjava.tjbot.features.help; + +import net.dv8tion.jda.api.JDA; + +import org.togetherjava.tjbot.db.Database; +import org.togetherjava.tjbot.features.Routine; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.concurrent.TimeUnit; + +import static org.togetherjava.tjbot.db.generated.tables.HelpThreads.HELP_THREADS; + +/** + * Updates the status of help threads in database that were created a few days ago and couldn't be + * closed. + */ +public final class MarkHelpThreadCloseInDBRoutine implements Routine { + private final Database database; + + /** + * Creates a new instance. + * + * @param database the database to store help thread metadata in + */ + public MarkHelpThreadCloseInDBRoutine(Database database) { + this.database = database; + } + + + @Override + public Schedule createSchedule() { + return new Schedule(ScheduleMode.FIXED_RATE, 0, 1, TimeUnit.HOURS); + } + + @Override + public void runRoutine(JDA jda) { + updateTicketStatus(); + } + + private void updateTicketStatus() { + Instant now = Instant.now(); + Instant threeDaysAgo = now.minus(3, ChronoUnit.DAYS); + + database.write(context -> context.update(HELP_THREADS) + .set(HELP_THREADS.TICKET_STATUS, HelpSystemHelper.TicketStatus.ARCHIVED.val) + .where(HELP_THREADS.CREATED_AT.lessOrEqual(threeDaysAgo) + .and(HELP_THREADS.TICKET_STATUS.eq(HelpSystemHelper.TicketStatus.ACTIVE.val))) + .execute()); + } +} From ab0fe6182fe8698485fa0c5a35a5fc376557794e Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Tue, 9 Jan 2024 11:54:41 +0530 Subject: [PATCH 14/27] spotless fix --- .../org/togetherjava/tjbot/features/help/HelpSystemHelper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java index 532219c204..4242d56e76 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java @@ -373,6 +373,7 @@ enum TicketStatus { this.val = val; } } + Optional getAuthorByHelpThreadId(final long channelId) { logger.debug("Looking for thread-record using channel ID: {}", channelId); From 58b129234c39a52d12bd5654dac40c31c09db9ca Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Wed, 24 Jan 2024 23:49:06 +0530 Subject: [PATCH 15/27] refactor MarkHelpThreadCloseInDBRoutine and changes * update constructor with HelpThreadLifecycleListener instance * using HelpThreadLifecycleListener method to clean up left over threads * increasing scope of handleArchiveStatus to package level * adding logger to MarkHelpThreadCloseInDBRoutine class --- .../togetherjava/tjbot/features/Features.java | 4 ++- .../help/HelpThreadLifecycleListener.java | 2 +- .../help/MarkHelpThreadCloseInDBRoutine.java | 36 ++++++++++++++----- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/Features.java b/application/src/main/java/org/togetherjava/tjbot/features/Features.java index b2e2ad0273..67d6fe10d9 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/Features.java @@ -88,6 +88,8 @@ public static Collection createFeatures(JDA jda, Database database, Con new CodeMessageHandler(blacklistConfig.special(), jshellEval); ChatGptService chatGptService = new ChatGptService(config); HelpSystemHelper helpSystemHelper = new HelpSystemHelper(config, database, chatGptService); + HelpThreadLifecycleListener helpThreadLifecycleListener = + new HelpThreadLifecycleListener(helpSystemHelper, database); // NOTE The system can add special system relevant commands also by itself, // hence this list may not necessarily represent the full list of all commands actually @@ -106,7 +108,7 @@ public static Collection createFeatures(JDA jda, Database database, Con .add(new AutoPruneHelperRoutine(config, helpSystemHelper, modAuditLogWriter, database)); features.add(new HelpThreadAutoArchiver(helpSystemHelper)); features.add(new LeftoverBookmarksCleanupRoutine(bookmarksSystem)); - features.add(new MarkHelpThreadCloseInDBRoutine(database)); + features.add(new MarkHelpThreadCloseInDBRoutine(database, helpThreadLifecycleListener)); // Message receivers features.add(new TopHelpersMessageListener(database, config)); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java index c2e5632dbe..8e88026295 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java @@ -79,7 +79,7 @@ private void handleThreadStatus(ThreadChannel threadChannel) { changeStatusToActive(threadId); } - private void handleArchiveStatus(Instant closedAt, ThreadChannel threadChannel) { + void handleArchiveStatus(Instant closedAt, ThreadChannel threadChannel) { long threadId = threadChannel.getIdLong(); int messageCount = threadChannel.getMessageCount(); int participantsExceptAuthor = threadChannel.getMemberCount() - 1; diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java b/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java index 40b3ea6b63..e98acd0bb1 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java @@ -1,12 +1,17 @@ package org.togetherjava.tjbot.features.help; import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.togetherjava.tjbot.db.Database; +import org.togetherjava.tjbot.db.generated.tables.records.HelpThreadsRecord; import org.togetherjava.tjbot.features.Routine; import java.time.Instant; import java.time.temporal.ChronoUnit; +import java.util.List; import java.util.concurrent.TimeUnit; import static org.togetherjava.tjbot.db.generated.tables.HelpThreads.HELP_THREADS; @@ -16,18 +21,21 @@ * closed. */ public final class MarkHelpThreadCloseInDBRoutine implements Routine { + private final Logger logger = LoggerFactory.getLogger(MarkHelpThreadCloseInDBRoutine.class); private final Database database; + private final HelpThreadLifecycleListener helpThreadLifecycleListener; /** * Creates a new instance. * * @param database the database to store help thread metadata in */ - public MarkHelpThreadCloseInDBRoutine(Database database) { + public MarkHelpThreadCloseInDBRoutine(Database database, + HelpThreadLifecycleListener helpThreadLifecycleListener) { this.database = database; + this.helpThreadLifecycleListener = helpThreadLifecycleListener; } - @Override public Schedule createSchedule() { return new Schedule(ScheduleMode.FIXED_RATE, 0, 1, TimeUnit.HOURS); @@ -35,17 +43,27 @@ public Schedule createSchedule() { @Override public void runRoutine(JDA jda) { - updateTicketStatus(); + updateTicketStatus(jda); } - private void updateTicketStatus() { + private void updateTicketStatus(JDA jda) { Instant now = Instant.now(); Instant threeDaysAgo = now.minus(3, ChronoUnit.DAYS); + List threadIdsToClose = database.read(context -> context.selectFrom(HELP_THREADS) + .where(HELP_THREADS.TICKET_STATUS.eq(HelpSystemHelper.TicketStatus.ACTIVE.val)) + .and(HELP_THREADS.CREATED_AT.lessThan(threeDaysAgo)) + .stream() + .map(HelpThreadsRecord::getChannelId) + .toList()); + - database.write(context -> context.update(HELP_THREADS) - .set(HELP_THREADS.TICKET_STATUS, HelpSystemHelper.TicketStatus.ARCHIVED.val) - .where(HELP_THREADS.CREATED_AT.lessOrEqual(threeDaysAgo) - .and(HELP_THREADS.TICKET_STATUS.eq(HelpSystemHelper.TicketStatus.ACTIVE.val))) - .execute()); + threadIdsToClose.forEach(id -> { + try { + ThreadChannel threadChannel = jda.getThreadChannelById(id); + helpThreadLifecycleListener.handleArchiveStatus(now, threadChannel); + } catch (Exception exception) { + logger.warn("unable to mark thread as close with id :{}", id, exception); + } + }); } } From dcf9a7a72d676f01d99a233386f95d8e9e679194 Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Thu, 25 Jan 2024 00:00:56 +0530 Subject: [PATCH 16/27] document updated param in MarkHelpThreadCloseInDBRoutine constructor --- .../tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java b/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java index e98acd0bb1..525ecf6339 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java @@ -29,6 +29,8 @@ public final class MarkHelpThreadCloseInDBRoutine implements Routine { * Creates a new instance. * * @param database the database to store help thread metadata in + * @param helpThreadLifecycleListener class which offers method to update thread status in + * database */ public MarkHelpThreadCloseInDBRoutine(Database database, HelpThreadLifecycleListener helpThreadLifecycleListener) { From 41667e366b5b645fd95db66639035f58f7abe89a Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Thu, 16 May 2024 08:52:53 +0530 Subject: [PATCH 17/27] use time of creation/modfication from thread and tags as csv --- .../tjbot/features/help/HelpSystemHelper.java | 9 ++++++--- .../tjbot/features/help/HelpThreadLifecycleListener.java | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java index 4242d56e76..8416acd5d8 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java @@ -204,15 +204,18 @@ private RestAction useChatGptFallbackMessage(ThreadChannel threadChanne void writeHelpThreadToDatabase(long authorId, ThreadChannel threadChannel) { - Instant createdAt = Instant.now(); - String tag = threadChannel.getAppliedTags().getFirst().getName(); + Instant createdAt = threadChannel.getTimeCreated().toInstant(); + List tagsList = + threadChannel.getAppliedTags().stream().map(ForumTag::getName).toList(); + + String tags = String.join(", ", tagsList); database.write(content -> { HelpThreadsRecord helpThreadsRecord = content.newRecord(HelpThreads.HELP_THREADS) .setAuthorId(authorId) .setChannelId(threadChannel.getIdLong()) .setCreatedAt(createdAt) - .setTag(tag) + .setTag(tags) .setTicketStatus(TicketStatus.ACTIVE.val); if (helpThreadsRecord.update() == 0) { helpThreadsRecord.insert(); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java index 8e88026295..c7302376c7 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java @@ -64,7 +64,7 @@ public void onChannelUpdateAppliedTags(@NotNull ChannelUpdateAppliedTagsEvent ev } private void handleThreadStatus(ThreadChannel threadChannel) { - Instant closedAt = Instant.now(); + Instant closedAt = threadChannel.getTimeArchiveInfoLastModified().toInstant(); long threadId = threadChannel.getIdLong(); int status = database.read(context -> context.selectFrom(HELP_THREADS) From ca6d4d4d5ab4cbc3ed5de41d95f7671b446d2183 Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Fri, 17 May 2024 09:07:21 +0530 Subject: [PATCH 18/27] rely on discord for getting thread status instead of DB --- .../features/help/HelpThreadLifecycleListener.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java index c7302376c7..88225c9130 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java @@ -66,17 +66,14 @@ public void onChannelUpdateAppliedTags(@NotNull ChannelUpdateAppliedTagsEvent ev private void handleThreadStatus(ThreadChannel threadChannel) { Instant closedAt = threadChannel.getTimeArchiveInfoLastModified().toInstant(); long threadId = threadChannel.getIdLong(); + boolean isArchived = threadChannel.isArchived(); - int status = database.read(context -> context.selectFrom(HELP_THREADS) - .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) - .fetchOne(HELP_THREADS.TICKET_STATUS)); - - if (status == HelpSystemHelper.TicketStatus.ACTIVE.val) { + if (isArchived) { handleArchiveStatus(closedAt, threadChannel); return; } - changeStatusToActive(threadId); + updateThreadStatusToActive(threadId); } void handleArchiveStatus(Instant closedAt, ThreadChannel threadChannel) { @@ -95,7 +92,7 @@ void handleArchiveStatus(Instant closedAt, ThreadChannel threadChannel) { logger.info("Thread with id: {}, updated to archived status in database", threadId); } - private void changeStatusToActive(long threadId) { + private void updateThreadStatusToActive(long threadId) { database.write(context -> context.update(HELP_THREADS) .set(HELP_THREADS.TICKET_STATUS, HelpSystemHelper.TicketStatus.ACTIVE.val) .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) From 87461c388530bf8cb841eac886164cb4ae7db8a9 Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Fri, 17 May 2024 18:46:40 +0530 Subject: [PATCH 19/27] changes * requested changes * update config to include tagsToIgnore * refactor tag update logic * update sql script * add tagsToIgnore list to config --- application/config.json.template | 3 +- .../tjbot/config/HelpSystemConfig.java | 15 ++++++-- .../togetherjava/tjbot/features/Features.java | 2 ++ .../tjbot/features/help/HelpSystemHelper.java | 29 ++++++++++++--- .../help/HelpThreadLifecycleListener.java | 36 +++++++++++++++---- ...ql => V15__Alter_Help_Thread_Metadata.sql} | 2 +- 6 files changed, 72 insertions(+), 15 deletions(-) rename application/src/main/resources/db/{V14__Alter_Help_Thread_Metadata.sql => V15__Alter_Help_Thread_Metadata.sql} (81%) diff --git a/application/config.json.template b/application/config.json.template index a1aec8f470..842b565cfe 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -45,7 +45,8 @@ "Together Java Bot", "Other" ], - "categoryRoleSuffix": " - Helper" + "categoryRoleSuffix": " - Helper", + "tagsToIgnore": ["Nobody helped yet", "Needs attention", "Active"] }, "mediaOnlyChannelPattern": "memes", "blacklistedFileExtension": [ diff --git a/application/src/main/java/org/togetherjava/tjbot/config/HelpSystemConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/HelpSystemConfig.java index 7f5f1558fb..540cbb0f77 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/HelpSystemConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/HelpSystemConfig.java @@ -18,16 +18,18 @@ public final class HelpSystemConfig { private final String helpForumPattern; private final List categories; private final String categoryRoleSuffix; + private final List tagsToIgnore; @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) private HelpSystemConfig( @JsonProperty(value = "helpForumPattern", required = true) String helpForumPattern, @JsonProperty(value = "categories", required = true) List categories, - @JsonProperty(value = "categoryRoleSuffix", - required = true) String categoryRoleSuffix) { + @JsonProperty(value = "categoryRoleSuffix", required = true) String categoryRoleSuffix, + @JsonProperty(value = "tagsToIgnore", required = true) List tagsToIgnore) { this.helpForumPattern = Objects.requireNonNull(helpForumPattern); this.categories = new ArrayList<>(Objects.requireNonNull(categories)); this.categoryRoleSuffix = Objects.requireNonNull(categoryRoleSuffix); + this.tagsToIgnore = new ArrayList<>(Objects.requireNonNull(tagsToIgnore)); } /** @@ -62,4 +64,13 @@ public List getCategories() { public String getCategoryRoleSuffix() { return categoryRoleSuffix; } + + /** + * Retrieves all tags that needs to be ignored during collection of meta data in + * {@link org.togetherjava.tjbot.features.help.HelpThreadLifecycleListener} and + * {@link org.togetherjava.tjbot.features.help.HelpThreadCreatedListener} + */ + public List getTagsToIgnore() { + return tagsToIgnore; + } } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/Features.java b/application/src/main/java/org/togetherjava/tjbot/features/Features.java index 93a68cdb9c..5d7778eae6 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/Features.java @@ -31,6 +31,8 @@ import org.togetherjava.tjbot.features.help.HelpThreadCreatedListener; import org.togetherjava.tjbot.features.help.HelpThreadMetadataPurger; import org.togetherjava.tjbot.features.help.PinnedNotificationRemover; +import org.togetherjava.tjbot.features.help.HelpThreadLifecycleListener; +import org.togetherjava.tjbot.features.help.MarkHelpThreadCloseInDBRoutine; import org.togetherjava.tjbot.features.javamail.RSSHandlerRoutine; import org.togetherjava.tjbot.features.jshell.JShellCommand; import org.togetherjava.tjbot.features.jshell.JShellEval; diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java index d35cf46a5d..e1ba7ef704 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java @@ -28,8 +28,8 @@ import org.togetherjava.tjbot.features.chatgpt.ChatGptService; import org.togetherjava.tjbot.features.componentids.ComponentIdInteractor; -import java.time.Instant; import java.awt.Color; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -67,6 +67,8 @@ public final class HelpSystemHelper { private final Set categories; private final Set threadActivityTagNames; private final String categoryRoleSuffix; + + private final Set tagsToIgnore; private final Database database; private final ChatGptService chatGptService; private static final int MAX_QUESTION_LENGTH = 200; @@ -105,6 +107,10 @@ public HelpSystemHelper(Config config, Database database, ChatGptService chatGpt threadActivityTagNames = Arrays.stream(ThreadActivity.values()) .map(ThreadActivity::getTagName) .collect(Collectors.toSet()); + + List tagsToIgnoreList = helpConfig.getTagsToIgnore(); + tagsToIgnore = new HashSet<>(tagsToIgnoreList); + } /** @@ -224,8 +230,12 @@ private RestAction useChatGptFallbackMessage(ThreadChannel threadChanne void writeHelpThreadToDatabase(long authorId, ThreadChannel threadChannel) { Instant createdAt = threadChannel.getTimeCreated().toInstant(); - List tagsList = - threadChannel.getAppliedTags().stream().map(ForumTag::getName).toList(); + + List tagsList = threadChannel.getAppliedTags() + .stream() + .filter(this::shouldIgnoreTag) + .map(ForumTag::getName) + .toList(); String tags = String.join(", ", tagsList); @@ -234,7 +244,7 @@ void writeHelpThreadToDatabase(long authorId, ThreadChannel threadChannel) { .setAuthorId(authorId) .setChannelId(threadChannel.getIdLong()) .setCreatedAt(createdAt) - .setTag(tags) + .setTags(tags) .setTicketStatus(TicketStatus.ACTIVE.val); if (helpThreadsRecord.update() == 0) { helpThreadsRecord.insert(); @@ -405,4 +415,15 @@ Optional getAuthorByHelpThreadId(final long channelId) { .where(HelpThreads.HELP_THREADS.CHANNEL_ID.eq(channelId)) .fetchOptional(HelpThreads.HELP_THREADS.AUTHOR_ID)); } + + + /** + * will be used to filter a tag based on tagsToIgnore config list + * + * @param tag applied tag + * @return boolean result whether to ignore this tag or not + */ + boolean shouldIgnoreTag(ForumTag tag) { + return !this.tagsToIgnore.contains(tag.getName()); + } } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java index 88225c9130..577f0f7c2d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java @@ -1,6 +1,7 @@ package org.togetherjava.tjbot.features.help; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; +import net.dv8tion.jda.api.entities.channel.forums.ForumTag; import net.dv8tion.jda.api.events.channel.update.ChannelUpdateAppliedTagsEvent; import net.dv8tion.jda.api.events.channel.update.ChannelUpdateArchivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; @@ -12,6 +13,7 @@ import org.togetherjava.tjbot.features.EventReceiver; import java.time.Instant; +import java.util.List; import static org.togetherjava.tjbot.db.generated.tables.HelpThreads.HELP_THREADS; @@ -38,9 +40,6 @@ public HelpThreadLifecycleListener(HelpSystemHelper helper, Database database) { @Override public void onChannelUpdateArchived(@NotNull ChannelUpdateArchivedEvent event) { - if (!event.getChannelType().isThread()) { - return; - } ThreadChannel threadChannel = event.getChannel().asThreadChannel(); if (!helper.isHelpForumName(threadChannel.getParentChannel().getName())) { @@ -53,14 +52,22 @@ public void onChannelUpdateArchived(@NotNull ChannelUpdateArchivedEvent event) { public void onChannelUpdateAppliedTags(@NotNull ChannelUpdateAppliedTagsEvent event) { ThreadChannel threadChannel = event.getChannel().asThreadChannel(); - if (!helper.isHelpForumName(threadChannel.getParentChannel().getName())) { + if (!helper.isHelpForumName(threadChannel.getParentChannel().getName()) + || shouldIgnoreUpdatedTagEvent(event)) { return; } - String updatedTag = event.getAddedTags().getFirst().getName(); + + List updatedTagList = threadChannel.getAppliedTags() + .stream() + .filter(helper::shouldIgnoreTag) + .map(ForumTag::getName) + .toList(); + String tags = String.join(", ", updatedTagList); + long threadId = threadChannel.getIdLong(); - handleTagsUpdate(threadId, updatedTag); + handleTagsUpdate(threadId, tags); } private void handleThreadStatus(ThreadChannel threadChannel) { @@ -103,10 +110,25 @@ private void updateThreadStatusToActive(long threadId) { private void handleTagsUpdate(long threadId, String updatedTag) { database.write(context -> context.update(HELP_THREADS) - .set(HELP_THREADS.TAG, updatedTag) + .set(HELP_THREADS.TAGS, updatedTag) .where(HELP_THREADS.CHANNEL_ID.eq(threadId)) .execute()); logger.info("Updated tag for thread with id: {} in database", threadId); } + + /** + * will ignore updated tag event if all new tags belong to tagsToIgnore config list + * + * @param event updated tags event + * @return boolean + */ + private boolean shouldIgnoreUpdatedTagEvent(ChannelUpdateAppliedTagsEvent event) { + List newTags = event.getNewTags() + .stream() + .filter(helper::shouldIgnoreTag) + .map(ForumTag::getName) + .toList(); + return newTags.isEmpty(); + } } diff --git a/application/src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql b/application/src/main/resources/db/V15__Alter_Help_Thread_Metadata.sql similarity index 81% rename from application/src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql rename to application/src/main/resources/db/V15__Alter_Help_Thread_Metadata.sql index c8610a7c56..1e7235d3b6 100644 --- a/application/src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql +++ b/application/src/main/resources/db/V15__Alter_Help_Thread_Metadata.sql @@ -1,5 +1,5 @@ ALTER TABLE help_threads ADD ticket_status INTEGER DEFAULT 0; -ALTER TABLE help_threads ADD tag TEXT DEFAULT 'none'; +ALTER TABLE help_threads ADD tags TEXT DEFAULT 'none'; ALTER TABLE help_threads ADD closed_at TIMESTAMP NULL; ALTER TABLE help_threads ADD participants INTEGER DEFAULT 1; ALTER TABLE help_threads ADD message_count INTEGER DEFAULT 0; \ No newline at end of file From 7d2256ceff5655618d95517318018f67cee7554a Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Sat, 18 May 2024 13:11:51 +0530 Subject: [PATCH 20/27] change list * adding data fields that are being collected in privacy policy * updating duration of data storage in privacy policy doc * HelpThreadMetadataPurger will now purge help threads data post 180 days * instead of appending new tags, only new tags are stored now --- PP.md | 9 ++++++++- .../tjbot/features/help/HelpThreadLifecycleListener.java | 5 +++-- .../tjbot/features/help/HelpThreadMetadataPurger.java | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/PP.md b/PP.md index ae5cce3537..31544ac609 100644 --- a/PP.md +++ b/PP.md @@ -48,6 +48,13 @@ The databases may store * `guild_id` of guilds the **bot** is member of (the unique id of a Discord guild), * `channel_id` of channels belonging to guilds the **bot** is member of (the unique id of a Discord channel), * `message_id` of messages send by users in guilds the **bot** is member of (the unique id of a Discord message), +* `participant_count` of no of people who participated in help thread discussions, +* `tags` aka categories to which these help threads belong to, +* `timestamp`s for both when thread was created and closed, +* `message_count` the no of messages that were sent in lifecycle of any help thread + +_Note: Help threads are just threads that are created via forum channels, used for anyone to ask questions and get help +in certain problems._ and any combination of those. @@ -55,7 +62,7 @@ For example, **TJ-Bot** may associate your `user_id` with a `message_id` and a ` **TJ-Bot** may further store data that you explicitly provided for **TJ-Bot** to offer its services. For example the reason of a moderative action when using its moderation commands. -Furthermore, upon utilization of our help service, `user_id`s and `channel_id`s are stored to track when/how many questions a user asks. The data may be stored for up to **30** days. +Furthermore, upon utilization of our help service, `user_id`s and `channel_id`s are stored to track when/how many questions a user asks. The data may be stored for up to **180** days. The stored data is not linked to any information that is personally identifiable. diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java index 577f0f7c2d..7af07d0b26 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java @@ -58,12 +58,13 @@ public void onChannelUpdateAppliedTags(@NotNull ChannelUpdateAppliedTagsEvent ev } - List updatedTagList = threadChannel.getAppliedTags() + List newlyAppliedTagsOnly = event.getAddedTags() .stream() .filter(helper::shouldIgnoreTag) .map(ForumTag::getName) .toList(); - String tags = String.join(", ", updatedTagList); + + String tags = String.join(", ", newlyAppliedTagsOnly); long threadId = threadChannel.getIdLong(); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadMetadataPurger.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadMetadataPurger.java index 457a222a4a..794a8391c0 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadMetadataPurger.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadMetadataPurger.java @@ -18,7 +18,7 @@ public class HelpThreadMetadataPurger implements Routine { private final Database database; private static final Logger logger = LoggerFactory.getLogger(HelpThreadMetadataPurger.class); - private static final Period DELETE_MESSAGE_RECORDS_AFTER = Period.ofDays(30); + private static final Period DELETE_MESSAGE_RECORDS_AFTER = Period.ofDays(180); /** * Creates a new instance. @@ -31,7 +31,7 @@ public HelpThreadMetadataPurger(Database database) { @Override public Schedule createSchedule() { - return new Schedule(ScheduleMode.FIXED_RATE, 0, 4, TimeUnit.HOURS); + return new Schedule(ScheduleMode.FIXED_RATE, 0, 1, TimeUnit.DAYS); } @Override From 3089083decc55c12669d802d3b59fa6b4d08b8a2 Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Sat, 18 May 2024 13:18:29 +0530 Subject: [PATCH 21/27] spotless fix --- .../main/java/org/togetherjava/tjbot/features/Features.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/Features.java b/application/src/main/java/org/togetherjava/tjbot/features/Features.java index 5d7778eae6..893adbc00f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/Features.java @@ -29,10 +29,10 @@ import org.togetherjava.tjbot.features.help.HelpThreadAutoArchiver; import org.togetherjava.tjbot.features.help.HelpThreadCommand; import org.togetherjava.tjbot.features.help.HelpThreadCreatedListener; -import org.togetherjava.tjbot.features.help.HelpThreadMetadataPurger; -import org.togetherjava.tjbot.features.help.PinnedNotificationRemover; import org.togetherjava.tjbot.features.help.HelpThreadLifecycleListener; +import org.togetherjava.tjbot.features.help.HelpThreadMetadataPurger; import org.togetherjava.tjbot.features.help.MarkHelpThreadCloseInDBRoutine; +import org.togetherjava.tjbot.features.help.PinnedNotificationRemover; import org.togetherjava.tjbot.features.javamail.RSSHandlerRoutine; import org.togetherjava.tjbot.features.jshell.JShellCommand; import org.togetherjava.tjbot.features.jshell.JShellEval; From a665aa79be3df3c1434234f83fef87a0c04193a2 Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Sat, 18 May 2024 13:40:00 +0530 Subject: [PATCH 22/27] tags from config sanitized --- .../tjbot/features/help/HelpSystemHelper.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java index e1ba7ef704..e412c4f39f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java @@ -108,7 +108,12 @@ public HelpSystemHelper(Config config, Database database, ChatGptService chatGpt .map(ThreadActivity::getTagName) .collect(Collectors.toSet()); - List tagsToIgnoreList = helpConfig.getTagsToIgnore(); + // tagsToIgnore list values are sanitized to avoid any config mismatch due to human error + List tagsToIgnoreList = helpConfig.getTagsToIgnore() + .stream() + .map(String::toLowerCase) + .map(String::strip) + .toList(); tagsToIgnore = new HashSet<>(tagsToIgnoreList); } @@ -424,6 +429,6 @@ Optional getAuthorByHelpThreadId(final long channelId) { * @return boolean result whether to ignore this tag or not */ boolean shouldIgnoreTag(ForumTag tag) { - return !this.tagsToIgnore.contains(tag.getName()); + return !this.tagsToIgnore.contains(tag.getName().toLowerCase()); } } From b061ae016ceed312af44f55e6bc582bb08ce1a2b Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Sat, 25 May 2024 07:12:44 +0530 Subject: [PATCH 23/27] requested changes --- .../tjbot/features/help/HelpSystemHelper.java | 8 +++----- .../tjbot/features/help/HelpThreadLifecycleListener.java | 3 +-- .../features/help/MarkHelpThreadCloseInDBRoutine.java | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java index e412c4f39f..4a2070eac4 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java @@ -236,20 +236,18 @@ void writeHelpThreadToDatabase(long authorId, ThreadChannel threadChannel) { Instant createdAt = threadChannel.getTimeCreated().toInstant(); - List tagsList = threadChannel.getAppliedTags() + String appliedTags = threadChannel.getAppliedTags() .stream() .filter(this::shouldIgnoreTag) .map(ForumTag::getName) - .toList(); - - String tags = String.join(", ", tagsList); + .collect(Collectors.joining(",")); database.write(content -> { HelpThreadsRecord helpThreadsRecord = content.newRecord(HelpThreads.HELP_THREADS) .setAuthorId(authorId) .setChannelId(threadChannel.getIdLong()) .setCreatedAt(createdAt) - .setTags(tags) + .setTags(appliedTags) .setTicketStatus(TicketStatus.ACTIVE.val); if (helpThreadsRecord.update() == 0) { helpThreadsRecord.insert(); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java index 7af07d0b26..bb048059db 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java @@ -22,9 +22,8 @@ * in database. */ public final class HelpThreadLifecycleListener extends ListenerAdapter implements EventReceiver { - + private static final Logger logger = LoggerFactory.getLogger(HelpThreadLifecycleListener.class); private final HelpSystemHelper helper; - private final Logger logger = LoggerFactory.getLogger(HelpThreadLifecycleListener.class); private final Database database; /** diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java b/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java index 525ecf6339..4a82dd65ab 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java @@ -21,7 +21,7 @@ * closed. */ public final class MarkHelpThreadCloseInDBRoutine implements Routine { - private final Logger logger = LoggerFactory.getLogger(MarkHelpThreadCloseInDBRoutine.class); + private static final Logger logger = LoggerFactory.getLogger(MarkHelpThreadCloseInDBRoutine.class); private final Database database; private final HelpThreadLifecycleListener helpThreadLifecycleListener; From e302e9568e719a54247cc31f392659247a317742 Mon Sep 17 00:00:00 2001 From: alphaBEE <61616007+ankitsmt211@users.noreply.github.com> Date: Sat, 25 May 2024 07:17:16 +0530 Subject: [PATCH 24/27] spotless --- .../org/togetherjava/tjbot/features/help/HelpSystemHelper.java | 2 +- .../tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java index 4a2070eac4..e3459a4c1f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java @@ -240,7 +240,7 @@ void writeHelpThreadToDatabase(long authorId, ThreadChannel threadChannel) { .stream() .filter(this::shouldIgnoreTag) .map(ForumTag::getName) - .collect(Collectors.joining(",")); + .collect(Collectors.joining(",")); database.write(content -> { HelpThreadsRecord helpThreadsRecord = content.newRecord(HelpThreads.HELP_THREADS) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java b/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java index 4a82dd65ab..67a32ed855 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java @@ -21,7 +21,8 @@ * closed. */ public final class MarkHelpThreadCloseInDBRoutine implements Routine { - private static final Logger logger = LoggerFactory.getLogger(MarkHelpThreadCloseInDBRoutine.class); + private static final Logger logger = + LoggerFactory.getLogger(MarkHelpThreadCloseInDBRoutine.class); private final Database database; private final HelpThreadLifecycleListener helpThreadLifecycleListener; From c745481a84f5732d955d246ec2c98c055e27bc32 Mon Sep 17 00:00:00 2001 From: Ankit Yadav <61616007+ankitsmt211@users.noreply.github.com> Date: Sat, 1 Jun 2024 11:05:22 +0530 Subject: [PATCH 25/27] requested changes --- application/config.json.template | 3 +-- .../tjbot/config/HelpSystemConfig.java | 15 ++------------ .../tjbot/features/help/HelpSystemHelper.java | 20 +++++++------------ .../help/HelpThreadCreatedListener.java | 3 +-- .../help/HelpThreadLifecycleListener.java | 15 +++++++------- 5 files changed, 18 insertions(+), 38 deletions(-) diff --git a/application/config.json.template b/application/config.json.template index 842b565cfe..a1aec8f470 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -45,8 +45,7 @@ "Together Java Bot", "Other" ], - "categoryRoleSuffix": " - Helper", - "tagsToIgnore": ["Nobody helped yet", "Needs attention", "Active"] + "categoryRoleSuffix": " - Helper" }, "mediaOnlyChannelPattern": "memes", "blacklistedFileExtension": [ diff --git a/application/src/main/java/org/togetherjava/tjbot/config/HelpSystemConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/HelpSystemConfig.java index 540cbb0f77..7f5f1558fb 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/HelpSystemConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/HelpSystemConfig.java @@ -18,18 +18,16 @@ public final class HelpSystemConfig { private final String helpForumPattern; private final List categories; private final String categoryRoleSuffix; - private final List tagsToIgnore; @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) private HelpSystemConfig( @JsonProperty(value = "helpForumPattern", required = true) String helpForumPattern, @JsonProperty(value = "categories", required = true) List categories, - @JsonProperty(value = "categoryRoleSuffix", required = true) String categoryRoleSuffix, - @JsonProperty(value = "tagsToIgnore", required = true) List tagsToIgnore) { + @JsonProperty(value = "categoryRoleSuffix", + required = true) String categoryRoleSuffix) { this.helpForumPattern = Objects.requireNonNull(helpForumPattern); this.categories = new ArrayList<>(Objects.requireNonNull(categories)); this.categoryRoleSuffix = Objects.requireNonNull(categoryRoleSuffix); - this.tagsToIgnore = new ArrayList<>(Objects.requireNonNull(tagsToIgnore)); } /** @@ -64,13 +62,4 @@ public List getCategories() { public String getCategoryRoleSuffix() { return categoryRoleSuffix; } - - /** - * Retrieves all tags that needs to be ignored during collection of meta data in - * {@link org.togetherjava.tjbot.features.help.HelpThreadLifecycleListener} and - * {@link org.togetherjava.tjbot.features.help.HelpThreadCreatedListener} - */ - public List getTagsToIgnore() { - return tagsToIgnore; - } } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java index e3459a4c1f..27022fcf5f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java @@ -34,7 +34,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Comparator; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -68,7 +67,6 @@ public final class HelpSystemHelper { private final Set threadActivityTagNames; private final String categoryRoleSuffix; - private final Set tagsToIgnore; private final Database database; private final ChatGptService chatGptService; private static final int MAX_QUESTION_LENGTH = 200; @@ -93,7 +91,10 @@ public HelpSystemHelper(Config config, Database database, ChatGptService chatGpt isHelpForumName = Pattern.compile(helpForumPattern).asMatchPredicate(); List categoriesList = helpConfig.getCategories(); - categories = new HashSet<>(categoriesList); + categories = categoriesList.stream() + .map(String::strip) + .map(String::toLowerCase) + .collect(Collectors.toSet()); categoryRoleSuffix = helpConfig.getCategoryRoleSuffix(); Map categoryToCommonDesc = IntStream.range(0, categoriesList.size()) @@ -108,13 +109,6 @@ public HelpSystemHelper(Config config, Database database, ChatGptService chatGpt .map(ThreadActivity::getTagName) .collect(Collectors.toSet()); - // tagsToIgnore list values are sanitized to avoid any config mismatch due to human error - List tagsToIgnoreList = helpConfig.getTagsToIgnore() - .stream() - .map(String::toLowerCase) - .map(String::strip) - .toList(); - tagsToIgnore = new HashSet<>(tagsToIgnoreList); } @@ -288,7 +282,7 @@ private Optional getFirstMatchingTagOfChannel(Set tagNamesToMa ThreadChannel channel) { return channel.getAppliedTags() .stream() - .filter(tag -> tagNamesToMatch.contains(tag.getName())) + .filter(tag -> tagNamesToMatch.contains(tag.getName().toLowerCase())) .min(byCategoryCommonnessAsc); } @@ -421,12 +415,12 @@ Optional getAuthorByHelpThreadId(final long channelId) { /** - * will be used to filter a tag based on tagsToIgnore config list + * will be used to filter a tag based on categories config * * @param tag applied tag * @return boolean result whether to ignore this tag or not */ boolean shouldIgnoreTag(ForumTag tag) { - return !this.tagsToIgnore.contains(tag.getName().toLowerCase()); + return this.categories.contains(tag.getName().toLowerCase()); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java index 02a959e5e4..306aaed2a2 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java @@ -14,7 +14,6 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.requests.RestAction; -import org.jetbrains.annotations.NotNull; import org.togetherjava.tjbot.features.EventReceiver; import org.togetherjava.tjbot.features.UserInteractionType; @@ -58,7 +57,7 @@ public HelpThreadCreatedListener(HelpSystemHelper helper) { } @Override - public void onMessageReceived(@NotNull MessageReceivedEvent event) { + public void onMessageReceived(MessageReceivedEvent event) { if (event.isFromThread()) { ThreadChannel threadChannel = event.getChannel().asThreadChannel(); Channel parentChannel = threadChannel.getParentChannel(); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java index bb048059db..f2b9d9a2c1 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java @@ -5,7 +5,6 @@ import net.dv8tion.jda.api.events.channel.update.ChannelUpdateAppliedTagsEvent; import net.dv8tion.jda.api.events.channel.update.ChannelUpdateArchivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; -import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,6 +13,7 @@ import java.time.Instant; import java.util.List; +import java.util.stream.Collectors; import static org.togetherjava.tjbot.db.generated.tables.HelpThreads.HELP_THREADS; @@ -38,7 +38,7 @@ public HelpThreadLifecycleListener(HelpSystemHelper helper, Database database) { } @Override - public void onChannelUpdateArchived(@NotNull ChannelUpdateArchivedEvent event) { + public void onChannelUpdateArchived(ChannelUpdateArchivedEvent event) { ThreadChannel threadChannel = event.getChannel().asThreadChannel(); if (!helper.isHelpForumName(threadChannel.getParentChannel().getName())) { @@ -48,7 +48,7 @@ public void onChannelUpdateArchived(@NotNull ChannelUpdateArchivedEvent event) { } @Override - public void onChannelUpdateAppliedTags(@NotNull ChannelUpdateAppliedTagsEvent event) { + public void onChannelUpdateAppliedTags(ChannelUpdateAppliedTagsEvent event) { ThreadChannel threadChannel = event.getChannel().asThreadChannel(); if (!helper.isHelpForumName(threadChannel.getParentChannel().getName()) @@ -57,17 +57,16 @@ public void onChannelUpdateAppliedTags(@NotNull ChannelUpdateAppliedTagsEvent ev } - List newlyAppliedTagsOnly = event.getAddedTags() + String newlyAppliedTagsOnly = event.getNewTags() .stream() .filter(helper::shouldIgnoreTag) .map(ForumTag::getName) - .toList(); + .collect(Collectors.joining(",")); - String tags = String.join(", ", newlyAppliedTagsOnly); long threadId = threadChannel.getIdLong(); - handleTagsUpdate(threadId, tags); + handleTagsUpdate(threadId, newlyAppliedTagsOnly); } private void handleThreadStatus(ThreadChannel threadChannel) { @@ -118,7 +117,7 @@ private void handleTagsUpdate(long threadId, String updatedTag) { } /** - * will ignore updated tag event if all new tags belong to tagsToIgnore config list + * will ignore updated tag event if all new tags belong to the categories config * * @param event updated tags event * @return boolean From 495e4d2697303fcc1bea5b3590a46b8171030978 Mon Sep 17 00:00:00 2001 From: Ankit Yadav <61616007+ankitsmt211@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:38:53 +0530 Subject: [PATCH 26/27] remove unnecessary map --- .../tjbot/features/help/HelpThreadLifecycleListener.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java index f2b9d9a2c1..3c2e778ba1 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java @@ -123,11 +123,8 @@ private void handleTagsUpdate(long threadId, String updatedTag) { * @return boolean */ private boolean shouldIgnoreUpdatedTagEvent(ChannelUpdateAppliedTagsEvent event) { - List newTags = event.getNewTags() - .stream() - .filter(helper::shouldIgnoreTag) - .map(ForumTag::getName) - .toList(); + List newTags = + event.getNewTags().stream().filter(helper::shouldIgnoreTag).toList(); return newTags.isEmpty(); } } From b10387c90684b516c7812b3b7f9ae0eeb5240ce9 Mon Sep 17 00:00:00 2001 From: Ankit Yadav <61616007+ankitsmt211@users.noreply.github.com> Date: Sun, 2 Jun 2024 19:14:08 +0530 Subject: [PATCH 27/27] increase routine schedule to 24 hrs --- .../tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java b/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java index 67a32ed855..ec96d77c72 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/MarkHelpThreadCloseInDBRoutine.java @@ -41,7 +41,7 @@ public MarkHelpThreadCloseInDBRoutine(Database database, @Override public Schedule createSchedule() { - return new Schedule(ScheduleMode.FIXED_RATE, 0, 1, TimeUnit.HOURS); + return new Schedule(ScheduleMode.FIXED_RATE, 0, 24, TimeUnit.HOURS); } @Override