88import net .dv8tion .jda .api .entities .MessageEmbed ;
99import net .dv8tion .jda .api .entities .User ;
1010import net .dv8tion .jda .api .entities .channel .concrete .ThreadChannel ;
11+ import net .javadiscord .javabot .systems .qotw .model .QOTWSubmission ;
1112import net .javadiscord .javabot .systems .qotw .submissions .SubmissionStatus ;
12- import net .javadiscord .javabot .systems .qotw .submissions .dao .QOTWSubmissionRepository ;
13- import net .javadiscord .javabot .systems .qotw .submissions .model .QOTWSubmission ;
14- import net .javadiscord .javabot .util .ExceptionLogger ;
1513
1614import org .jetbrains .annotations .NotNull ;
17- import org .springframework .dao .DataAccessException ;
1815
19- import javax .annotation .Nullable ;
2016import java .time .Instant ;
21- import java .util .Optional ;
22- import java .util .concurrent .ExecutorService ;
2317
2418/**
2519 * Handles all sorts of guild qotw notifications.
@@ -32,42 +26,29 @@ public class QOTWGuildNotificationService {
3226 */
3327 protected final NotificationService notificationService ;
3428 private final Guild guild ;
35- private final ExecutorService asyncPool ;
36- private final QOTWSubmissionRepository qotwSubmissionRepository ;
3729
3830 /**
3931 * Sends the executed action, performed on a QOTW submission thread, to the {@link Guild}s log channel.
4032 *
4133 * @param reviewedBy The user which reviewed the QOTW submission thread.
42- * @param submissionThread The submission thread itself .
34+ * @param submission The {@link QOTWSubmission} .
4335 * @param status The {@link SubmissionStatus}.
44- * @param reasons The reasons for taking this action.
4536 */
46- public void sendSubmissionActionNotification (User reviewedBy , ThreadChannel submissionThread , SubmissionStatus status , @ Nullable String ... reasons ) {
47- asyncPool .execute (()->{
48- try {
49- Optional <QOTWSubmission > submissionOptional = qotwSubmissionRepository .getSubmissionByThreadId (submissionThread .getIdLong ());
50- submissionOptional .ifPresent (submission -> guild .getJDA ().retrieveUserById (submission .getAuthorId ()).queue (author -> {
51- notificationService .withGuild (guild ).sendToModerationLog (c -> c .sendMessageEmbeds (buildSubmissionActionEmbed (author , submissionThread , reviewedBy , status , reasons )));
52- log .info ("{} {} {}'s QOTW Submission{}" , reviewedBy .getAsTag (), status .name ().toLowerCase (), author .getAsTag (), reasons != null ? " for: " + String .join (", " , reasons ) : "." );
53- }));
54- }catch (DataAccessException e ) {
55- ExceptionLogger .capture (e , QOTWGuildNotificationService .class .getSimpleName ());
56- }
37+ public void sendSubmissionActionNotification (User reviewedBy , @ NotNull QOTWSubmission submission , SubmissionStatus status ) {
38+ submission .retrieveAuthor (author -> {
39+ notificationService .withGuild (guild ).sendToModerationLog (c -> c .sendMessageEmbeds (buildSubmissionActionEmbed (author , submission .getThread (), reviewedBy , status )));
40+ log .info ("{} {} {}'s QOTW Submission" , reviewedBy .getAsTag (), status .getVerb (), author .getAsTag ());
5741 });
5842 }
5943
60- private @ NotNull MessageEmbed buildSubmissionActionEmbed (@ NotNull User author , ThreadChannel thread , @ NotNull User reviewedBy , @ NotNull SubmissionStatus status , String ... reasons ) {
44+ private @ NotNull MessageEmbed buildSubmissionActionEmbed (@ NotNull User author , ThreadChannel thread , @ NotNull User reviewedBy , @ NotNull SubmissionStatus status ) {
6145 EmbedBuilder builder = new EmbedBuilder ()
6246 .setAuthor (reviewedBy .getAsTag (), null , reviewedBy .getEffectiveAvatarUrl ())
63- .setTitle (String .format ("%s %s %s's QOTW Submission" , reviewedBy .getAsTag (), status .name (). toLowerCase (), author .getAsTag ()))
47+ .setTitle (String .format ("%s %s %s's QOTW Submission" , reviewedBy .getAsTag (), status .getVerb (), author .getAsTag ()))
6448 .setTimestamp (Instant .now ());
65- if (thread != null && status != SubmissionStatus . DELETED ) {
49+ if (thread != null ) {
6650 builder .addField ("Thread" , thread .getAsMention (), true );
6751 }
68- if (reasons != null && reasons .length > 0 ) {
69- builder .addField ("Reason(s)" , String .join (", " , reasons ), true );
70- }
7152 return builder .build ();
7253 }
7354}
0 commit comments