|
25 | 25 | import net.javadiscord.javabot.util.Responses; |
26 | 26 | import net.javadiscord.javabot.util.WebhookUtil; |
27 | 27 | import org.jetbrains.annotations.NotNull; |
28 | | -import org.springframework.dao.DataAccessException; |
29 | 28 | import org.springframework.transaction.annotation.Transactional; |
30 | 29 |
|
31 | 30 | import java.time.Instant; |
@@ -73,25 +72,21 @@ public WebhookMessageCreateAction<?> handleSubmission(@NotNull ButtonInteraction |
73 | 72 | thread -> { |
74 | 73 | thread.addThreadMember(member).queue(); |
75 | 74 | thread.getManager().setInvitable(false).setAutoArchiveDuration(ThreadChannel.AutoArchiveDuration.TIME_1_WEEK).queue(); |
76 | | - try { |
77 | | - asyncPool.execute(() -> { |
78 | | - Optional<QOTWQuestion> questionOptional = questionQueueRepository.findByQuestionNumber(questionNumber); |
79 | | - if (questionOptional.isPresent()) { |
80 | | - thread.sendMessage(member.getAsMention()) |
81 | | - .setEmbeds(buildSubmissionThreadEmbed(event.getUser(), questionOptional.get(), config)) |
82 | | - .setComponents(ActionRow.of(Button.danger("qotw-submission:delete", "Delete Submission"))) |
83 | | - .queue(s -> { |
84 | | - }, err -> ExceptionLogger.capture(err, getClass().getSimpleName())); |
85 | | - QOTWSubmission submission = new QOTWSubmission(thread); |
86 | | - submission.setAuthor(member.getUser()); |
87 | | - } else { |
88 | | - thread.sendMessage("Could not retrieve current QOTW Question. Please contact an Administrator if you think that this is a mistake.") |
89 | | - .queue(); |
90 | | - } |
91 | | - }); |
92 | | - } catch (DataAccessException e) { |
93 | | - ExceptionLogger.capture(e, getClass().getSimpleName()); |
94 | | - } |
| 75 | + asyncPool.execute(() -> { |
| 76 | + Optional<QOTWQuestion> questionOptional = questionQueueRepository.findByQuestionNumber(questionNumber); |
| 77 | + if (questionOptional.isPresent()) { |
| 78 | + thread.sendMessage(member.getAsMention()) |
| 79 | + .setEmbeds(buildSubmissionThreadEmbed(event.getUser(), questionOptional.get(), config)) |
| 80 | + .setComponents(ActionRow.of(Button.danger("qotw-submission:delete", "Delete Submission"))) |
| 81 | + .queue(s -> { |
| 82 | + }, err -> ExceptionLogger.capture(err, getClass().getSimpleName())); |
| 83 | + QOTWSubmission submission = new QOTWSubmission(thread); |
| 84 | + submission.setAuthor(member.getUser()); |
| 85 | + } else { |
| 86 | + thread.sendMessage("Could not retrieve current QOTW Question. Please contact an Administrator if you think that this is a mistake.") |
| 87 | + .queue(); |
| 88 | + } |
| 89 | + }); |
95 | 90 | }, e -> log.error("Could not create submission thread for member {}. ", member.getUser().getAsTag(), e) |
96 | 91 | ); |
97 | 92 | log.info("Opened new Submission Thread for User {}", member.getUser().getAsTag()); |
@@ -150,20 +145,19 @@ public void acceptSubmission(InteractionHook hook, @NotNull ThreadChannel thread |
150 | 145 | .stream().max(Comparator.comparing(ThreadChannel::getTimeCreated)); |
151 | 146 | if (newestPostOptional.isPresent()) { |
152 | 147 | ThreadChannel newestPost = newestPostOptional.get(); |
153 | | - getMessagesByUser(thread, author).thenAccept(messages -> { |
154 | | - for (Message message : messages) { |
155 | | - if (message.getAuthor().isBot() || message.getType() != MessageType.DEFAULT) continue; |
156 | | - WebhookUtil.ensureWebhookExists(newestPost.getParentChannel().asForumChannel(), wh -> { |
157 | | - if (message.getContentRaw().length() > 2000) { |
158 | | - WebhookUtil.mirrorMessageToWebhook(wh, message, message.getContentRaw().substring(0, 2000), newestPost.getIdLong()); |
159 | | - WebhookUtil.mirrorMessageToWebhook(wh, message, message.getContentRaw().substring(2000), newestPost.getIdLong()); |
160 | | - } else { |
161 | | - WebhookUtil.mirrorMessageToWebhook(wh, message, message.getContentRaw(), newestPost.getIdLong()); |
| 148 | + WebhookUtil.ensureWebhookExists(newestPost.getParentChannel().asForumChannel(), wh -> |
| 149 | + getMessagesByUser(thread, author).thenAccept(messages -> { |
| 150 | + for (Message message : messages) { |
| 151 | + if (message.getAuthor().isBot() || message.getType() != MessageType.DEFAULT) continue; |
| 152 | + if (message.getContentRaw().length() > 2000) { |
| 153 | + WebhookUtil.mirrorMessageToWebhook(wh, message, message.getContentRaw().substring(0, 2000), newestPost.getIdLong()); |
| 154 | + WebhookUtil.mirrorMessageToWebhook(wh, message, message.getContentRaw().substring(2000), newestPost.getIdLong()); |
| 155 | + } else { |
| 156 | + WebhookUtil.mirrorMessageToWebhook(wh, message, message.getContentRaw(), newestPost.getIdLong()); |
| 157 | + } |
162 | 158 | } |
163 | | - }); |
164 | | - } |
165 | | - newestPost.sendMessageEmbeds(buildAuthorEmbed(author, bestAnswer)).queue(); |
166 | | - }); |
| 159 | + newestPost.sendMessageEmbeds(buildAuthorEmbed(author, bestAnswer)).queue(); |
| 160 | + })); |
167 | 161 | } |
168 | 162 | thread.getManager().setLocked(true).setArchived(true).queue(); |
169 | 163 | } |
|
0 commit comments