Skip to content

Commit 529c594

Browse files
Started work on refactoring the way QOTW Submissions work internally to reduce problems and improve code readability (enums 'n' stuff)
1 parent 08aa4aa commit 529c594

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import net.javadiscord.javabot.systems.qotw.submissions.model.QOTWSubmission;
1919
import net.javadiscord.javabot.util.GuildUtils;
2020

21+
import javax.annotation.Nullable;
2122
import java.sql.Connection;
2223
import java.sql.SQLException;
2324
import java.time.Instant;
@@ -168,12 +169,20 @@ protected void declineSelectSubmission(SelectMenuInteractionEvent event, ThreadC
168169
protected void deleteSubmission(ButtonInteractionEvent event, ThreadChannel thread) {
169170
thread.delete().queueAfter(10, TimeUnit.SECONDS);
170171
log.info("{} deleted submission thread {}", event.getUser().getAsTag(), thread.getName());
171-
GuildUtils.getLogChannel(event.getGuild()).sendMessageFormat("%s deleted submission thread `%s`", event.getUser().getAsTag(), thread.getName()).queue();
172+
this.sendLogMessage(event.getGuild(), thread, event.getUser(), SubmissionStatus.DELETED, null);
172173
this.disableControls(String.format("Deleted by %s", event.getUser().getAsTag()), event.getMessage());
173174
DbHelper.doDaoAction(QOTWSubmissionRepository::new, dao -> dao.removeSubmission(thread.getIdLong()));
174175
event.getHook().sendMessage("This Submission will be deleted in 10 seconds.").setEphemeral(true).queue();
175176
}
176177

178+
private void sendLogMessage(Guild guild, ThreadChannel thread, User reviewedBy, SubmissionStatus status, @Nullable String reason) {
179+
DbHelper.doDaoAction(QOTWSubmissionRepository::new, dao -> {
180+
Optional<QOTWSubmission> submissionOptional = dao.getSubmissionByThreadId(thread.getIdLong());
181+
submissionOptional.ifPresent(submission -> guild.getJDA().retrieveUserById(submission.getAuthorId()).queue(author ->
182+
GuildUtils.getLogChannel(guild).sendMessageEmbeds(this.buildLogEmbed(thread, author, reviewedBy, status, reason)).queue()));
183+
});
184+
}
185+
177186
protected void declineButtonSubmission(ButtonInteractionEvent event) {
178187
event.getMessage().editMessageComponents(ActionRow.of(this.buildDeclineMenu())).queue();
179188
}
@@ -223,4 +232,18 @@ private MessageEmbed buildSubmissionControlEmbed() {
223232
.setTimestamp(Instant.now())
224233
.build();
225234
}
235+
236+
private MessageEmbed buildLogEmbed(ThreadChannel thread, User threadOwner, User reviewedBy, SubmissionStatus status, @Nullable String reason) {
237+
EmbedBuilder builder = new EmbedBuilder()
238+
.setAuthor(reviewedBy.getAsTag(), null, reviewedBy.getEffectiveAvatarUrl())
239+
.setTitle(String.format("%s %s %s's QOTW Submission", reviewedBy.getAsTag(), status.name().toLowerCase(), threadOwner.getAsTag()))
240+
.setTimestamp(Instant.now());
241+
if (thread != null && status != SubmissionStatus.DELETED) {
242+
builder.addField("Thread", thread.getAsMention(), true);
243+
}
244+
if (reason != null) {
245+
builder.addField("Reason(s)", reason, true);
246+
}
247+
return builder.build();
248+
}
226249
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.javadiscord.javabot.Bot;
88
import net.javadiscord.javabot.command.Responses;
99
import net.javadiscord.javabot.data.config.guild.QOTWConfig;
10+
import net.javadiscord.javabot.util.GuildUtils;
1011

1112
/**
1213
* Handles all interactions regarding the QOTW Submission System.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package net.javadiscord.javabot.systems.qotw.submissions;
2+
3+
/**
4+
* Enum class that represents the status of QOTW Submissions.
5+
*/
6+
public enum SubmissionStatus {
7+
/**
8+
* Used for submissions that were accepted.
9+
*/
10+
ACCEPTED,
11+
/**
12+
* Used for submissions that were declined.
13+
*/
14+
DECLINED,
15+
/**
16+
* Used for submissions that were deleted.
17+
*/
18+
DELETED,
19+
/**
20+
* Used for submissions that were yet unreviewed.
21+
*/
22+
UNREVIEWED
23+
}

0 commit comments

Comments
 (0)