1111import net .dv8tion .jda .api .entities .channel .ChannelType ;
1212import net .dv8tion .jda .api .entities .channel .concrete .ThreadChannel ;
1313import net .dv8tion .jda .api .events .interaction .component .ButtonInteractionEvent ;
14+ import net .dv8tion .jda .api .events .interaction .component .StringSelectInteractionEvent ;
1415import net .dv8tion .jda .api .interactions .InteractionHook ;
1516import net .dv8tion .jda .api .interactions .components .ActionRow ;
1617import net .dv8tion .jda .api .interactions .components .buttons .Button ;
@@ -99,6 +100,52 @@ public List<QOTWSubmission> getActiveSubmissions() {
99100 .map (QOTWSubmission ::new ).toList ();
100101 }
101102
103+ /**
104+ * Handles a submission review using a {@link net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu}.
105+ *
106+ * @param event The {@link StringSelectInteractionEvent} that was fired.
107+ * @param threadId The submissions' thread-id.
108+ */
109+ public void handleSelectReview (StringSelectInteractionEvent event , String threadId ) {
110+ if (event .getGuild () == null ) {
111+ Responses .replyGuildOnly (event ).queue ();
112+ return ;
113+ }
114+ final ThreadChannel submissionThread = event .getGuild ().getThreadChannelById (threadId );
115+ if (submissionThread == null ) {
116+ Responses .error (event , "Could not find submission thread!" ).queue ();
117+ return ;
118+ }
119+ if (submissionThread .getParentChannel ().getIdLong () != config .getSubmissionChannelId ()) {
120+ Responses .error (event , "The selected thread is not a submission channel!" ).queue ();
121+ return ;
122+ }
123+ if (event .getValues ().size () != 1 ) {
124+ Responses .error (event , "Please select an action!" ).queue ();
125+ return ;
126+ }
127+ final SubmissionStatus status = SubmissionStatus .valueOf (event .getValues ().get (0 ));
128+ event .deferReply ().queue ();
129+ final QOTWSubmission submission = new QOTWSubmission (submissionThread );
130+ submission .retrieveAuthor (author -> {
131+ switch (status ) {
132+ case ACCEPT_BEST -> acceptSubmission (event .getHook (), submissionThread , author , true );
133+ case ACCEPT -> acceptSubmission (event .getHook (), submissionThread , author , false );
134+ default -> declineSubmission (event .getHook (), submissionThread , author , status );
135+ }
136+ if (config .getSubmissionChannel ().getThreadChannels ().size () <= 1 ) {
137+ Optional <ThreadChannel > newestPostOptional = config .getSubmissionsForumChannel ().getThreadChannels ()
138+ .stream ().max (Comparator .comparing (ThreadChannel ::getTimeCreated ));
139+ newestPostOptional .ifPresent (p -> {
140+ p .getManager ().setAppliedTags ().queue ();
141+ notificationService .withGuild (config .getGuild ()).sendToModerationLog (log -> log .sendMessageFormat ("All submissions have been reviewed!" ));
142+ });
143+ }
144+ event .getMessage ().editMessageComponents (ActionRow .of (Button .secondary ("dummy" , "%s by %s" .formatted (status .getVerb (), event .getUser ().getAsTag ())))).queue ();
145+ Responses .info (event , "Review done!" , "Successfully reviewed %s! (`%s`)" , submissionThread .getAsMention (), status ).queue ();
146+ });
147+ }
148+
102149 /**
103150 * Handles the "Delete Submission" Button.
104151 *
@@ -151,10 +198,10 @@ public void acceptSubmission(InteractionHook hook, @NotNull ThreadChannel thread
151198 boolean lastMessage = messages .indexOf (message ) + 1 == messages .size ();
152199 if (message .getAuthor ().isBot () || message .getType () != MessageType .DEFAULT ) continue ;
153200 if (message .getContentRaw ().length () > 2000 ) {
154- WebhookUtil .mirrorMessageToWebhook (wh , message , message .getContentRaw ().substring (0 , 2000 ), newestPost .getIdLong (), null , null );
155- WebhookUtil .mirrorMessageToWebhook (wh , message , message .getContentRaw ().substring (2000 ), newestPost .getIdLong (), null , lastMessage ? List .of (buildAuthorEmbed (author , bestAnswer )) : null );
201+ WebhookUtil .mirrorMessageToWebhook (wh , message , message .getContentRaw ().substring (0 , 2000 ), newestPost .getIdLong (), null , null ). join () ;
202+ WebhookUtil .mirrorMessageToWebhook (wh , message , message .getContentRaw ().substring (2000 ), newestPost .getIdLong (), null , lastMessage ? List .of (buildAuthorEmbed (author , bestAnswer )) : null ). join () ;
156203 } else {
157- WebhookUtil .mirrorMessageToWebhook (wh , message , message .getContentRaw (), newestPost .getIdLong (), null , lastMessage ? List .of (buildAuthorEmbed (author , bestAnswer )) : null );
204+ WebhookUtil .mirrorMessageToWebhook (wh , message , message .getContentRaw (), newestPost .getIdLong (), null , lastMessage ? List .of (buildAuthorEmbed (author , bestAnswer )) : null ). join () ;
158205 }
159206 }
160207 }));
@@ -168,12 +215,13 @@ public void acceptSubmission(InteractionHook hook, @NotNull ThreadChannel thread
168215 * @param hook The {@link net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent} that was fired.
169216 * @param thread The submission's {@link ThreadChannel}.
170217 * @param author The submissions' author.
218+ * @param status The {@link SubmissionStatus}.
171219 */
172- public void declineSubmission (InteractionHook hook , @ NotNull ThreadChannel thread , User author ) {
220+ public void declineSubmission (InteractionHook hook , @ NotNull ThreadChannel thread , User author , SubmissionStatus status ) {
173221 thread .getManager ().setName (SUBMISSION_DECLINED + thread .getName ().substring (1 )).queue ();
174- notificationService .withQOTW (thread .getGuild (), author ).sendSubmissionDeclinedEmbed ();
222+ notificationService .withQOTW (thread .getGuild (), author ).sendSubmissionDeclinedEmbed (status );
175223 Responses .success (hook , "Submission Declined" , "Successfully declined submission by " + author .getAsMention ()).queue ();
176- notificationService .withQOTW (thread .getGuild ()).sendSubmissionActionNotification (author , new QOTWSubmission (thread ), SubmissionStatus . DECLINE );
224+ notificationService .withQOTW (thread .getGuild ()).sendSubmissionActionNotification (author , new QOTWSubmission (thread ), status );
177225 thread .getManager ().setLocked (true ).setArchived (true ).queue ();
178226 }
179227
0 commit comments