Skip to content

Commit 4c75144

Browse files
committed
refactor: add helper for getting nonbotuser
adds helper function in HelpThreadLifecycleListener to get nonBot participant for database updates
1 parent 1a17607 commit 4c75144

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

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

33
import net.dv8tion.jda.api.JDA;
4+
import net.dv8tion.jda.api.entities.Member;
5+
import net.dv8tion.jda.api.entities.User;
46
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
57
import net.dv8tion.jda.api.entities.channel.forums.ForumTag;
68
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateAppliedTagsEvent;
@@ -83,6 +85,11 @@ private void handleThreadStatus(ThreadChannel threadChannel) {
8385
updateThreadStatusToActive(threadId);
8486
}
8587

88+
private boolean isNonBotParticipant(long threadOwnerId, Member threadMember) {
89+
User targetUser = threadMember.getUser();
90+
return threadOwnerId != targetUser.getIdLong() && !targetUser.isBot();
91+
}
92+
8693
void handleArchiveStatus(Instant closedAt, long id, JDA jda) {
8794
ThreadChannel threadChannel = jda.getThreadChannelById(id);
8895
if (threadChannel == null) {
@@ -101,8 +108,7 @@ void handleArchiveStatus(Instant closedAt, long id, JDA jda) {
101108
long threadOwnerId = threadChannel.getOwnerIdLong();
102109
int participantsExceptAuthor = (int) threadChannel.getMembers()
103110
.stream()
104-
.filter(threadMember -> threadMember.getIdLong() != threadOwnerId)
105-
.filter(m -> !m.getUser().isBot())
111+
.filter(threadMember -> isNonBotParticipant(threadOwnerId, threadMember))
106112
.count();
107113

108114
database.write(context -> context.update(HELP_THREADS)

0 commit comments

Comments
 (0)