Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;

import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
import org.jetbrains.annotations.NotNull;
import org.springframework.dao.DataAccessException;

Expand Down Expand Up @@ -47,8 +47,8 @@ public void sendBestAnswerNotification() {
notificationService.withUser(user).sendDirectMessage(c -> c.sendMessageEmbeds(buildBestAnswerEmbed(account.getPoints())));
}

public void sendAccountIncrementedNotification() {
notificationService.withUser(user).sendDirectMessage(c -> c.sendMessageEmbeds(buildAccountIncrementEmbed(account.getPoints())));
public void sendAccountIncrementedNotification(ForumChannel acceptedAnswerForumChannel) {
notificationService.withUser(user).sendDirectMessage(c -> c.sendMessageEmbeds(buildAccountIncrementEmbed(account.getPoints(), acceptedAnswerForumChannel)));
}

public void sendAccountDecrementedNotification() {
Expand All @@ -59,15 +59,17 @@ public void sendAccountDecrementedNotification() {
* Sends a "your submission was declined"-notification to the {@link QOTWNotificationService#user}.
*
* @param status The {@link SubmissionStatus}. Must NOT be {@link SubmissionStatus#ACCEPT} or {@link SubmissionStatus#ACCEPT_BEST}
* @param acceptedAnswerForumChannel The forum channel containing accepted answers to the QOTW
*/
public void sendSubmissionDeclinedEmbed(SubmissionStatus status) {
public void sendSubmissionDeclinedEmbed(SubmissionStatus status, ForumChannel acceptedAnswerForumChannel) {
String reason = switch (status) {
case DECLINE_WRONG_ANSWER -> "Wrong answer";
case DECLINE_TOO_SHORT -> "Too short";
case DECLINE_EMPTY -> "Empty submission";
default -> throw new IllegalArgumentException("Invalid decline status: " + status);
case DECLINE_PLAGIARISM -> "Plagiarism / AI usage";
case ACCEPT, ACCEPT_BEST -> throw new IllegalArgumentException("Invalid decline status: " + status);
};
notificationService.withUser(user).sendDirectMessage(c -> c.sendMessageEmbeds(buildSubmissionDeclinedEmbed(reason)));
notificationService.withUser(user).sendDirectMessage(c -> c.sendMessageEmbeds(buildSubmissionDeclinedEmbed(reason, acceptedAnswerForumChannel)));
}

private @NotNull EmbedBuilder buildQOTWNotificationEmbed() {
Expand All @@ -87,14 +89,15 @@ public void sendSubmissionDeclinedEmbed(SubmissionStatus status) {
.build();
}

private @NotNull MessageEmbed buildAccountIncrementEmbed(long points) {
private @NotNull MessageEmbed buildAccountIncrementEmbed(long points, ForumChannel acceptedAnswerForumChannel) {
return buildQOTWNotificationEmbed()
.setColor(Responses.Type.SUCCESS.getColor())
.setDescription(String.format(
"""
Your submission was accepted! %s
You can view accepted answers in %s.
You've been granted **`1 QOTW-Point`**! (monthly total: %s)""",
systemsConfig.getEmojiConfig().getSuccessEmote(guild.getJDA()), points))
systemsConfig.getEmojiConfig().getSuccessEmote(guild.getJDA()), acceptedAnswerForumChannel.getJumpUrl(), points))
.build();
}

Expand All @@ -109,14 +112,15 @@ public void sendSubmissionDeclinedEmbed(SubmissionStatus status) {
.build();
}

private @NotNull MessageEmbed buildSubmissionDeclinedEmbed(String reason) {
private @NotNull MessageEmbed buildSubmissionDeclinedEmbed(String reason, ForumChannel acceptedAnswerForumChannel) {
return this.buildQOTWNotificationEmbed()
.setColor(Responses.Type.ERROR.getColor())
.setDescription(String.format("""
Hey %s,
Your QOTW-Submission was **declined** for the following reason: `%s`.
You can view accepted answers in %s.
However, you can try your luck again next week!""",
user.getAsMention(), reason))
user.getAsMention(), reason, acceptedAnswerForumChannel.getJumpUrl()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ private void sendNotifications(SlashCommandInteractionEvent event, Member member
MessageEmbed embed = buildIncrementEmbed(member.getUser(), points);
notificationService.withGuild(event.getGuild()).sendToModerationLog(c -> c.sendMessageEmbeds(embed));
if (!quiet) {
sendUserNotification(notificationService.withQOTW(event.getGuild(), member.getUser()));
sendUserNotification(notificationService.withQOTW(event.getGuild(), member.getUser()), member);

}
event.getHook().sendMessageEmbeds(embed).queue();
}

protected abstract void sendUserNotification(@NotNull QOTWNotificationService notificationService);
protected abstract void sendUserNotification(@NotNull QOTWNotificationService notificationService, Member member);

protected @NotNull MessageEmbed buildIncrementEmbed(@NotNull User user, long points) {
return createIncrementEmbedBuilder(user, points)
Expand All @@ -88,7 +88,7 @@ private void sendNotifications(SlashCommandInteractionEvent event, Member member
* Creates an {@link EmbedBuilder} for the notification embed.
* @param user The user whose account is incremented
* @param points The new total number of points of the user
* @return The created {@link EmbedBuilder} for creating the noticiation embed
* @return The created {@link EmbedBuilder} for creating the notification embed
*/
protected @NotNull EmbedBuilder createIncrementEmbedBuilder(User user, long points) {
return new EmbedBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected int getIncrementCount(Member targetMember, SlashCommandInteractionEven
}

@Override
protected void sendUserNotification(@NotNull QOTWNotificationService notificationService) {
protected void sendUserNotification(@NotNull QOTWNotificationService notificationService, Member member) {
notificationService.sendAccountDecrementedNotification();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.discordjug.javabot.systems.qotw.commands.qotw_points;

import org.jetbrains.annotations.NotNull;

import net.discordjug.javabot.data.config.BotConfig;
import net.discordjug.javabot.systems.notification.NotificationService;
import net.discordjug.javabot.systems.notification.QOTWNotificationService;
import net.discordjug.javabot.systems.qotw.QOTWPointsService;
Expand All @@ -15,9 +15,12 @@
* This Subcommand allows staff-members to increment the QOTW-points of any user.
*/
public class IncrementPointsSubcommand extends ChangePointsSubcommand {

public IncrementPointsSubcommand(QOTWPointsService pointsService, NotificationService notificationService) {

private final BotConfig botConfig;

public IncrementPointsSubcommand(QOTWPointsService pointsService, NotificationService notificationService, BotConfig botConfig) {
super(pointsService, notificationService, "increment", "Adds one point to the user's QOTW-Account");
this.botConfig = botConfig;
}

@Override
Expand All @@ -32,8 +35,8 @@ protected int getIncrementCount(Member targetMember, SlashCommandInteractionEven
}

@Override
protected void sendUserNotification(@NotNull QOTWNotificationService notificationService) {
notificationService.sendAccountIncrementedNotification();
protected void sendUserNotification(@NotNull QOTWNotificationService notificationService, Member member) {
notificationService.sendAccountIncrementedNotification(botConfig.get(member.getGuild()).getQotwConfig().getSubmissionsForumChannel());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ private RestAction<Void> changeForumPin(ThreadChannel toPin) {
.withEmoji(emojiConfig.getFailureEmote(jda)),
SelectOption.of("Decline: Empty Submission", SubmissionStatus.DECLINE_EMPTY.name())
.withDescription("The submission was empty")
.withEmoji(emojiConfig.getFailureEmote(jda)),
SelectOption.of("Decline: Plagiarism/AI content", SubmissionStatus.DECLINE_PLAGIARISM.name())
.withDescription("The submission is plagiarized and/or AI content")
.withEmoji(emojiConfig.getFailureEmote(jda))
).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private boolean canCreateSubmissions(Member member) {
public void acceptSubmission(@NotNull ThreadChannel thread, @NotNull User author, Member reviewedBy, boolean bestAnswer) {
thread.getManager().setName(SUBMISSION_ACCEPTED + thread.getName().substring(1)).queue();
pointsService.increment(author.getIdLong());
notificationService.withQOTW(thread.getGuild(), author).sendAccountIncrementedNotification();
notificationService.withQOTW(thread.getGuild(), author).sendAccountIncrementedNotification(config.getSubmissionsForumChannel());
if (bestAnswer) {
pointsService.increment(author.getIdLong());
notificationService.withQOTW(thread.getGuild(), author).sendBestAnswerNotification();
Expand Down Expand Up @@ -250,7 +250,7 @@ private enum AcceptedAnswerType{
*/
public void declineSubmission(@NotNull ThreadChannel thread, User author, Member reviewedBy, SubmissionStatus status) {
thread.getManager().setName(SUBMISSION_DECLINED + thread.getName().substring(1)).queue();
notificationService.withQOTW(thread.getGuild(), author).sendSubmissionDeclinedEmbed(status);
notificationService.withQOTW(thread.getGuild(), author).sendSubmissionDeclinedEmbed(status, config.getSubmissionsForumChannel());
notificationService.withQOTW(thread.getGuild()).sendSubmissionActionNotification(reviewedBy.getUser(), new QOTWSubmission(thread), status);
thread.getManager().setLocked(true).setArchived(true).queue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public enum SubmissionStatus {
/**
* The submission got declined as it was simply empty.
*/
DECLINE_EMPTY("declined (empty)");
DECLINE_EMPTY("declined (empty)"),
/**
* The submission got declined as it was simply empty.
*/
DECLINE_PLAGIARISM("declined (plagiarism/AI)");

private final String verb;

Expand Down
Loading