Skip to content

Commit c5d94fc

Browse files
authored
Merge pull request #387 from danthe1st/qotw-unclutter-review
create thread for QOTW review
2 parents cd27c02 + e4d3ca9 commit c5d94fc

File tree

3 files changed

+40
-35
lines changed

3 files changed

+40
-35
lines changed

src/main/java/net/javadiscord/javabot/systems/qotw/jobs/QOTWCloseSubmissionsJob.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.dv8tion.jda.api.entities.Message;
99
import net.dv8tion.jda.api.entities.MessageEmbed;
1010
import net.dv8tion.jda.api.entities.MessageHistory;
11+
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
1112
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
1213
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
1314
import net.dv8tion.jda.api.interactions.components.ActionRow;
@@ -21,7 +22,6 @@
2122
import net.javadiscord.javabot.data.config.GuildConfig;
2223
import net.javadiscord.javabot.data.config.SystemsConfig;
2324
import net.javadiscord.javabot.data.config.guild.QOTWConfig;
24-
import net.javadiscord.javabot.systems.notification.NotificationService;
2525
import net.javadiscord.javabot.systems.qotw.dao.QuestionQueueRepository;
2626
import net.javadiscord.javabot.systems.qotw.model.QOTWQuestion;
2727
import net.javadiscord.javabot.systems.qotw.model.QOTWSubmission;
@@ -47,7 +47,6 @@ public class QOTWCloseSubmissionsJob {
4747
private static final String SUBMISSION_PENDING = "\uD83D\uDD52 ";
4848

4949
private final JDA jda;
50-
private final NotificationService notificationService;
5150
private final QuestionQueueRepository questionQueueRepository;
5251
private final ExecutorService asyncPool;
5352
private final BotConfig botConfig;
@@ -66,28 +65,30 @@ public void execute() throws SQLException {
6665
qotwConfig.getSubmissionChannel().getManager()
6766
.putRolePermissionOverride(guild.getIdLong(), Collections.emptySet(), Collections.singleton(Permission.MESSAGE_SEND_IN_THREADS))
6867
.queue();
69-
if (config.getModerationConfig().getLogChannel() == null) continue;
68+
TextChannel logChannel = config.getModerationConfig().getLogChannel();
69+
if (logChannel == null) continue;
7070
if (qotwConfig.getSubmissionChannel() == null || qotwConfig.getQuestionChannel() == null) continue;
7171
Message questionMessage = getLatestQOTWMessage(qotwConfig.getQuestionChannel(), qotwConfig, jda);
7272
questionMessage.editMessageComponents(ActionRow.of(Button.secondary("qotw-submission:closed", "Submissions closed").asDisabled())).queue();
73-
notificationService.withGuild(guild)
74-
.sendToModerationLog(log ->
75-
log.sendMessageFormat("%s%nIt's review time! There are **%s** threads to review",
73+
logChannel
74+
.sendMessageFormat("%s%nIt's review time! There are **%s** threads to review",
7675
qotwConfig.getQOTWReviewRole().getAsMention(),
7776
qotwConfig.getSubmissionChannel().getThreadChannels().size())
78-
);
79-
for (ThreadChannel submission : qotwConfig.getSubmissionChannel().getThreadChannels()) {
80-
submission.getManager().setName(SUBMISSION_PENDING + submission.getName()).queue();
81-
// remove the author
82-
final QOTWSubmission s = new QOTWSubmission(submission);
83-
s.retrieveAuthor(author -> {
84-
submission.removeThreadMember(author).queue();
85-
notificationService.withGuild(guild).sendToModerationLog(log ->
86-
log.sendMessage("%s by %s".formatted(submission.getAsMention(), author.getAsMention()))
87-
.addActionRow(buildSubmissionSelectMenu(jda, submission.getIdLong()))
88-
);
77+
.flatMap(msg -> msg.createThreadChannel("QOTW review"))
78+
.queue(thread -> {
79+
for (ThreadChannel submission : qotwConfig.getSubmissionChannel().getThreadChannels()) {
80+
submission.getManager().setName(SUBMISSION_PENDING + submission.getName()).queue();
81+
// remove the author
82+
final QOTWSubmission s = new QOTWSubmission(submission);
83+
s.retrieveAuthor(author -> {
84+
submission.removeThreadMember(author).queue();
85+
thread
86+
.sendMessage("%s by %s".formatted(submission.getAsMention(), author.getAsMention()))
87+
.addActionRow(buildSubmissionSelectMenu(jda, submission.getIdLong()))
88+
.queue();
89+
});
90+
}
8991
});
90-
}
9192
if (qotwConfig.getSubmissionsForumChannel() == null) continue;
9293
asyncPool.execute(() -> {
9394
MessageEmbed embed = questionMessage.getEmbeds().get(0);

src/main/java/net/javadiscord/javabot/systems/qotw/submissions/SubmissionManager.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import net.dv8tion.jda.api.entities.User;
1111
import net.dv8tion.jda.api.entities.channel.ChannelType;
1212
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
13+
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
1314
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
1415
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
15-
import net.dv8tion.jda.api.interactions.InteractionHook;
1616
import net.dv8tion.jda.api.interactions.components.ActionRow;
1717
import net.dv8tion.jda.api.interactions.components.buttons.Button;
1818
import net.dv8tion.jda.api.requests.restaction.WebhookMessageCreateAction;
@@ -125,24 +125,31 @@ public void handleSelectReview(StringSelectInteractionEvent event, String thread
125125
return;
126126
}
127127
final SubmissionStatus status = SubmissionStatus.valueOf(event.getValues().get(0));
128-
event.deferReply().queue();
128+
event.deferEdit().queue();
129129
final QOTWSubmission submission = new QOTWSubmission(submissionThread);
130130
submission.retrieveAuthor(author -> {
131131
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);
132+
case ACCEPT_BEST -> acceptSubmission(submissionThread, author, true);
133+
case ACCEPT -> acceptSubmission(submissionThread, author, false);
134+
default -> declineSubmission(submissionThread, author, status);
135135
}
136136
if (config.getSubmissionChannel().getThreadChannels().size() <= 1) {
137137
Optional<ThreadChannel> newestPostOptional = config.getSubmissionsForumChannel().getThreadChannels()
138138
.stream().max(Comparator.comparing(ThreadChannel::getTimeCreated));
139139
newestPostOptional.ifPresent(p -> {
140140
p.getManager().setAppliedTags().queue();
141-
notificationService.withGuild(config.getGuild()).sendToModerationLog(log -> log.sendMessageFormat("All submissions have been reviewed!"));
141+
MessageChannelUnion channel = event
142+
.getChannel();
143+
channel
144+
.sendMessageFormat("All submissions have been reviewed!")
145+
.queue(msg -> {
146+
if(channel.getType().isThread()) {
147+
channel.asThreadChannel().getManager().setLocked(true).queue();
148+
}
149+
});
142150
});
143151
}
144-
event.getMessage().editMessageComponents(ActionRow.of(Button.secondary("dummy", "%s by %s".formatted(status.getVerb(), event.getUser().getAsTag())).asDisabled())).queue();
145-
Responses.info(event, "Review done!", "Successfully reviewed %s! (`%s`)", submissionThread.getAsMention(), status).queue();
152+
event.getHook().editOriginalComponents(ActionRow.of(Button.secondary("dummy", "%s by %s".formatted(status.getVerb(), event.getUser().getAsTag())).asDisabled())).queue();
146153
});
147154
}
148155

@@ -172,21 +179,18 @@ private boolean canCreateSubmissions(Member member) {
172179
/**
173180
* Accepts a submission.
174181
*
175-
* @param hook The {@link net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent} that was fired.
176182
* @param thread The submission's {@link ThreadChannel}.
177183
* @param author The submissions' author.
178184
* @param bestAnswer Whether the submission is among the best answers for this week.
179185
*/
180-
public void acceptSubmission(InteractionHook hook, @NotNull ThreadChannel thread, @NotNull User author, boolean bestAnswer) {
186+
public void acceptSubmission(@NotNull ThreadChannel thread, @NotNull User author, boolean bestAnswer) {
181187
thread.getManager().setName(SUBMISSION_ACCEPTED + thread.getName().substring(1)).queue();
182188
pointsService.increment(author.getIdLong());
183189
notificationService.withQOTW(thread.getGuild(), author).sendAccountIncrementedNotification();
184190
if (bestAnswer) {
185191
pointsService.increment(author.getIdLong());
186192
notificationService.withQOTW(thread.getGuild(), author).sendBestAnswerNotification();
187193
}
188-
Responses.success(hook, "Submission Accepted",
189-
"Successfully accepted submission by " + author.getAsMention()).queue();
190194
notificationService.withQOTW(thread.getGuild()).sendSubmissionActionNotification(author, new QOTWSubmission(thread), bestAnswer ? SubmissionStatus.ACCEPT_BEST : SubmissionStatus.ACCEPT);
191195
Optional<ThreadChannel> newestPostOptional = config.getSubmissionsForumChannel().getThreadChannels()
192196
.stream().max(Comparator.comparing(ThreadChannel::getTimeCreated));
@@ -212,15 +216,13 @@ public void acceptSubmission(InteractionHook hook, @NotNull ThreadChannel thread
212216
/**
213217
* Declines a submission.
214218
*
215-
* @param hook The {@link net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent} that was fired.
216219
* @param thread The submission's {@link ThreadChannel}.
217220
* @param author The submissions' author.
218221
* @param status The {@link SubmissionStatus}.
219222
*/
220-
public void declineSubmission(InteractionHook hook, @NotNull ThreadChannel thread, User author, SubmissionStatus status) {
223+
public void declineSubmission(@NotNull ThreadChannel thread, User author, SubmissionStatus status) {
221224
thread.getManager().setName(SUBMISSION_DECLINED + thread.getName().substring(1)).queue();
222225
notificationService.withQOTW(thread.getGuild(), author).sendSubmissionDeclinedEmbed(status);
223-
Responses.success(hook, "Submission Declined", "Successfully declined submission by " + author.getAsMention()).queue();
224226
notificationService.withQOTW(thread.getGuild()).sendSubmissionActionNotification(author, new QOTWSubmission(thread), status);
225227
thread.getManager().setLocked(true).setArchived(true).queue();
226228
}

src/main/java/net/javadiscord/javabot/systems/qotw/submissions/subcommands/QOTWReviewSubcommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
8181
submission.retrieveAuthor(author -> {
8282
SubmissionManager manager = new SubmissionManager(qotwConfig, pointsService, questionQueueRepository, notificationService, asyncPool);
8383
if (state.contains("ACCEPT")) {
84-
manager.acceptSubmission(event.getHook(), submissionThread, author, state.equals("ACCEPT_BEST"));
84+
manager.acceptSubmission(submissionThread, author, state.equals("ACCEPT_BEST"));
85+
Responses.success(event.getHook(), "Submission Accepted", "Successfully accepted submission by " + author.getAsMention()).queue();
8586
} else {
8687
// just do a "wrong answer" for now. this command is going to be removed
8788
// in the near future anyway
88-
manager.declineSubmission(event.getHook(), submissionThread, author, SubmissionStatus.DECLINE_WRONG_ANSWER);
89+
manager.declineSubmission(submissionThread, author, SubmissionStatus.DECLINE_WRONG_ANSWER);
90+
Responses.success(event.getHook(), "Submission Declined", "Successfully declined submission by " + author.getAsMention()).queue();
8991
}
9092
if (qotwConfig.getSubmissionChannel().getThreadChannels().size() <= 1) {
9193
Optional<ThreadChannel> newestPostOptional = qotwConfig.getSubmissionsForumChannel().getThreadChannels()

0 commit comments

Comments
 (0)