Skip to content

Commit 30b4489

Browse files
Replaced some more things with NotificationServices and reduced code duplication
1 parent 07f7bc4 commit 30b4489

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

src/main/java/net/javadiscord/javabot/systems/notification/QOTWNotificationService.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.javadiscord.javabot.systems.qotw.dao.QuestionPointsRepository;
1010
import net.javadiscord.javabot.systems.qotw.model.QOTWAccount;
1111

12+
import javax.annotation.Nonnull;
1213
import java.sql.Connection;
1314
import java.sql.SQLException;
1415
import java.time.Instant;
@@ -51,30 +52,49 @@ public void sendAccountIncrementedNotification() {
5152
this.sendDirectMessageNotification(user, this.buildAccountIncrementEmbed(account.getPoints()));
5253
}
5354

54-
private MessageEmbed buildBestAnswerEmbed(long points) {
55+
public void sendSubmissionDeclinedEmbed(@Nonnull String reason) {
56+
this.sendDirectMessageNotification(user, this.buildSubmissionDeclinedEmbed(reason));
57+
}
58+
59+
private EmbedBuilder buildQOTWNotificationEmbed() {
5560
return new EmbedBuilder()
5661
.setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl())
5762
.setTitle("QOTW Notification")
63+
.setTimestamp(Instant.now());
64+
}
65+
66+
private MessageEmbed buildBestAnswerEmbed(long points) {
67+
return this.buildQOTWNotificationEmbed()
5868
.setColor(Bot.config.get(guild).getSlashCommand().getSuccessColor())
5969
.setDescription(String.format(
6070
"""
6171
Your submission was marked as the best answer!
6272
You've been granted **`1 extra QOTW-Point`**! (total: %s)""", points))
63-
.setTimestamp(Instant.now())
6473
.build();
6574
}
6675

6776
private MessageEmbed buildAccountIncrementEmbed(long points) {
68-
return new EmbedBuilder()
69-
.setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl())
70-
.setTitle("QOTW Notification")
77+
return this.buildQOTWNotificationEmbed()
7178
.setColor(Bot.config.get(guild).getSlashCommand().getSuccessColor())
7279
.setDescription(String.format(
7380
"""
7481
Your submission was accepted! %s
7582
You've been granted **`1 QOTW-Point`**! (total: %s)""",
7683
Bot.config.get(guild).getEmote().getSuccessEmote().getAsMention(), points))
77-
.setTimestamp(Instant.now())
7884
.build();
7985
}
86+
87+
private MessageEmbed buildSubmissionDeclinedEmbed(String reasons) {
88+
return this.buildQOTWNotificationEmbed()
89+
.setColor(Bot.config.get(guild).getSlashCommand().getErrorColor())
90+
.setDescription(String.format("""
91+
Hey %s,
92+
Your QOTW-Submission was **declined** for the following reasons:
93+
**`%s`**
94+
95+
However, you can try your luck again next week!""",
96+
user.getAsMention(), reasons))
97+
.build();
98+
}
99+
80100
}

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected void declineSelectSubmission(SelectMenuInteractionEvent event, ThreadC
137137
DbHelper.doDaoAction(QOTWSubmissionRepository::new, dao -> dao.updateStatus(thread.getIdLong(), SubmissionStatus.DECLINED));
138138
thread.getManager().setName(SUBMISSION_DECLINED + thread.getName().substring(1)).queue();
139139
event.getJDA().retrieveUserById(submission.getAuthorId()).queue(user -> {
140-
user.openPrivateChannel().queue(c -> c.sendMessageEmbeds(this.buildSubmissionDeclinedEmbed(user, reasons)).queue());
140+
new QOTWNotificationService(user, event.getGuild()).sendSubmissionDeclinedEmbed(reasons);
141141
Responses.success(event.getHook(), "Submission Declined",
142142
String.format("Successfully declined submission by %s for the following reasons:\n`%s`", user.getAsMention(), reasons)).queue();
143143
}
@@ -174,22 +174,6 @@ private void disableControls(String buttonLabel, Message message) {
174174
message.editMessageComponents(ActionRow.of(Button.secondary("qotw-submission:controls:dummy", buttonLabel).asDisabled())).queue();
175175
}
176176

177-
private MessageEmbed buildSubmissionDeclinedEmbed(User createdBy, String reasons) {
178-
return new EmbedBuilder()
179-
.setAuthor(createdBy.getAsTag(), null, createdBy.getEffectiveAvatarUrl())
180-
.setTitle("QOTW Notification")
181-
.setColor(Bot.config.get(config.getGuild()).getSlashCommand().getErrorColor())
182-
.setDescription(String.format("""
183-
Hey %s,
184-
Your QOTW-Submission was **declined** for the following reasons:
185-
**`%s`**
186-
187-
However, you can try your luck again next week!""",
188-
createdBy.getAsMention(), reasons))
189-
.setTimestamp(Instant.now())
190-
.build();
191-
}
192-
193177
private MessageEmbed buildLogEmbed(ThreadChannel thread, User threadOwner, User reviewedBy, SubmissionStatus status, @Nullable String reason) {
194178
EmbedBuilder builder = new EmbedBuilder()
195179
.setAuthor(reviewedBy.getAsTag(), null, reviewedBy.getEffectiveAvatarUrl())

0 commit comments

Comments
 (0)