Skip to content

Commit e7c2b88

Browse files
Merge remote-tracking branch 'origin/main' into dynxsty/post_based_help
2 parents 69977f7 + 5443214 commit e7c2b88

22 files changed

+186
-150
lines changed

src/main/java/net/javadiscord/javabot/data/config/guild/QOTWConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class QOTWConfig extends GuildConfigItem {
2222
private long submissionsForumChannelId;
2323
private long questionRoleId;
2424
private long qotwReviewRoleId;
25+
private long qotwChampionRoleId;
2526
private String submissionForumOngoingReviewTagName = "";
2627

2728
public NewsChannel getQuestionChannel() {
@@ -44,6 +45,10 @@ public Role getQOTWReviewRole() {
4445
return this.getGuild().getRoleById(this.qotwReviewRoleId);
4546
}
4647

48+
public Role getQOTWChampionRole() {
49+
return this.getGuild().getRoleById(this.qotwChampionRoleId);
50+
}
51+
4752
/**
4853
* Gets a {@link ForumTag} based on the specified name.
4954
*

src/main/java/net/javadiscord/javabot/listener/HugListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private char copyCase(String original, int index, char newChar) {
9696
}
9797

9898
private void sendWebhookMessage(Webhook webhook, Message originalMessage, String newMessageContent, long threadId) {
99-
WebhookUtil.mirrorMessageToWebhook(webhook, originalMessage, newMessageContent, threadId)
99+
WebhookUtil.mirrorMessageToWebhook(webhook, originalMessage, newMessageContent, threadId, null, null)
100100
.thenAccept(unused -> originalMessage.delete().queue()).exceptionally(e -> {
101101
log.error("replacing the content 'fuck' with 'hug' in an incoming message failed", e);
102102
return null;

src/main/java/net/javadiscord/javabot/listener/MessageLinkListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.jetbrains.annotations.NotNull;
1616

1717
import java.util.Arrays;
18+
import java.util.List;
1819
import java.util.Optional;
1920
import java.util.regex.Matcher;
2021
import java.util.regex.Pattern;
@@ -34,7 +35,7 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
3435
Optional<RestAction<Message>> optional = parseMessageUrl(matcher.group(), event.getJDA());
3536
optional.ifPresent(action -> action.queue(
3637
m -> WebhookUtil.ensureWebhookExists(event.getChannel().asTextChannel(),
37-
wh -> WebhookUtil.mirrorMessageToWebhook(wh, m, m.getContentRaw(), 0, ActionRow.of(Button.link(m.getJumpUrl(), "Jump to Message")))
38+
wh -> WebhookUtil.mirrorMessageToWebhook(wh, m, m.getContentRaw(), 0, List.of(ActionRow.of(Button.link(m.getJumpUrl(), "Jump to Message"))), null)
3839
), e -> ExceptionLogger.capture(e, getClass().getSimpleName())
3940
));
4041
}

src/main/java/net/javadiscord/javabot/systems/moderation/report/ReportManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private void handleMessageReport(ModalInteractionEvent event, String messageId)
159159
MessageChannel reportChannel = config.getModerationConfig().getReportChannel();
160160
reportChannel.sendMessageEmbeds(embed.build()).queue(m -> createReportThread(m, target.getAuthor().getIdLong(), config.getModerationConfig(), thread->{
161161
WebhookUtil.ensureWebhookExists(thread.getParentChannel().asStandardGuildMessageChannel(), wh->{
162-
WebhookUtil.mirrorMessageToWebhook(wh, target, target.getContentRaw(), thread.getIdLong());
162+
WebhookUtil.mirrorMessageToWebhook(wh, target, target.getContentRaw(), thread.getIdLong(), null, null);
163163
});
164164
}));
165165
embed.setDescription("Successfully reported " + "`" + target.getAuthor().getAsTag() + "`!\nYour report has been send to our Moderators");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void sendSubmissionDeclinedEmbed() {
6565
.setDescription(String.format(
6666
"""
6767
Your submission was marked as the best answer!
68-
You've been granted **`1 extra QOTW-Point`**! (total: %s)""", points))
68+
You've been granted **`1 extra QOTW-Point`**! (monthly total: %s)""", points))
6969
.build();
7070
}
7171

@@ -75,7 +75,7 @@ public void sendSubmissionDeclinedEmbed() {
7575
.setDescription(String.format(
7676
"""
7777
Your submission was accepted! %s
78-
You've been granted **`1 QOTW-Point`**! (total: %s)""",
78+
You've been granted **`1 QOTW-Point`**! (monthly total: %s)""",
7979
systemsConfig.getEmojiConfig().getSuccessEmote(guild.getJDA()), points))
8080
.build();
8181
}

src/main/java/net/javadiscord/javabot/systems/qotw/QOTWPointsService.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.springframework.stereotype.Service;
1313
import org.springframework.transaction.annotation.Transactional;
1414

15+
import java.time.LocalDate;
16+
import java.time.YearMonth;
1517
import java.util.List;
1618
import java.util.Optional;
1719

@@ -33,14 +35,13 @@ public class QOTWPointsService {
3335
@Transactional
3436
public QOTWAccount getOrCreateAccount(long userId) throws DataAccessException {
3537
QOTWAccount account;
36-
Optional<QOTWAccount> optional = pointsRepository.getByUserId(userId);
38+
Optional<QOTWAccount> optional = pointsRepository.getByUserId(userId, getCurrentMonth());
3739
if (optional.isPresent()) {
3840
account = optional.get();
3941
} else {
4042
account = new QOTWAccount();
4143
account.setUserId(userId);
4244
account.setPoints(0);
43-
pointsRepository.insert(account);
4445
}
4546
return account;
4647
}
@@ -53,7 +54,7 @@ public QOTWAccount getOrCreateAccount(long userId) throws DataAccessException {
5354
*/
5455
public int getQOTWRank(long userId) {
5556
try{
56-
List<QOTWAccount> accounts = pointsRepository.sortByPoints();
57+
List<QOTWAccount> accounts = pointsRepository.sortByPoints(getCurrentMonth());
5758
return accounts.stream()
5859
.map(QOTWAccount::getUserId)
5960
.toList()
@@ -88,9 +89,10 @@ public long getPoints(long userId) {
8889
*/
8990
public List<Pair<QOTWAccount, Member>> getTopMembers(int n, Guild guild) {
9091
try {
91-
List<QOTWAccount> accounts = pointsRepository.sortByPoints();
92+
List<QOTWAccount> accounts = pointsRepository.sortByPoints(getCurrentMonth());
9293
return accounts.stream()
9394
.map(s -> new Pair<>(s, guild.getMemberById(s.getUserId())))
95+
.filter(p->p.first().getPoints() > 0)
9496
.filter(p -> p.second() != null)
9597
.limit(n)
9698
.toList();
@@ -109,7 +111,7 @@ public List<Pair<QOTWAccount, Member>> getTopMembers(int n, Guild guild) {
109111
*/
110112
public List<QOTWAccount> getTopAccounts(int amount, int page) {
111113
try {
112-
return pointsRepository.getTopAccounts(page, amount);
114+
return pointsRepository.getTopAccounts(getCurrentMonth(), page, amount);
113115
} catch (DataAccessException e) {
114116
ExceptionLogger.capture(e, getClass().getSimpleName());
115117
return List.of();
@@ -119,21 +121,24 @@ public List<QOTWAccount> getTopAccounts(int amount, int page) {
119121
/**
120122
* Increments a single user's QOTW-Points.
121123
*
122-
* @param userId The discord Id of the user.
124+
* @param userId The ID of the user whose points shall be incremented
123125
* @return The total points after the update.
124126
*/
125127
public long increment(long userId) {
126128
try {
127-
QOTWAccount account = getOrCreateAccount(userId);
128-
account.setPoints(account.getPoints() + 1);
129-
if (pointsRepository.update(account)) {
130-
return account.getPoints();
131-
} else {
132-
return 0;
133-
}
129+
LocalDate date=LocalDate.now();
130+
int points = pointsRepository.getPointsAtDate(userId, date)+1;
131+
pointsRepository.setPointsAtDate(userId, date, points);
132+
LocalDate month = getCurrentMonth();
133+
long newScore = pointsRepository.getByUserId(userId, month).map(QOTWAccount::getPoints).orElse(0L);
134+
return newScore;
134135
} catch (DataAccessException e) {
135136
ExceptionLogger.capture(e, getClass().getSimpleName());
136137
return 0;
137138
}
138139
}
140+
141+
public static LocalDate getCurrentMonth() {
142+
return YearMonth.from(LocalDate.now()).atDay(1);
143+
}
139144
}

src/main/java/net/javadiscord/javabot/systems/qotw/commands/QOTWAdminCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import net.dv8tion.jda.api.interactions.commands.build.Commands;
55
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
66
import net.javadiscord.javabot.systems.qotw.commands.qotw_points.IncrementPointsSubcommand;
7-
import net.javadiscord.javabot.systems.qotw.commands.qotw_points.SetPointsSubcommand;
87
import net.javadiscord.javabot.systems.qotw.commands.questions_queue.AddQuestionSubcommand;
98
import net.javadiscord.javabot.systems.qotw.commands.questions_queue.ListQuestionsSubcommand;
109
import net.javadiscord.javabot.systems.qotw.commands.questions_queue.RemoveQuestionSubcommand;
@@ -23,18 +22,17 @@ public class QOTWAdminCommand extends SlashCommand {
2322
* @param addQuestionSubcommand /qotw-admin questions-queue add
2423
* @param removeQuestionSubcommand /qotw-admin questions-queue remove
2524
* @param incrementPointsSubcommand /qotw-admin account increment
26-
* @param setPointsSubcommand /qotw-admin account set
2725
* @param reviewSubcommand /qotw-admin submissions review
2826
*/
29-
public QOTWAdminCommand(ListQuestionsSubcommand listQuestionsSubcommand, AddQuestionSubcommand addQuestionSubcommand, RemoveQuestionSubcommand removeQuestionSubcommand, IncrementPointsSubcommand incrementPointsSubcommand, SetPointsSubcommand setPointsSubcommand, QOTWReviewSubcommand reviewSubcommand) {
27+
public QOTWAdminCommand(ListQuestionsSubcommand listQuestionsSubcommand, AddQuestionSubcommand addQuestionSubcommand, RemoveQuestionSubcommand removeQuestionSubcommand, IncrementPointsSubcommand incrementPointsSubcommand, QOTWReviewSubcommand reviewSubcommand) {
3028
setCommandData(Commands.slash("qotw-admin", "Administrative tools for managing the Question of the Week.")
3129
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
3230
.setGuildOnly(true)
3331
);
3432
addSubcommands(reviewSubcommand);
3533
addSubcommandGroups(
3634
SubcommandGroup.of(new SubcommandGroupData("questions-queue", "Commands for interacting with the set of QOTW questions that are in queue."), listQuestionsSubcommand, addQuestionSubcommand, removeQuestionSubcommand),
37-
SubcommandGroup.of(new SubcommandGroupData("account", "Commands for interaction with Users Question of the Week points."), incrementPointsSubcommand, setPointsSubcommand),
35+
SubcommandGroup.of(new SubcommandGroupData("account", "Commands for interaction with Users Question of the Week points."), incrementPointsSubcommand),
3836
SubcommandGroup.of(new SubcommandGroupData("submissions", "Commands for managing QOTW Submissions."), reviewSubcommand)
3937
);
4038
}

src/main/java/net/javadiscord/javabot/systems/qotw/commands/qotw_points/SetPointsSubcommand.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)