Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.utils.TimeUtil;
import org.slf4j.Logger;
Expand Down Expand Up @@ -88,8 +89,8 @@ private void autoArchiveForThread(ThreadChannel threadChannel) {
"""
Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
If it was not resolved yet, **click the button below** to keep it
open, or feel free to create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
Expand Down Expand Up @@ -128,41 +129,44 @@ private void handleArchiveFlow(ThreadChannel threadChannel, MessageEmbed embed)
() -> triggerAuthorIdNotFoundArchiveFlow(threadChannel, embed));
}

private void triggerArchiveFlow(ThreadChannel threadChannel, long authorId,
MessageEmbed embed) {
private void triggerArchiveFlow(ThreadChannel threadChannel, long authorId, MessageEmbed embed) {

Function<Member, RestAction<Message>> sendEmbedWithMention =
member -> threadChannel.sendMessage(member.getAsMention()).addEmbeds(embed);
member -> threadChannel.sendMessage(member.getAsMention())
.addEmbeds(embed)
.addActionRow(Button.primary("OTHER:chatpgt-answer:mark-active", "Mark Active"));

Supplier<RestAction<Message>> sendEmbedWithoutMention =
() -> threadChannel.sendMessageEmbeds(embed);
() -> threadChannel.sendMessageEmbeds(embed)
.addActionRow(Button.primary("OTHER:chatpgt-answer:mark-active", "Mark Active"));

threadChannel.getGuild()
.retrieveMemberById(authorId)
.mapToResult()
.flatMap(authorResults -> {
if (authorResults.isFailure()) {
logger.info(
"Trying to archive a thread ({}), but OP ({}) left the server, sending embed without mention",
threadChannel.getId(), authorId, authorResults.getFailure());

return sendEmbedWithoutMention.get();
}

return sendEmbedWithMention.apply(authorResults.get());
})
.flatMap(_ -> threadChannel.getManager().setArchived(true))
.queue();
.retrieveMemberById(authorId)
.mapToResult()
.flatMap(authorResults -> {
if (authorResults.isFailure()) {
logger.info(
"Trying to archive a thread ({}), but OP ({}) left the server, sending embed without mention",
threadChannel.getId(), authorId, authorResults.getFailure());

return sendEmbedWithoutMention.get();
}

return sendEmbedWithMention.apply(authorResults.get());
})
.flatMap(_ -> threadChannel.getManager().setArchived(true))
.queue();
}

private void triggerAuthorIdNotFoundArchiveFlow(ThreadChannel threadChannel,
MessageEmbed embed) {
private void triggerAuthorIdNotFoundArchiveFlow(ThreadChannel threadChannel, MessageEmbed embed) {

logger.info(
"Was unable to find a matching thread for id: {} in DB, archiving thread without mentioning OP",
threadChannel.getId());

threadChannel.sendMessageEmbeds(embed)
.flatMap(sentEmbed -> threadChannel.getManager().setArchived(true))
.queue();
.addActionRow(Button.primary("OTHER:chatpgt-answer:mark-active", "Mark Active"))
.flatMap(sentEmbed -> threadChannel.getManager().setArchived(true))
Comment thread
Zabuzard marked this conversation as resolved.
Outdated
.queue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,14 @@ private Consumer<Throwable> handleParentMessageDeleted(Member user, ThreadChanne

@Override
public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
// This method handles chatgpt's automatic response "dismiss" button
if (args.contains("mark-active")) {
onInactivityButton(event);
} else {
onAiHelpDismissButton(event, args);
}
}
Comment thread
SleepyStack marked this conversation as resolved.
Outdated

private void onAiHelpDismissButton(ButtonInteractionEvent event, List<String> args) {
event.deferEdit().queue();

ThreadChannel channel = event.getChannel().asThreadChannel();
Expand All @@ -197,7 +204,6 @@ public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
.queue(forumPostMessage -> handleDismiss(interactionUser, channel, forumPostMessage,
event, args),
handleParentMessageDeleted(interactionUser, channel, event, args));

}

private boolean isPostAuthor(Member interactionUser, Message message) {
Expand Down Expand Up @@ -248,4 +254,19 @@ private void registerThreadDataInDB(Message message, ThreadChannel threadChannel

helper.writeHelpThreadToDatabase(authorId, threadChannel);
}

private void onInactivityButton(ButtonInteractionEvent event) {
event.deferEdit().queue();

if (event.getChannel() instanceof ThreadChannel thread) {
Message botClosedThreadMessage = event.getMessage();

thread.getManager().setArchived(false)
.flatMap(v -> botClosedThreadMessage.delete())
Comment thread
Zabuzard marked this conversation as resolved.
Outdated
.queue();

log.debug("Thread {} was manually reactivated via button by {}",
Comment thread
Zabuzard marked this conversation as resolved.
Outdated
thread.getId(), event.getUser().getId());
}
}
}
Loading