Skip to content

Commit e4869d1

Browse files
authored
Merge pull request #508 from danthe1st/qotw-better-messages
improve QOTW messages sent to users
2 parents 559694b + 9a61943 commit e4869d1

File tree

7 files changed

+36
-22
lines changed

7 files changed

+36
-22
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import net.dv8tion.jda.api.entities.Guild;
1212
import net.dv8tion.jda.api.entities.MessageEmbed;
1313
import net.dv8tion.jda.api.entities.User;
14-
14+
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
1515
import org.jetbrains.annotations.NotNull;
1616
import org.springframework.dao.DataAccessException;
1717

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

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

5454
public void sendAccountDecrementedNotification() {
@@ -59,15 +59,17 @@ public void sendAccountDecrementedNotification() {
5959
* Sends a "your submission was declined"-notification to the {@link QOTWNotificationService#user}.
6060
*
6161
* @param status The {@link SubmissionStatus}. Must NOT be {@link SubmissionStatus#ACCEPT} or {@link SubmissionStatus#ACCEPT_BEST}
62+
* @param acceptedAnswerForumChannel The forum channel containing accepted answers to the QOTW
6263
*/
63-
public void sendSubmissionDeclinedEmbed(SubmissionStatus status) {
64+
public void sendSubmissionDeclinedEmbed(SubmissionStatus status, ForumChannel acceptedAnswerForumChannel) {
6465
String reason = switch (status) {
6566
case DECLINE_WRONG_ANSWER -> "Wrong answer";
6667
case DECLINE_TOO_SHORT -> "Too short";
6768
case DECLINE_EMPTY -> "Empty submission";
68-
default -> throw new IllegalArgumentException("Invalid decline status: " + status);
69+
case DECLINE_PLAGIARISM -> "Plagiarism / AI usage";
70+
case ACCEPT, ACCEPT_BEST -> throw new IllegalArgumentException("Invalid decline status: " + status);
6971
};
70-
notificationService.withUser(user).sendDirectMessage(c -> c.sendMessageEmbeds(buildSubmissionDeclinedEmbed(reason)));
72+
notificationService.withUser(user).sendDirectMessage(c -> c.sendMessageEmbeds(buildSubmissionDeclinedEmbed(reason, acceptedAnswerForumChannel)));
7173
}
7274

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

90-
private @NotNull MessageEmbed buildAccountIncrementEmbed(long points) {
92+
private @NotNull MessageEmbed buildAccountIncrementEmbed(long points, ForumChannel acceptedAnswerForumChannel) {
9193
return buildQOTWNotificationEmbed()
9294
.setColor(Responses.Type.SUCCESS.getColor())
9395
.setDescription(String.format(
9496
"""
9597
Your submission was accepted! %s
98+
You can view accepted answers in %s.
9699
You've been granted **`1 QOTW-Point`**! (monthly total: %s)""",
97-
systemsConfig.getEmojiConfig().getSuccessEmote(guild.getJDA()), points))
100+
systemsConfig.getEmojiConfig().getSuccessEmote(guild.getJDA()), acceptedAnswerForumChannel.getJumpUrl(), points))
98101
.build();
99102
}
100103

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

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

src/main/java/net/discordjug/javabot/systems/qotw/commands/qotw_points/ChangePointsSubcommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ private void sendNotifications(SlashCommandInteractionEvent event, Member member
7171
MessageEmbed embed = buildIncrementEmbed(member.getUser(), points);
7272
notificationService.withGuild(event.getGuild()).sendToModerationLog(c -> c.sendMessageEmbeds(embed));
7373
if (!quiet) {
74-
sendUserNotification(notificationService.withQOTW(event.getGuild(), member.getUser()));
74+
sendUserNotification(notificationService.withQOTW(event.getGuild(), member.getUser()), member);
7575

7676
}
7777
event.getHook().sendMessageEmbeds(embed).queue();
7878
}
7979

80-
protected abstract void sendUserNotification(@NotNull QOTWNotificationService notificationService);
80+
protected abstract void sendUserNotification(@NotNull QOTWNotificationService notificationService, Member member);
8181

8282
protected @NotNull MessageEmbed buildIncrementEmbed(@NotNull User user, long points) {
8383
return createIncrementEmbedBuilder(user, points)
@@ -88,7 +88,7 @@ private void sendNotifications(SlashCommandInteractionEvent event, Member member
8888
* Creates an {@link EmbedBuilder} for the notification embed.
8989
* @param user The user whose account is incremented
9090
* @param points The new total number of points of the user
91-
* @return The created {@link EmbedBuilder} for creating the noticiation embed
91+
* @return The created {@link EmbedBuilder} for creating the notification embed
9292
*/
9393
protected @NotNull EmbedBuilder createIncrementEmbedBuilder(User user, long points) {
9494
return new EmbedBuilder()

src/main/java/net/discordjug/javabot/systems/qotw/commands/qotw_points/DecrementPointsSubcommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected int getIncrementCount(Member targetMember, SlashCommandInteractionEven
3232
}
3333

3434
@Override
35-
protected void sendUserNotification(@NotNull QOTWNotificationService notificationService) {
35+
protected void sendUserNotification(@NotNull QOTWNotificationService notificationService, Member member) {
3636
notificationService.sendAccountDecrementedNotification();
3737
}
3838
}

src/main/java/net/discordjug/javabot/systems/qotw/commands/qotw_points/IncrementPointsSubcommand.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package net.discordjug.javabot.systems.qotw.commands.qotw_points;
22

33
import org.jetbrains.annotations.NotNull;
4-
4+
import net.discordjug.javabot.data.config.BotConfig;
55
import net.discordjug.javabot.systems.notification.NotificationService;
66
import net.discordjug.javabot.systems.notification.QOTWNotificationService;
77
import net.discordjug.javabot.systems.qotw.QOTWPointsService;
@@ -15,9 +15,12 @@
1515
* This Subcommand allows staff-members to increment the QOTW-points of any user.
1616
*/
1717
public class IncrementPointsSubcommand extends ChangePointsSubcommand {
18-
19-
public IncrementPointsSubcommand(QOTWPointsService pointsService, NotificationService notificationService) {
18+
19+
private final BotConfig botConfig;
20+
21+
public IncrementPointsSubcommand(QOTWPointsService pointsService, NotificationService notificationService, BotConfig botConfig) {
2022
super(pointsService, notificationService, "increment", "Adds one point to the user's QOTW-Account");
23+
this.botConfig = botConfig;
2124
}
2225

2326
@Override
@@ -32,8 +35,8 @@ protected int getIncrementCount(Member targetMember, SlashCommandInteractionEven
3235
}
3336

3437
@Override
35-
protected void sendUserNotification(@NotNull QOTWNotificationService notificationService) {
36-
notificationService.sendAccountIncrementedNotification();
38+
protected void sendUserNotification(@NotNull QOTWNotificationService notificationService, Member member) {
39+
notificationService.sendAccountIncrementedNotification(botConfig.get(member.getGuild()).getQotwConfig().getSubmissionsForumChannel());
3740
}
3841

3942
}

src/main/java/net/discordjug/javabot/systems/qotw/jobs/QOTWCloseSubmissionsJob.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ private RestAction<Void> changeForumPin(ThreadChannel toPin) {
184184
.withEmoji(emojiConfig.getFailureEmote(jda)),
185185
SelectOption.of("Decline: Empty Submission", SubmissionStatus.DECLINE_EMPTY.name())
186186
.withDescription("The submission was empty")
187+
.withEmoji(emojiConfig.getFailureEmote(jda)),
188+
SelectOption.of("Decline: Plagiarism/AI content", SubmissionStatus.DECLINE_PLAGIARISM.name())
189+
.withDescription("The submission is plagiarized and/or AI content")
187190
.withEmoji(emojiConfig.getFailureEmote(jda))
188191
).build();
189192
}

src/main/java/net/discordjug/javabot/systems/qotw/submissions/SubmissionManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private boolean canCreateSubmissions(Member member) {
193193
public void acceptSubmission(@NotNull ThreadChannel thread, @NotNull User author, Member reviewedBy, boolean bestAnswer) {
194194
thread.getManager().setName(SUBMISSION_ACCEPTED + thread.getName().substring(1)).queue();
195195
pointsService.increment(author.getIdLong());
196-
notificationService.withQOTW(thread.getGuild(), author).sendAccountIncrementedNotification();
196+
notificationService.withQOTW(thread.getGuild(), author).sendAccountIncrementedNotification(config.getSubmissionsForumChannel());
197197
if (bestAnswer) {
198198
pointsService.increment(author.getIdLong());
199199
notificationService.withQOTW(thread.getGuild(), author).sendBestAnswerNotification();
@@ -250,7 +250,7 @@ private enum AcceptedAnswerType{
250250
*/
251251
public void declineSubmission(@NotNull ThreadChannel thread, User author, Member reviewedBy, SubmissionStatus status) {
252252
thread.getManager().setName(SUBMISSION_DECLINED + thread.getName().substring(1)).queue();
253-
notificationService.withQOTW(thread.getGuild(), author).sendSubmissionDeclinedEmbed(status);
253+
notificationService.withQOTW(thread.getGuild(), author).sendSubmissionDeclinedEmbed(status, config.getSubmissionsForumChannel());
254254
notificationService.withQOTW(thread.getGuild()).sendSubmissionActionNotification(reviewedBy.getUser(), new QOTWSubmission(thread), status);
255255
thread.getManager().setLocked(true).setArchived(true).queue();
256256
}

src/main/java/net/discordjug/javabot/systems/qotw/submissions/SubmissionStatus.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public enum SubmissionStatus {
2323
/**
2424
* The submission got declined as it was simply empty.
2525
*/
26-
DECLINE_EMPTY("declined (empty)");
26+
DECLINE_EMPTY("declined (empty)"),
27+
/**
28+
* The submission got declined as it was simply empty.
29+
*/
30+
DECLINE_PLAGIARISM("declined (plagiarism/AI)");
2731

2832
private final String verb;
2933

0 commit comments

Comments
 (0)