Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/npe help thread close #1160

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.togetherjava.tjbot.features.help;

import net.dv8tion.jda.api.JDA;
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;
Expand Down Expand Up @@ -75,14 +76,25 @@ private void handleThreadStatus(ThreadChannel threadChannel) {
boolean isArchived = threadChannel.isArchived();

if (isArchived) {
handleArchiveStatus(closedAt, threadChannel);
handleArchiveStatus(closedAt, threadId, threadChannel.getJDA());
return;
}

updateThreadStatusToActive(threadId);
}

void handleArchiveStatus(Instant closedAt, ThreadChannel threadChannel) {
void handleArchiveStatus(Instant closedAt, long id, JDA jda) {
ThreadChannel threadChannel = jda.getThreadChannelById(id);
if (threadChannel == null) {
logger.info("thread with id: {} no longer exists, marking archived in records", id);
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(id))
.execute());
return;
}

long threadId = threadChannel.getIdLong();
int messageCount = threadChannel.getMessageCount();
int participantsExceptAuthor = threadChannel.getMemberCount() - 1;
Expand All @@ -96,6 +108,7 @@ void handleArchiveStatus(Instant closedAt, ThreadChannel threadChannel) {
.execute());

logger.info("Thread with id: {}, updated to archived status in database", threadId);

}

private void updateThreadStatusToActive(long threadId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
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;
Expand All @@ -21,8 +18,6 @@
* closed.
*/
public final class MarkHelpThreadCloseInDBRoutine implements Routine {
private static final Logger logger =
LoggerFactory.getLogger(MarkHelpThreadCloseInDBRoutine.class);
private final Database database;
private final HelpThreadLifecycleListener helpThreadLifecycleListener;

Expand Down Expand Up @@ -59,14 +54,7 @@ private void updateTicketStatus(JDA jda) {
.map(HelpThreadsRecord::getChannelId)
.toList());


threadIdsToClose.forEach(id -> {
try {
Zabuzard marked this conversation as resolved.
Show resolved Hide resolved
ThreadChannel threadChannel = jda.getThreadChannelById(id);
helpThreadLifecycleListener.handleArchiveStatus(now, threadChannel);
} catch (Exception exception) {
logger.warn("unable to mark thread as close with id :{}", id, exception);
}
});
threadIdsToClose
.forEach(id -> helpThreadLifecycleListener.handleArchiveStatus(now, id, jda));
}
}
Loading