1414import net .javadiscord .javabot .Bot ;
1515import net .javadiscord .javabot .command .Responses ;
1616import net .javadiscord .javabot .data .config .guild .QOTWConfig ;
17+ import net .javadiscord .javabot .data .h2db .DbHelper ;
18+ import net .javadiscord .javabot .systems .qotw .dao .QuestionQueueRepository ;
19+ import net .javadiscord .javabot .systems .qotw .model .QOTWQuestion ;
1720import net .javadiscord .javabot .systems .qotw .submissions .dao .QOTWSubmissionRepository ;
1821import net .javadiscord .javabot .systems .qotw .submissions .model .QOTWSubmission ;
1922
@@ -47,6 +50,7 @@ public WebhookMessageAction<?> handleSubmission(ButtonInteractionEvent event, in
4750 config .getSubmissionChannel ().createThreadChannel (
4851 String .format (THREAD_NAME , questionNumber , member .getEffectiveName ()), true ).queue (
4952 thread -> {
53+ thread .getManager ().setInvitable (false ).setAutoArchiveDuration (ThreadChannel .AutoArchiveDuration .TIME_1_WEEK ).queue ();
5054 try (var con = Bot .dataSource .getConnection ()) {
5155 var repo = new QOTWSubmissionRepository (con );
5256 QOTWSubmission submission = new QOTWSubmission ();
@@ -55,12 +59,18 @@ public WebhookMessageAction<?> handleSubmission(ButtonInteractionEvent event, in
5559 submission .setGuildId (thread .getGuild ().getIdLong ());
5660 submission .setAuthorId (member .getIdLong ());
5761 repo .insert (submission );
58-
59- thread .getManager ().setInvitable (false ).setAutoArchiveDuration (ThreadChannel .AutoArchiveDuration .TIME_1_WEEK ).queue ();
60- thread .sendMessage (String .format ("%s %s" , config .getQOTWReviewRole (), member .getAsMention ()))
61- .setEmbeds (buildSubmissionThreadEmbed (event .getUser (), questionNumber , config ))
62- .setActionRows (ActionRow .of (Button .danger ("qotw-submission:delete" , "Delete Submission" )))
63- .queue ();
62+ DbHelper .doDaoAction (QuestionQueueRepository ::new , dao -> {
63+ var questionOptional = dao .findByQuestionNumber (questionNumber );
64+ if (questionOptional .isPresent ()) {
65+ thread .sendMessage (String .format ("%s %s" , config .getQOTWReviewRole (), member .getAsMention ()))
66+ .setEmbeds (buildSubmissionThreadEmbed (event .getUser (), questionOptional .get (), config ))
67+ .setActionRows (ActionRow .of (Button .danger ("qotw-submission:delete" , "Delete Submission" )))
68+ .queue ();
69+ } else {
70+ thread .sendMessage ("Could not retrieve current QOTW Question. Please contact an Administrator if you think that this is a mistake." )
71+ .queue ();
72+ }
73+ });
6474 } catch (SQLException e ) {
6575 e .printStackTrace ();
6676 }
@@ -118,15 +128,24 @@ public boolean hasActiveSubmissionThreads(long authorId) {
118128 }
119129 }
120130
121- private MessageEmbed buildSubmissionThreadEmbed (User createdBy , long questionNumber , QOTWConfig config ) {
131+ private MessageEmbed buildSubmissionThreadEmbed (User createdBy , QOTWQuestion question , QOTWConfig config ) {
122132 return new EmbedBuilder ()
123133 .setColor (Bot .config .get (config .getGuild ()).getSlashCommand ().getDefaultColor ())
124134 .setAuthor (createdBy .getAsTag (), null , createdBy .getEffectiveAvatarUrl ())
125- .setTitle (String .format ("Question of the Week #%s" , questionNumber ))
126- .setDescription (String .format ("Hey, %s! Please submit your answer into this thread." +
127- "\n You can even send multiple messages, if you want to. This whole thread counts as your submission." +
128- "\n The %s will review your submission once a new question appears." ,
129- createdBy .getAsMention (), config .getQOTWReviewRole ().getAsMention ()))
135+ .setTitle (String .format ("Question of the Week #%s" , question .getQuestionNumber ()))
136+ .setDescription (String .format ("""
137+ %s
138+
139+ Hey, %s! Please submit your answer into this private thread.
140+ The %s will review your submission once a new question appears.""" ,
141+ question .getText (), createdBy .getAsMention (), config .getQOTWReviewRole ().getAsMention ()))
142+ .addField ("Note" ,
143+ """
144+ To maximize your chances of getting this weeks QOTW Point make sure to:
145+ — Provide a **Code example** (if possible)
146+ — Try to answer the question as detailed as possible.
147+
148+ Staff usually wont reply in here.""" , false )
130149 .setTimestamp (Instant .now ())
131150 .build ();
132151 }
0 commit comments