11package net .javadiscord .javabot .systems .qotw .submissions ;
22
3+ import lombok .Getter ;
34import lombok .RequiredArgsConstructor ;
45import lombok .extern .slf4j .Slf4j ;
56import net .dv8tion .jda .api .EmbedBuilder ;
2930import org .jetbrains .annotations .NotNull ;
3031import org .springframework .transaction .annotation .Transactional ;
3132
33+ import java .awt .Color ;
3234import java .time .Instant ;
3335import java .util .Comparator ;
3436import java .util .List ;
@@ -198,6 +200,14 @@ public void acceptSubmission(@NotNull ThreadChannel thread, @NotNull User author
198200 notificationService .withQOTW (thread .getGuild (), author ).sendBestAnswerNotification ();
199201 }
200202 notificationService .withQOTW (thread .getGuild ()).sendSubmissionActionNotification (reviewedBy .getUser (), new QOTWSubmission (thread ), bestAnswer ? SubmissionStatus .ACCEPT_BEST : SubmissionStatus .ACCEPT );
203+ sendToQOTWAnswerArchive (thread , author , bestAnswer ?AcceptedAnswerType .BEST_ANSWER :AcceptedAnswerType .ACCEPTED_ANSWER );
204+ }
205+
206+ public void copySampleAnswerSubmission (@ NotNull ThreadChannel thread , @ NotNull User author ) {
207+ sendToQOTWAnswerArchive (thread , author , AcceptedAnswerType .SAMPLE_ANSWER );
208+ }
209+
210+ private void sendToQOTWAnswerArchive (ThreadChannel thread , User author , AcceptedAnswerType type ) {
201211 Optional <ThreadChannel > newestPostOptional = config .getSubmissionsForumChannel ().getThreadChannels ()
202212 .stream ().max (Comparator .comparing (ThreadChannel ::getTimeCreated ));
203213 if (newestPostOptional .isPresent ()) {
@@ -209,9 +219,9 @@ public void acceptSubmission(@NotNull ThreadChannel thread, @NotNull User author
209219 if (message .getAuthor ().isBot () || message .getType () != MessageType .DEFAULT ) continue ;
210220 if (message .getContentRaw ().length () > 2000 ) {
211221 WebhookUtil .mirrorMessageToWebhook (wh , message , message .getContentRaw ().substring (0 , 2000 ), newestPost .getIdLong (), null , null ).join ();
212- WebhookUtil .mirrorMessageToWebhook (wh , message , message .getContentRaw ().substring (2000 ), newestPost .getIdLong (), null , lastMessage ? List .of (buildAuthorEmbed (author , bestAnswer )) : null ).join ();
222+ WebhookUtil .mirrorMessageToWebhook (wh , message , message .getContentRaw ().substring (2000 ), newestPost .getIdLong (), null , lastMessage ? List .of (buildAuthorEmbed (author , type )) : null ).join ();
213223 } else {
214- WebhookUtil .mirrorMessageToWebhook (wh , message , message .getContentRaw (), newestPost .getIdLong (), null , lastMessage ? List .of (buildAuthorEmbed (author , bestAnswer )) : null ).join ();
224+ WebhookUtil .mirrorMessageToWebhook (wh , message , message .getContentRaw (), newestPost .getIdLong (), null , lastMessage ? List .of (buildAuthorEmbed (author , type )) : null ).join ();
215225 }
216226 }
217227 }).exceptionally (err ->{
@@ -222,6 +232,15 @@ public void acceptSubmission(@NotNull ThreadChannel thread, @NotNull User author
222232 thread .getManager ().setLocked (true ).setArchived (true ).queue ();
223233 }
224234
235+ @ RequiredArgsConstructor
236+ @ Getter
237+ private enum AcceptedAnswerType {
238+ SAMPLE_ANSWER (Responses .Type .DEFAULT .getColor (), "\uD83D \uDCD6 Sample answer" ), ACCEPTED_ANSWER (Responses .Type .DEFAULT .getColor (),"Submission" ), BEST_ANSWER (Responses .Type .WARN .getColor (), "\u2B50 Submission" );
239+
240+ private final Color color ;
241+ private final String prefix ;
242+ }
243+
225244 /**
226245 * Declines a submission.
227246 *
@@ -244,10 +263,10 @@ private CompletableFuture<List<Message>> getMessagesByUser(@NotNull ThreadChanne
244263 .thenApply (list -> list .stream ().filter (m -> m .getAuthor ().equals (user )).toList ());
245264 }
246265
247- private @ NotNull MessageEmbed buildAuthorEmbed (@ NotNull User user , boolean bestAnswer ) {
266+ private @ NotNull MessageEmbed buildAuthorEmbed (@ NotNull User user , AcceptedAnswerType answerType ) {
248267 return new EmbedBuilder ()
249- .setAuthor (( bestAnswer ? " \u2B50 " : "" ) + "Submission from " + UserUtils .getUserTag (user ), null , user .getAvatarUrl ())
250- .setColor (bestAnswer ? Responses . Type . WARN . getColor () : Responses . Type . DEFAULT .getColor ())
268+ .setAuthor (answerType . getPrefix ( ) + " from " + UserUtils .getUserTag (user ), null , user .getAvatarUrl ())
269+ .setColor (answerType .getColor ())
251270 .build ();
252271 }
253272
0 commit comments