44import lombok .RequiredArgsConstructor ;
55import lombok .extern .slf4j .Slf4j ;
66import net .discordjug .javabot .data .config .guild .QOTWConfig ;
7+ import net .discordjug .javabot .systems .help .AnswerOverflowService ;
78import net .discordjug .javabot .systems .notification .NotificationService ;
89import net .discordjug .javabot .systems .qotw .QOTWPointsService ;
910import net .discordjug .javabot .systems .qotw .dao .QuestionQueueRepository ;
3940import java .util .concurrent .CompletableFuture ;
4041import java .util .concurrent .ExecutorService ;
4142
43+ import club .minnced .discord .webhook .receive .ReadonlyMessage ;
44+
4245/**
4346 * Handles & manages QOTW Submissions by using Discords {@link ThreadChannel}s.
4447 */
@@ -57,6 +60,7 @@ public class SubmissionManager {
5760 private final QuestionQueueRepository questionQueueRepository ;
5861 private final NotificationService notificationService ;
5962 private final ExecutorService asyncPool ;
63+ private final AnswerOverflowService answerOverflowService ;
6064
6165 /**
6266 * Handles the "Submit your Answer" Button interaction.
@@ -221,14 +225,19 @@ private void sendToQOTWAnswerArchive(ThreadChannel thread, User author, Accepted
221225 ThreadChannel newestPost = newestPostOptional .get ();
222226 WebhookUtil .ensureWebhookExists (newestPost .getParentChannel ().asForumChannel (), wh ->
223227 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 ();
226231 if (message .getAuthor ().isBot () || message .getType () != MessageType .DEFAULT ) continue ;
232+ ReadonlyMessage firstPostedMessage ;
227233 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 ();
229235 WebhookUtil .mirrorMessageToWebhook (wh , message , message .getContentRaw ().substring (2000 ), newestPost .getIdLong (), null , lastMessage ? List .of (buildAuthorEmbed (author , type )) : null ).join ();
230236 } 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 ());
232241 }
233242 }
234243 }).exceptionally (err ->{
0 commit comments