1616import net .javadiscord .javabot .systems .qotw .dao .QuestionPointsRepository ;
1717import net .javadiscord .javabot .systems .qotw .submissions .dao .QOTWSubmissionRepository ;
1818import net .javadiscord .javabot .systems .qotw .submissions .model .QOTWSubmission ;
19- import net .javadiscord .javabot .systems .notification .GuildNotificationService ;
2019
21- import javax .annotation .Nullable ;
2220import java .sql .Connection ;
2321import java .sql .SQLException ;
2422import java .time .Instant ;
@@ -123,7 +121,7 @@ protected void acceptSubmission(ButtonInteractionEvent event, ThreadChannel thre
123121 }
124122 );
125123 this .disableControls (String .format ("Accepted by %s" , event .getUser ().getAsTag ()), event .getMessage ());
126- this . sendLogMessage ( thread , event .getUser (), SubmissionStatus .ACCEPTED , null );
124+ new QOTWNotificationService ( guild ). sendSubmissionActionNotification ( event .getUser (), thread , SubmissionStatus .ACCEPTED );
127125 }
128126
129127 /**
@@ -133,17 +131,16 @@ protected void acceptSubmission(ButtonInteractionEvent event, ThreadChannel thre
133131 * @param thread The submission's {@link ThreadChannel}.
134132 */
135133 protected void declineSelectSubmission (SelectMenuInteractionEvent event , ThreadChannel thread ) {
136- String reasons = String .join (", " , event .getValues ());
137134 DbHelper .doDaoAction (QOTWSubmissionRepository ::new , dao -> dao .updateStatus (thread .getIdLong (), SubmissionStatus .DECLINED ));
138135 thread .getManager ().setName (SUBMISSION_DECLINED + thread .getName ().substring (1 )).queue ();
139136 event .getJDA ().retrieveUserById (submission .getAuthorId ()).queue (user -> {
140- new QOTWNotificationService (user , event .getGuild ()).sendSubmissionDeclinedEmbed (reasons );
137+ new QOTWNotificationService (user , event .getGuild ()).sendSubmissionDeclinedEmbed (String . join ( ", " , event . getValues ()) );
141138 Responses .success (event .getHook (), "Submission Declined" ,
142- String .format ("Successfully declined submission by %s for the following reasons:\n `%s`" , user .getAsMention (), reasons )).queue ();
139+ String .format ("Successfully declined submission by %s for the following reasons:\n `%s`" , user .getAsMention (), String . join ( ", " , event . getValues ()) )).queue ();
143140 }
144141 );
145142 this .disableControls (String .format ("Declined by %s" , event .getUser ().getAsTag ()), event .getMessage ());
146- this . sendLogMessage ( thread , event .getUser (), SubmissionStatus .DECLINED , reasons );
143+ new QOTWNotificationService ( guild ). sendSubmissionActionNotification ( event .getUser (), thread , SubmissionStatus .DECLINED , event . getValues (). toArray ( new String [ 0 ]) );
147144 }
148145
149146 /**
@@ -156,35 +153,11 @@ protected void deleteSubmission(ButtonInteractionEvent event, ThreadChannel thre
156153 DbHelper .doDaoAction (QOTWSubmissionRepository ::new , dao -> dao .deleteSubmission (thread .getIdLong ()));
157154 event .getHook ().sendMessage ("This Submission will be deleted in 10 seconds." ).setEphemeral (true ).queue ();
158155 this .disableControls (String .format ("Deleted by %s" , event .getUser ().getAsTag ()), event .getMessage ());
159- this . sendLogMessage ( thread , event .getUser (), SubmissionStatus .DELETED , null );
156+ new QOTWNotificationService ( guild ). sendSubmissionActionNotification ( event .getUser (), thread , SubmissionStatus .DELETED );
160157 thread .delete ().queueAfter (10 , TimeUnit .SECONDS );
161158 }
162159
163- private void sendLogMessage (ThreadChannel thread , User reviewedBy , SubmissionStatus status , @ Nullable String reason ) {
164- DbHelper .doDaoAction (QOTWSubmissionRepository ::new , dao -> {
165- Optional <QOTWSubmission > submissionOptional = dao .getSubmissionByThreadId (thread .getIdLong ());
166- submissionOptional .ifPresent (submission -> guild .getJDA ().retrieveUserById (submission .getAuthorId ()).queue (author -> {
167- new GuildNotificationService (guild ).sendLogChannelNotification (this .buildLogEmbed (thread , author , reviewedBy , status , reason ));
168- log .info ("{} {} {}'s QOTW Submission{}" , reviewedBy .getAsTag (), status .name ().toLowerCase (), author .getAsTag (), reason != null ? " for: " + reason : "." );
169- }));
170- });
171- }
172-
173160 private void disableControls (String buttonLabel , Message message ) {
174161 message .editMessageComponents (ActionRow .of (Button .secondary ("qotw-submission:controls:dummy" , buttonLabel ).asDisabled ())).queue ();
175162 }
176-
177- private MessageEmbed buildLogEmbed (ThreadChannel thread , User threadOwner , User reviewedBy , SubmissionStatus status , @ Nullable String reason ) {
178- EmbedBuilder builder = new EmbedBuilder ()
179- .setAuthor (reviewedBy .getAsTag (), null , reviewedBy .getEffectiveAvatarUrl ())
180- .setTitle (String .format ("%s %s %s's QOTW Submission" , reviewedBy .getAsTag (), status .name ().toLowerCase (), threadOwner .getAsTag ()))
181- .setTimestamp (Instant .now ());
182- if (thread != null && status != SubmissionStatus .DELETED ) {
183- builder .addField ("Thread" , thread .getAsMention (), true );
184- }
185- if (reason != null ) {
186- builder .addField ("Reason(s)" , reason , true );
187- }
188- return builder .build ();
189- }
190163}
0 commit comments