| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,9 @@ | |||
| 10 | 10 | import net.discordjug.javabot.data.config.BotConfig; | |
| 11 | 11 | import org.springframework.stereotype.Service; | |
| 12 | 12 | ||
| 13 | + /** | ||
| 14 | + * A service class for interacting with the Answer Overflow bot. | ||
| 15 | + */ | ||
| 13 | 16 | @Service | |
| 14 | 17 | @Slf4j | |
| 15 | 18 | public class AnswerOverflowService { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | import net.discordjug.javabot.data.config.GuildConfig; | |
| 6 | 6 | import net.discordjug.javabot.data.config.SystemsConfig; | |
| 7 | 7 | import net.discordjug.javabot.data.config.guild.QOTWConfig; | |
| 8 | + import net.discordjug.javabot.systems.help.AnswerOverflowService; | ||
| 8 | 9 | import net.discordjug.javabot.systems.notification.NotificationService; | |
| 9 | 10 | import net.discordjug.javabot.systems.qotw.QOTWPointsService; | |
| 10 | 11 | import net.discordjug.javabot.systems.qotw.dao.QuestionQueueRepository; | |
@@ -63,6 +64,7 @@ public class QOTWCloseSubmissionsJob { | |||
| 63 | 64 | private final ExecutorService asyncPool; | |
| 64 | 65 | private final QOTWPointsService pointsService; | |
| 65 | 66 | private final NotificationService notificationService; | |
| 67 | + private final AnswerOverflowService answerOverflowService; | ||
| 66 | 68 | private final BotConfig botConfig; | |
| 67 | 69 | ||
| 68 | 70 | /** | |
@@ -131,7 +133,7 @@ private void sendReviewInformation(Guild guild, QOTWConfig qotwConfig, TextChann | |||
| 131 | 133 | s.retrieveAuthor(author -> { | |
| 132 | 134 | submission.removeThreadMember(author).queue(); | |
| 133 | 135 | if (author.getIdLong() == qotwConfig.getQotwSampleAnswerUserId()) { | |
| 134 | - SubmissionManager manager = new SubmissionManager(botConfig.get(guild).getQotwConfig(), pointsService, questionQueueRepository, notificationService, asyncPool); | ||
| 136 | + SubmissionManager manager = new SubmissionManager(botConfig.get(guild).getQotwConfig(), pointsService, questionQueueRepository, notificationService, asyncPool, answerOverflowService); | ||
| 135 | 137 | manager.copySampleAnswerSubmission(submission, author); | |
| 136 | 138 | } else { | |
| 137 | 139 | thread | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | 3 | import net.discordjug.javabot.data.config.BotConfig; | |
| 4 | 4 | import net.discordjug.javabot.data.config.guild.QOTWConfig; | |
| 5 | + import net.discordjug.javabot.systems.help.AnswerOverflowService; | ||
| 5 | 6 | import net.discordjug.javabot.systems.notification.NotificationService; | |
| 6 | 7 | import net.discordjug.javabot.systems.qotw.QOTWPointsService; | |
| 7 | 8 | import net.discordjug.javabot.systems.qotw.dao.QuestionQueueRepository; | |
@@ -33,6 +34,7 @@ public class QOTWUserReminderJob { | |||
| 33 | 34 | private final QOTWPointsService pointsService; | |
| 34 | 35 | private final NotificationService notificationService; | |
| 35 | 36 | private final QuestionQueueRepository questionQueueRepository; | |
| 37 | + private final AnswerOverflowService answerOverflowService; | ||
| 36 | 38 | private final ExecutorService asyncPool; | |
| 37 | 39 | ||
| 38 | 40 | /** | |
@@ -42,7 +44,7 @@ public class QOTWUserReminderJob { | |||
| 42 | 44 | public void execute() { | |
| 43 | 45 | for (Guild guild : jda.getGuilds()) { | |
| 44 | 46 | QOTWConfig config = botConfig.get(guild).getQotwConfig(); | |
| 45 | - List<QOTWSubmission> submissions = new SubmissionManager(config, pointsService, questionQueueRepository, notificationService, asyncPool).getActiveSubmissions(); | ||
| 47 | + List<QOTWSubmission> submissions = new SubmissionManager(config, pointsService, questionQueueRepository, notificationService, asyncPool, answerOverflowService).getActiveSubmissions(); | ||
| 46 | 48 | for (QOTWSubmission submission : submissions) { | |
| 47 | 49 | submission.retrieveAuthor(author -> { | |
| 48 | 50 | UserPreference preference = userPreferenceService.getOrCreate(author.getIdLong(), Preference.QOTW_REMINDER); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ | |||
| 8 | 8 | import lombok.RequiredArgsConstructor; | |
| 9 | 9 | import net.discordjug.javabot.annotations.AutoDetectableComponentHandler; | |
| 10 | 10 | import net.discordjug.javabot.data.config.BotConfig; | |
| 11 | + import net.discordjug.javabot.systems.help.AnswerOverflowService; | ||
| 11 | 12 | import net.discordjug.javabot.systems.notification.NotificationService; | |
| 12 | 13 | import net.discordjug.javabot.systems.qotw.QOTWPointsService; | |
| 13 | 14 | import net.discordjug.javabot.systems.qotw.dao.QuestionQueueRepository; | |
@@ -29,11 +30,12 @@ public class SubmissionInteractionManager implements ButtonHandler, StringSelect | |||
| 29 | 30 | private final NotificationService notificationService; | |
| 30 | 31 | private final BotConfig botConfig; | |
| 31 | 32 | private final QuestionQueueRepository questionQueueRepository; | |
| 33 | + private final AnswerOverflowService answerOverflowService; | ||
| 32 | 34 | private final ExecutorService asyncPool; | |
| 33 | 35 | ||
| 34 | 36 | @Override | |
| 35 | 37 | public void handleButton(@NotNull ButtonInteractionEvent event, Button button) { | |
| 36 | - SubmissionManager manager = new SubmissionManager(botConfig.get(event.getGuild()).getQotwConfig(), pointsService, questionQueueRepository, notificationService, asyncPool); | ||
| 38 | + SubmissionManager manager = new SubmissionManager(botConfig.get(event.getGuild()).getQotwConfig(), pointsService, questionQueueRepository, notificationService, asyncPool, answerOverflowService); | ||
| 37 | 39 | String[] id = ComponentIdBuilder.split(event.getComponentId()); | |
| 38 | 40 | switch (id[1]) { | |
| 39 | 41 | case "submit" -> manager.handleSubmission(event, Integer.parseInt(id[2])).queue(); | |
@@ -43,7 +45,7 @@ public void handleButton(@NotNull ButtonInteractionEvent event, Button button) { | |||
| 43 | 45 | ||
| 44 | 46 | @Override | |
| 45 | 47 | public void handleStringSelectMenu(@NotNull StringSelectInteractionEvent event, @NotNull List<String> values) { | |
| 46 | - SubmissionManager manager = new SubmissionManager(botConfig.get(event.getGuild()).getQotwConfig(), pointsService, questionQueueRepository, notificationService, asyncPool); | ||
| 48 | + SubmissionManager manager = new SubmissionManager(botConfig.get(event.getGuild()).getQotwConfig(), pointsService, questionQueueRepository, notificationService, asyncPool, answerOverflowService); | ||
| 47 | 49 | String[] id = ComponentIdBuilder.split(event.getComponentId()); | |
| 48 | 50 | switch (id[1]) { | |
| 49 | 51 | case "review" -> manager.handleSelectReview(event, id[2]); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | import lombok.RequiredArgsConstructor; | |
| 5 | 5 | import lombok.extern.slf4j.Slf4j; | |
| 6 | 6 | import net.discordjug.javabot.data.config.guild.QOTWConfig; | |
| 7 | + import net.discordjug.javabot.systems.help.AnswerOverflowService; | ||
| 7 | 8 | import net.discordjug.javabot.systems.notification.NotificationService; | |
| 8 | 9 | import net.discordjug.javabot.systems.qotw.QOTWPointsService; | |
| 9 | 10 | import net.discordjug.javabot.systems.qotw.dao.QuestionQueueRepository; | |
@@ -39,6 +40,8 @@ | |||
| 39 | 40 | import java.util.concurrent.CompletableFuture; | |
| 40 | 41 | import java.util.concurrent.ExecutorService; | |
| 41 | 42 | ||
| 43 | + import club.minnced.discord.webhook.receive.ReadonlyMessage; | ||
| 44 | + | ||
| 42 | 45 | /** | |
| 43 | 46 | * Handles & manages QOTW Submissions by using Discords {@link ThreadChannel}s. | |
| 44 | 47 | */ | |
@@ -57,6 +60,7 @@ public class SubmissionManager { | |||
| 57 | 60 | private final QuestionQueueRepository questionQueueRepository; | |
| 58 | 61 | private final NotificationService notificationService; | |
| 59 | 62 | private final ExecutorService asyncPool; | |
| 63 | + private final AnswerOverflowService answerOverflowService; | ||
| 60 | 64 | ||
| 61 | 65 | /** | |
| 62 | 66 | * Handles the "Submit your Answer" Button interaction. | |
@@ -221,14 +225,19 @@ private void sendToQOTWAnswerArchive(ThreadChannel thread, User author, Accepted | |||
| 221 | 225 | ThreadChannel newestPost = newestPostOptional.get(); | |
| 222 | 226 | WebhookUtil.ensureWebhookExists(newestPost.getParentChannel().asForumChannel(), wh -> | |
| 223 | 227 | getMessagesByUser(thread, author).thenAccept(messages -> { | |
| 224 | - for (Message message : messages) { | ||
| 225 | - boolean lastMessage = messages.indexOf(message) + 1 == messages.size(); | ||
| 228 | + for (int i = 0; i < messages.size(); i++) { | ||
| 229 | + Message message = messages.get(i); | ||
| 230 | + boolean lastMessage = i + 1 == messages.size(); | ||
| 226 | 231 | if (message.getAuthor().isBot() || message.getType() != MessageType.DEFAULT) continue; | |
| 232 | + ReadonlyMessage firstPostedMessage; | ||
| 227 | 233 | if (message.getContentRaw().length() > 2000) { | |
| 228 | - WebhookUtil.mirrorMessageToWebhook(wh, message, message.getContentRaw().substring(0, 2000), newestPost.getIdLong(), null, null).join(); | ||
| 234 | + firstPostedMessage = WebhookUtil.mirrorMessageToWebhook(wh, message, message.getContentRaw().substring(0, 2000), newestPost.getIdLong(), null, null).join(); | ||
| 229 | 235 | WebhookUtil.mirrorMessageToWebhook(wh, message, message.getContentRaw().substring(2000), newestPost.getIdLong(), null, lastMessage ? List.of(buildAuthorEmbed(author, type)) : null).join(); | |
| 230 | 236 | } else { | |
| 231 | - WebhookUtil.mirrorMessageToWebhook(wh, message, message.getContentRaw(), newestPost.getIdLong(), null, lastMessage ? List.of(buildAuthorEmbed(author, type)) : null).join(); | ||
| 237 | + firstPostedMessage = WebhookUtil.mirrorMessageToWebhook(wh, message, message.getContentRaw(), newestPost.getIdLong(), null, lastMessage ? List.of(buildAuthorEmbed(author, type)) : null).join(); | ||
| 238 | + } | ||
| 239 | + if (i == 0 && (type == AcceptedAnswerType.BEST_ANSWER || type == AcceptedAnswerType.SAMPLE_ANSWER)) { | ||
| 240 | + answerOverflowService.markAnswer(firstPostedMessage.getChannelId(), firstPostedMessage.getId()); | ||
| 232 | 241 | } | |
| 233 | 242 | } | |
| 234 | 243 | }).exceptionally(err->{ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | 3 | import net.discordjug.javabot.data.config.BotConfig; | |
| 4 | 4 | import net.discordjug.javabot.data.config.guild.QOTWConfig; | |
| 5 | + import net.discordjug.javabot.systems.help.AnswerOverflowService; | ||
| 5 | 6 | import net.discordjug.javabot.systems.notification.NotificationService; | |
| 6 | 7 | import net.discordjug.javabot.systems.qotw.QOTWPointsService; | |
| 7 | 8 | import net.discordjug.javabot.systems.qotw.dao.QuestionQueueRepository; | |
@@ -34,7 +35,7 @@ public class QOTWReviewSubcommand extends SlashCommand.Subcommand { | |||
| 34 | 35 | private final QuestionQueueRepository questionQueueRepository; | |
| 35 | 36 | private final BotConfig botConfig; | |
| 36 | 37 | private final ExecutorService asyncPool; | |
| 37 | - | ||
| 38 | + private final AnswerOverflowService answerOverflowService; | ||
| 38 | 39 | ||
| 39 | 40 | /** | |
| 40 | 41 | * The constructor of this class, which sets the corresponding {@link SubcommandData}. | |
@@ -43,13 +44,15 @@ public class QOTWReviewSubcommand extends SlashCommand.Subcommand { | |||
| 43 | 44 | * @param questionQueueRepository The {@link QuestionQueueRepository}. | |
| 44 | 45 | * @param botConfig The main configuration of the bot | |
| 45 | 46 | * @param asyncPool The main thread pool for asynchronous operations | |
| 47 | + * @param answerOverflowService The {@link AnswerOverflowService} for interacting with the Answer Overflow bot. | ||
| 46 | 48 | */ | |
| 47 | - public QOTWReviewSubcommand(QOTWPointsService pointsService, NotificationService notificationService, QuestionQueueRepository questionQueueRepository, BotConfig botConfig, ExecutorService asyncPool) { | ||
| 49 | + public QOTWReviewSubcommand(QOTWPointsService pointsService, NotificationService notificationService, QuestionQueueRepository questionQueueRepository, BotConfig botConfig, ExecutorService asyncPool, AnswerOverflowService answerOverflowService) { | ||
| 48 | 50 | this.pointsService = pointsService; | |
| 49 | 51 | this.notificationService = notificationService; | |
| 50 | 52 | this.questionQueueRepository = questionQueueRepository; | |
| 51 | 53 | this.botConfig = botConfig; | |
| 52 | 54 | this.asyncPool = asyncPool; | |
| 55 | + this.answerOverflowService = answerOverflowService; | ||
| 53 | 56 | setCommandData(new SubcommandData("review", "Administrative command for reviewing QOTW-submissions") | |
| 54 | 57 | .addOptions( | |
| 55 | 58 | new OptionData(OptionType.CHANNEL, "submission", "A users' submission", true) | |
@@ -80,7 +83,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { | |||
| 80 | 83 | event.deferReply().queue(); | |
| 81 | 84 | QOTWSubmission submission = new QOTWSubmission(submissionThread); | |
| 82 | 85 | submission.retrieveAuthor(author -> { | |
| 83 | - SubmissionManager manager = new SubmissionManager(qotwConfig, pointsService, questionQueueRepository, notificationService, asyncPool); | ||
| 86 | + SubmissionManager manager = new SubmissionManager(qotwConfig, pointsService, questionQueueRepository, notificationService, asyncPool, answerOverflowService); | ||
| 84 | 87 | if (state.contains("ACCEPT")) { | |
| 85 | 88 | manager.acceptSubmission(submissionThread, author, event.getMember(), state.equals("ACCEPT_BEST")); | |
| 86 | 89 | Responses.success(event.getHook(), "Submission Accepted", "Successfully accepted submission by " + author.getAsMention()).queue(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments