|
12 | 12 | import net.discordjug.javabot.systems.qotw.model.QOTWSubmission; |
13 | 13 | import net.discordjug.javabot.systems.qotw.submissions.SubmissionManager; |
14 | 14 | import net.discordjug.javabot.systems.qotw.submissions.SubmissionStatus; |
| 15 | +import net.discordjug.javabot.util.ExceptionLogger; |
15 | 16 | import net.dv8tion.jda.api.EmbedBuilder; |
16 | 17 | import net.dv8tion.jda.api.JDA; |
17 | 18 | import net.dv8tion.jda.api.Permission; |
|
45 | 46 | import java.util.Collections; |
46 | 47 | import java.util.List; |
47 | 48 | import java.util.Optional; |
| 49 | +import java.util.concurrent.CompletableFuture; |
48 | 50 | import java.util.concurrent.ExecutorService; |
49 | 51 |
|
50 | 52 | /** |
@@ -81,46 +83,58 @@ public void execute() throws SQLException { |
81 | 83 | if (qotwConfig.getSubmissionChannel() == null || qotwConfig.getQuestionChannel() == null) continue; |
82 | 84 | Message questionMessage = getLatestQOTWMessage(qotwConfig.getQuestionChannel(), qotwConfig, jda); |
83 | 85 | questionMessage.editMessageComponents(ActionRow.of(Button.secondary("qotw-submission:closed", "Submissions closed").asDisabled())).queue(); |
84 | | - logChannel |
85 | | - .sendMessageFormat("%s%nIt's review time! There are **%s** threads to review", |
86 | | - qotwConfig.getQOTWReviewRole().getAsMention(), |
87 | | - qotwConfig.getSubmissionChannel().getThreadChannels().size()) |
88 | | - .flatMap(msg -> msg.createThreadChannel("QOTW review")) |
89 | | - .queue(thread -> { |
90 | | - for (ThreadChannel submission : qotwConfig.getSubmissionChannel().getThreadChannels()) { |
91 | | - submission.getManager().setName(SUBMISSION_PENDING + submission.getName()).queue(); |
92 | | - // remove the author |
93 | | - final QOTWSubmission s = new QOTWSubmission(submission); |
94 | | - s.retrieveAuthor(author -> { |
95 | | - submission.removeThreadMember(author).queue(); |
96 | | - if (author.getIdLong() == qotwConfig.getQotwSampleAnswerUserId()) { |
97 | | - SubmissionManager manager = new SubmissionManager(botConfig.get(guild).getQotwConfig(), pointsService, questionQueueRepository, notificationService, asyncPool); |
98 | | - manager.copySampleAnswerSubmission(submission, author); |
99 | | - } else { |
100 | | - thread |
101 | | - .sendMessage("%s by %s".formatted(submission.getAsMention(), author.getAsMention())) |
102 | | - .addActionRow(buildSubmissionSelectMenu(jda, submission.getIdLong())) |
103 | | - .queue(); |
104 | | - } |
105 | | - }); |
106 | | - for (Member member : guild.getMembersWithRoles(qotwConfig.getQOTWReviewRole())) { |
107 | | - thread.addThreadMember(member).queue(); |
| 86 | + if (qotwConfig.getSubmissionsForumChannel() == null) { |
| 87 | + sendReviewInformation(guild, qotwConfig, logChannel); |
| 88 | + } else { |
| 89 | + CompletableFuture.runAsync(() -> { |
| 90 | + |
| 91 | + MessageEmbed embed = questionMessage.getEmbeds().get(0); |
| 92 | + Optional<QOTWQuestion> questionOptional = questionQueueRepository.findByQuestionNumber(getQuestionNumberFromEmbed(embed)); |
| 93 | + if (questionOptional.isPresent()) { |
| 94 | + QOTWQuestion question = questionOptional.get(); |
| 95 | + try (MessageCreateData data = new MessageCreateBuilder() |
| 96 | + .setEmbeds(buildQuestionEmbed(question)).build()) { |
| 97 | + createPinnedAnswerForum(qotwConfig, question, data); |
108 | 98 | } |
109 | 99 | } |
| 100 | + }, asyncPool).whenComplete((success, ex) -> { |
| 101 | + if (ex != null) { |
| 102 | + ExceptionLogger.capture(ex, getClass().getName()); |
| 103 | + } |
| 104 | + sendReviewInformation(guild, qotwConfig, logChannel); |
110 | 105 | }); |
111 | | - if (qotwConfig.getSubmissionsForumChannel() == null) continue; |
112 | | - asyncPool.execute(() -> { |
113 | | - MessageEmbed embed = questionMessage.getEmbeds().get(0); |
114 | | - Optional<QOTWQuestion> questionOptional = questionQueueRepository.findByQuestionNumber(getQuestionNumberFromEmbed(embed)); |
115 | | - if (questionOptional.isPresent()) { |
116 | | - QOTWQuestion question = questionOptional.get(); |
117 | | - try (MessageCreateData data = new MessageCreateBuilder() |
118 | | - .setEmbeds(buildQuestionEmbed(question)).build()) { |
119 | | - createPinnedAnswerForum(qotwConfig, question, data); |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + private void sendReviewInformation(Guild guild, QOTWConfig qotwConfig, TextChannel logChannel) { |
| 111 | + logChannel |
| 112 | + .sendMessageFormat("%s%nIt's review time! There are **%s** threads to review", |
| 113 | + qotwConfig.getQOTWReviewRole().getAsMention(), |
| 114 | + qotwConfig.getSubmissionChannel().getThreadChannels().size()) |
| 115 | + .flatMap(msg -> msg.createThreadChannel("QOTW review")) |
| 116 | + .queue(thread -> { |
| 117 | + for (ThreadChannel submission : qotwConfig.getSubmissionChannel().getThreadChannels()) { |
| 118 | + submission.getManager().setName(SUBMISSION_PENDING + submission.getName()).queue(); |
| 119 | + // remove the author |
| 120 | + final QOTWSubmission s = new QOTWSubmission(submission); |
| 121 | + s.retrieveAuthor(author -> { |
| 122 | + submission.removeThreadMember(author).queue(); |
| 123 | + if (author.getIdLong() == qotwConfig.getQotwSampleAnswerUserId()) { |
| 124 | + SubmissionManager manager = new SubmissionManager(botConfig.get(guild).getQotwConfig(), pointsService, questionQueueRepository, notificationService, asyncPool); |
| 125 | + manager.copySampleAnswerSubmission(submission, author); |
| 126 | + } else { |
| 127 | + thread |
| 128 | + .sendMessage("%s by %s".formatted(submission.getAsMention(), author.getAsMention())) |
| 129 | + .addActionRow(buildSubmissionSelectMenu(jda, submission.getIdLong())) |
| 130 | + .queue(); |
| 131 | + } |
| 132 | + }); |
| 133 | + for (Member member : guild.getMembersWithRoles(qotwConfig.getQOTWReviewRole())) { |
| 134 | + thread.addThreadMember(member).queue(); |
120 | 135 | } |
121 | 136 | } |
122 | 137 | }); |
123 | | - } |
124 | 138 | } |
125 | 139 |
|
126 | 140 | private void createPinnedAnswerForum(QOTWConfig qotwConfig, QOTWQuestion question, MessageCreateData data) { |
|
0 commit comments