1616import net .javadiscord .javabot .systems .notification .NotificationService ;
1717import net .javadiscord .javabot .systems .qotw .dao .QuestionQueueRepository ;
1818import net .javadiscord .javabot .systems .qotw .model .QOTWQuestion ;
19- import net .javadiscord .javabot .util .ExceptionLogger ;
2019import org .jetbrains .annotations .NotNull ;
2120import org .springframework .scheduling .annotation .Scheduled ;
2221import org .springframework .stereotype .Service ;
2322
24- import java .sql .Connection ;
2523import java .sql .SQLException ;
2624import java .time .OffsetDateTime ;
2725import java .util .Collections ;
2826import java .util .Optional ;
2927import java .util .Set ;
3028
31- import javax .sql .DataSource ;
32-
3329/**
3430 * Job which posts a new question to the QOTW channel.
3531 */
@@ -40,7 +36,6 @@ public class QOTWJob {
4036 private final JDA jda ;
4137 private final NotificationService notificationService ;
4238 private final BotConfig botConfig ;
43- private final DataSource dataSource ;
4439 private final QuestionQueueRepository questionQueueRepository ;
4540
4641 /**
@@ -51,7 +46,9 @@ public class QOTWJob {
5146 public void execute () throws SQLException {
5247 for (Guild guild : jda .getGuilds ()) {
5348 GuildConfig config = botConfig .get (guild );
54- if (config .getModerationConfig ().getLogChannel () == null ) continue ;
49+ if (config .getModerationConfig ().getLogChannel () == null ) {
50+ continue ;
51+ }
5552 Optional <QOTWQuestion > nextQuestion = questionQueueRepository .getNextQuestion (guild .getIdLong ());
5653 if (nextQuestion .isEmpty ()) {
5754 notificationService .withGuild (guild ).sendToModerationLog (m -> m .sendMessageFormat ("Warning! %s No available next question for QOTW!" , config .getQotwConfig ().getQOTWReviewRole ().getAsMention ()));
@@ -66,12 +63,13 @@ public void execute() throws SQLException {
6663 question .setQuestionNumber (questionQueueRepository .getNextQuestionNumber ());
6764 }
6865 NewsChannel questionChannel = qotw .getQuestionChannel ();
69- if (questionChannel == null ) continue ;
70- questionChannel .sendMessage (qotw .getQOTWRole ().getAsMention ())
71- .setEmbeds (this .buildQuestionEmbed (question ))
72- .setComponents (ActionRow .of (Button .success ("qotw-submission:submit:" + question .getQuestionNumber (), "Submit your Answer" )))
73- .queue (msg -> questionChannel .crosspostMessageById (msg .getIdLong ()).queue ());
74- questionQueueRepository .markUsed (question );
66+ if (questionChannel != null ) {
67+ questionChannel .sendMessage (qotw .getQOTWRole ().getAsMention ())
68+ .setEmbeds (this .buildQuestionEmbed (question ))
69+ .setComponents (ActionRow .of (Button .success ("qotw-submission:submit:" + question .getQuestionNumber (), "Submit your Answer" )))
70+ .queue (msg -> questionChannel .crosspostMessageById (msg .getIdLong ()).queue ());
71+ questionQueueRepository .markUsed (question );
72+ }
7573 }
7674 }
7775 }
@@ -80,7 +78,7 @@ public void execute() throws SQLException {
8078 OffsetDateTime checkTime = OffsetDateTime .now ().plusDays (6 ).withHour (22 ).withMinute (0 ).withSecond (0 );
8179 return new EmbedBuilder ()
8280 .setTitle ("Question of the Week #" + question .getQuestionNumber ())
83- .setDescription (String .format ("%s\n \ n Click the button below to submit your answer.\ n Your answers will be checked by <t:%d:F>" ,
81+ .setDescription (String .format ("%s%n% nClick the button below to submit your answer.% nYour answer will be checked by <t:%d:F>" ,
8482 question .getText (), checkTime .toEpochSecond ()))
8583 .build ();
8684 }
0 commit comments