88import net .dv8tion .jda .api .entities .Message ;
99import net .dv8tion .jda .api .entities .MessageEmbed ;
1010import net .dv8tion .jda .api .entities .MessageHistory ;
11+ import net .dv8tion .jda .api .entities .channel .concrete .ThreadChannel ;
1112import net .dv8tion .jda .api .entities .channel .middleman .MessageChannel ;
1213import net .dv8tion .jda .api .interactions .components .ActionRow ;
1314import net .dv8tion .jda .api .interactions .components .buttons .Button ;
15+ import net .dv8tion .jda .api .interactions .components .selections .SelectOption ;
16+ import net .dv8tion .jda .api .interactions .components .selections .StringSelectMenu ;
1417import net .dv8tion .jda .api .requests .restaction .ForumPostAction ;
1518import net .dv8tion .jda .api .utils .messages .MessageCreateBuilder ;
1619import net .dv8tion .jda .api .utils .messages .MessageCreateData ;
1720import net .javadiscord .javabot .data .config .BotConfig ;
1821import net .javadiscord .javabot .data .config .GuildConfig ;
22+ import net .javadiscord .javabot .data .config .SystemsConfig ;
1923import net .javadiscord .javabot .data .config .guild .QOTWConfig ;
2024import net .javadiscord .javabot .systems .notification .NotificationService ;
2125import net .javadiscord .javabot .systems .qotw .dao .QuestionQueueRepository ;
2226import net .javadiscord .javabot .systems .qotw .model .QOTWQuestion ;
27+ import net .javadiscord .javabot .systems .qotw .model .QOTWSubmission ;
28+ import net .javadiscord .javabot .systems .qotw .submissions .SubmissionStatus ;
2329import org .jetbrains .annotations .NotNull ;
2430import org .springframework .scheduling .annotation .Scheduled ;
2531import org .springframework .stereotype .Service ;
32+ import xyz .dynxsty .dih4jda .util .ComponentIdBuilder ;
2633
34+ import javax .annotation .Nonnull ;
2735import java .sql .SQLException ;
2836import java .util .Collections ;
2937import java .util .List ;
3038import java .util .Optional ;
3139import java .util .concurrent .ExecutorService ;
32- import java .util .stream .Collectors ;
3340
3441/**
3542 * Job which disables the Submission button.
@@ -65,15 +72,20 @@ public void execute() throws SQLException {
6572 questionMessage .editMessageComponents (ActionRow .of (Button .secondary ("qotw-submission:closed" , "Submissions closed" ).asDisabled ())).queue ();
6673 notificationService .withGuild (guild )
6774 .sendToModerationLog (log ->
68- log .sendMessageFormat ("%s%nIt's review time! There are **%s** threads to review:%n%n%s " ,
75+ log .sendMessageFormat ("%s%nIt's review time! There are **%s** threads to review" ,
6976 qotwConfig .getQOTWReviewRole ().getAsMention (),
70- qotwConfig .getSubmissionChannel ().getThreadChannels ().size (),
71- qotwConfig .getSubmissionChannel ().getThreadChannels ().stream ()
72- .map (t -> "> %s (%d message(s))" .formatted (t .getAsMention (), t .getMessageCount () - 2 )) // NOTE: Subtract 2 messages which are send by the bot
73- .collect (Collectors .joining ("\n " )))
77+ qotwConfig .getSubmissionChannel ().getThreadChannels ().size ())
7478 );
75- qotwConfig .getSubmissionChannel ().getThreadChannels ().forEach (t ->
76- t .getManager ().setName (SUBMISSION_PENDING + t .getName ()).queue ());
79+ for (ThreadChannel submission : qotwConfig .getSubmissionChannel ().getThreadChannels ()) {
80+ notificationService .withGuild (guild ).sendToModerationLog (log ->
81+ log .sendMessage (submission .getAsMention ())
82+ .addActionRow (buildSubmissionSelectMenu (jda , submission .getIdLong ()))
83+ );
84+ submission .getManager ().setName (SUBMISSION_PENDING + submission .getName ()).queue ();
85+ // remove the author
86+ final QOTWSubmission s = new QOTWSubmission (submission );
87+ s .retrieveAuthor (author -> submission .removeThreadMember (author ).queue ());
88+ }
7789 if (qotwConfig .getSubmissionsForumChannel () == null ) continue ;
7890 asyncPool .execute (() -> {
7991 MessageEmbed embed = questionMessage .getEmbeds ().get (0 );
@@ -94,6 +106,29 @@ public void execute() throws SQLException {
94106 }
95107 }
96108
109+ private @ Nonnull StringSelectMenu buildSubmissionSelectMenu (JDA jda , long threadId ) {
110+ final SystemsConfig .EmojiConfig emojiConfig = botConfig .getSystems ().getEmojiConfig ();
111+ return StringSelectMenu .create (ComponentIdBuilder .build ("qotw-submission-select" , "review" , threadId ))
112+ .setPlaceholder ("Select an action for this submission" )
113+ .addOptions (
114+ SelectOption .of ("Accept (Best Answer)" , SubmissionStatus .ACCEPT_BEST .name ())
115+ .withDescription ("The submission is correct and is considered to be among the \" best answers\" " )
116+ .withEmoji (emojiConfig .getSuccessEmote (jda )),
117+ SelectOption .of ("Accept" , SubmissionStatus .ACCEPT .name ())
118+ .withDescription ("The overall submission is correct" )
119+ .withEmoji (emojiConfig .getSuccessEmote (jda )),
120+ SelectOption .of ("Decline: Wrong Answer" , SubmissionStatus .DECLINE .name () + ":1" )
121+ .withDescription ("The submission is simply wrong or falsely explained" )
122+ .withEmoji (emojiConfig .getFailureEmote (jda )),
123+ SelectOption .of ("Decline: Too short" , SubmissionStatus .DECLINE .name () + ":2" )
124+ .withDescription ("The submission is way to short in comparison to other submissions" )
125+ .withEmoji (emojiConfig .getFailureEmote (jda )),
126+ SelectOption .of ("Decline: Empty Submission" , SubmissionStatus .DECLINE .name () + ":3" )
127+ .withDescription ("The submission was empty" )
128+ .withEmoji (emojiConfig .getFailureEmote (jda ))
129+ ).build ();
130+ }
131+
97132 private @ NotNull MessageEmbed buildQuestionEmbed (@ NotNull QOTWQuestion question ) {
98133 return new EmbedBuilder ()
99134 .setTitle ("Question of the Week #" + question .getQuestionNumber ())
0 commit comments