Skip to content

Commit 08aa4aa

Browse files
Improved the way the thread author gets removed from the submission thread
1 parent 636cb70 commit 08aa4aa

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/main/java/net/javadiscord/javabot/systems/qotw/submissions/SubmissionControlsManager.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import lombok.extern.slf4j.Slf4j;
44
import net.dv8tion.jda.api.EmbedBuilder;
5+
import net.dv8tion.jda.api.JDA;
56
import net.dv8tion.jda.api.entities.*;
67
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
78
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
@@ -79,19 +80,22 @@ public SubmissionControlsManager(Guild guild, ThreadChannel channel) {
7980
public void sendControls() {
8081
ThreadChannel thread = this.guild.getThreadChannelById(this.submission.getThreadId());
8182
if (thread == null) return;
82-
this.removeThreadMembers(thread, this.config);
8383
thread.getManager().setName(String.format("%s %s", SUBMISSION_PENDING, thread.getName())).queue();
8484
thread.sendMessage(config.getQOTWReviewRole().getAsMention())
8585
.setEmbeds(this.buildSubmissionControlEmbed())
8686
.setActionRows(this.buildInteractionControls()).queue();
87+
this.removeThreadOwner(thread.getJDA(), thread);
8788
log.info("Sent Submission Controls to thread {}", thread.getName());
89+
8890
}
8991

90-
private void removeThreadMembers(ThreadChannel thread, QOTWConfig config) {
91-
thread.getThreadMembers()
92-
.stream()
93-
.filter(m -> !m.getMember().getRoles().contains(config.getQOTWReviewRole()) && !m.getMember().getUser().isBot())
94-
.forEach(m -> thread.removeThreadMember(m.getUser()).queue());
92+
private void removeThreadOwner(JDA jda, ThreadChannel thread) {
93+
DbHelper.doDaoAction(QOTWSubmissionRepository::new, dao -> {
94+
Optional<QOTWSubmission> submissionOptional = dao.getSubmissionByThreadId(thread.getIdLong());
95+
submissionOptional.ifPresent(submission -> jda.retrieveUserById(submission.getAuthorId()).queue(
96+
author -> thread.removeThreadMember(author).queue()
97+
));
98+
});
9599
}
96100

97101
/**

0 commit comments

Comments
 (0)