Skip to content

Commit ee211ac

Browse files
committed
Merge branch 'main' into user-api
2 parents 6600865 + e63ef35 commit ee211ac

31 files changed

+646
-244
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ For more information on how this works, visit the [DIH4JDA Wiki!](https://github
7070
#### `GET` `guilds/{guild_id}/leaderboard/experience?page=1`
7171
- A paginated endpoint which responds with an ordered list of users, based on their help channel experience.
7272

73-
You can try out the API yourself on `api.javadiscord.net`!
73+
You can try out the API yourself on `api.discordjug.net`!
7474

7575
# Credits
7676

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies {
3131

3232
// DIH4JDA (Command Framework) & JDA
3333
implementation("com.github.DynxstyGIT:DIH4JDA:120a15ad2e")
34-
implementation("net.dv8tion:JDA:5.0.0-beta.12") {
34+
implementation("net.dv8tion:JDA:5.0.0-beta.15") {
3535
exclude(module = "opus-java")
3636
}
3737

src/main/java/net/javadiscord/javabot/api/routes/metrics/model/MetricsData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
public class MetricsData {
1313
private long memberCount;
1414
private long onlineCount;
15-
private String weeklyMessages;
16-
private String activeMembers;
15+
private long weeklyMessages;
16+
private long activeMembers;
1717
}

src/main/java/net/javadiscord/javabot/api/routes/user_profile/UserProfileController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public ResponseEntity<UserProfileData> getUserProfile(
104104
data.setQotwAccount(qotwAccount);
105105
// Help Account
106106
HelpAccount helpAccount = helpExperienceService.getOrCreateAccount(user.getIdLong());
107-
data.setHelpAccount(HelpAccountData.of(helpAccount, guild));
107+
data.setHelpAccount(HelpAccountData.of(botConfig, helpAccount, guild));
108108
// User Warns
109109
LocalDateTime cutoff = LocalDateTime.now().minusDays(botConfig.get(guild).getModerationConfig().getWarnTimeoutDays());
110110
data.setWarns(warnRepository.getActiveWarnsByUserId(user.getIdLong(), cutoff));

src/main/java/net/javadiscord/javabot/api/routes/user_profile/model/HelpAccountData.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import lombok.Data;
44
import net.dv8tion.jda.api.entities.Guild;
55
import net.dv8tion.jda.api.entities.Role;
6+
import net.javadiscord.javabot.data.config.BotConfig;
67
import net.javadiscord.javabot.systems.help.model.HelpAccount;
78
import net.javadiscord.javabot.util.ColorUtils;
89
import net.javadiscord.javabot.util.Pair;
@@ -27,20 +28,21 @@ public class HelpAccountData {
2728
* A simple utility method which creates an instance of this class based on
2829
* the specified {@link HelpAccount}.
2930
*
31+
* @param botConfig configuration of the bot.
3032
* @param account The {@link HelpAccount} to convert.
3133
* @param guild The {@link Guild}.
3234
* @return An instance of the {@link HelpAccountData} class.
3335
*/
34-
public static @NotNull HelpAccountData of(@NotNull HelpAccount account, Guild guild) {
36+
public static @NotNull HelpAccountData of(BotConfig botConfig, @NotNull HelpAccount account, Guild guild) {
3537
HelpAccountData data = new HelpAccountData();
3638
data.setExperienceCurrent(account.getExperience());
37-
Pair<Role, Double> previousRank = account.getPreviousExperienceGoal(guild);
39+
Pair<Role, Double> previousRank = account.getPreviousExperienceGoal(botConfig, guild);
3840
if (previousRank != null && previousRank.first() != null) {
3941
data.setCurrentRank(previousRank.first().getName());
4042
data.setCurrentRankColor(ColorUtils.toString(previousRank.first().getColor()));
4143
data.setExperiencePrevious(previousRank.second());
4244
}
43-
Pair<Role, Double> nextRank = account.getNextExperienceGoal(guild);
45+
Pair<Role, Double> nextRank = account.getNextExperienceGoal(botConfig, guild);
4446
if (nextRank != null && nextRank.first() != null) {
4547
data.setNextRank(nextRank.first().getName());
4648
data.setNextRankColor(ColorUtils.toString(nextRank.first().getColor()));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
@Data
1212
@EqualsAndHashCode(callSuper = true)
1313
public class MetricsConfig extends GuildConfigItem {
14-
private String weeklyMessages = "";
15-
private String activeMembers = "";
14+
private long weeklyMessages = -1;
15+
private long activeMembers = -1;
1616
private long metricsCategoryId = 0;
1717
private String metricsMessageTemplate = "";
1818

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
3636
if (!content.getFirst().isBlank() && !content.getSecond().isBlank()) {
3737
event.getMessage().reply(String.format("```%s\n%s\n```", content.getSecond(), StringUtils.standardSanitizer().compute(content.getFirst())))
3838
.setAllowedMentions(List.of())
39-
.setActionRow(Button.secondary(InteractionUtils.DELETE_ORIGINAL_TEMPLATE, "\uD83D\uDDD1️"), Button.link(matcher.group(), "View on GitHub"))
39+
.setActionRow(InteractionUtils.createDeleteButton(event.getAuthor().getIdLong()), Button.link(matcher.group(), "View on GitHub"))
4040
.queue();
4141
}
4242
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
99
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent;
1010
import net.dv8tion.jda.api.hooks.ListenerAdapter;
11-
import net.dv8tion.jda.api.interactions.components.buttons.Button;
1211
import net.javadiscord.javabot.data.config.BotConfig;
1312
import net.javadiscord.javabot.util.InteractionUtils;
1413

@@ -17,9 +16,9 @@
1716
*/
1817
@RequiredArgsConstructor
1918
public class JobChannelCloseOldPostsListener extends ListenerAdapter {
20-
19+
2120
private final BotConfig botConfig;
22-
21+
2322
@Override
2423
public void onChannelCreate(ChannelCreateEvent event) {
2524
if (event.getChannel().getType() != ChannelType.GUILD_PUBLIC_THREAD) {
@@ -30,10 +29,10 @@ public void onChannelCreate(ChannelCreateEvent event) {
3029
botConfig.get(event.getGuild()).getModerationConfig().getJobChannelId()) {
3130
return;
3231
}
33-
34-
32+
33+
3534
boolean postClosed = false;
36-
35+
3736
for (ThreadChannel otherPost : post.getParentChannel().getThreadChannels()) {
3837
if (otherPost.getOwnerIdLong() == post.getOwnerIdLong() &&
3938
otherPost.getIdLong() != post.getIdLong() &&
@@ -56,9 +55,7 @@ public void onChannelCreate(ChannelCreateEvent event) {
5655
.setDescription("Since only one open post is allowed per user, older posts have been closed")
5756
.setColor(Color.YELLOW)
5857
.build())
59-
.addActionRow(Button.secondary(
60-
InteractionUtils.DELETE_ORIGINAL_TEMPLATE,
61-
"\uD83D\uDDD1️"))
58+
.addActionRow(InteractionUtils.createDeleteButton(post.getOwnerIdLong()))
6259
.queue();
6360
}
6461
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import net.dv8tion.jda.api.hooks.ListenerAdapter;
1616
import net.dv8tion.jda.api.requests.RestAction;
1717
import net.javadiscord.javabot.util.ExceptionLogger;
18+
import net.javadiscord.javabot.util.InteractionUtils;
1819
import net.javadiscord.javabot.util.WebhookUtil;
1920
import org.jetbrains.annotations.NotNull;
2021

@@ -42,7 +43,12 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
4243
Optional<RestAction<Message>> optional = parseMessageUrl(matcher.group(), event.getJDA());
4344
optional.ifPresent(action -> action.queue(m -> {
4445
WebhookUtil.ensureWebhookExists(webhookChannel,
45-
wh -> WebhookUtil.mirrorMessageToWebhook(wh, m, m.getContentRaw(), messageChannel.getType().isThread() ? messageChannel.getIdLong() : 0, List.of(ActionRow.of(Button.link(m.getJumpUrl(), "Jump to Message"))), null));
46+
wh -> WebhookUtil.mirrorMessageToWebhook(wh, m, m.getContentRaw(),
47+
messageChannel.getType().isThread() ? messageChannel.getIdLong() : 0,
48+
List.of(ActionRow.of(
49+
Button.link(m.getJumpUrl(), "Jump to Message"),
50+
Button.secondary(InteractionUtils.createDeleteInteractionId(m.getAuthor().getIdLong()), "\uD83D\uDDD1️"))),
51+
null));
4652
}, e -> ExceptionLogger.capture(e, getClass().getSimpleName())));
4753
}
4854
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
66
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
77
import net.dv8tion.jda.api.hooks.ListenerAdapter;
8-
import net.dv8tion.jda.api.interactions.components.buttons.Button;
98
import net.javadiscord.javabot.data.config.BotConfig;
109
import net.javadiscord.javabot.data.config.guild.QOTWConfig;
1110
import net.javadiscord.javabot.util.InteractionUtils;
@@ -35,7 +34,7 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
3534
Please keep in mind that messages **over 2000 characters** get split in half due to webhook limitations.
3635
If you want to make sure that your submission is properly formatted, split your message into smaller chunks instead.""",
3736
event.getAuthor().getAsMention())
38-
.setActionRow(Button.secondary(InteractionUtils.DELETE_ORIGINAL_TEMPLATE, "\uD83D\uDDD1️"))
37+
.setActionRow(InteractionUtils.createDeleteButton(event.getAuthor().getIdLong()))
3938
.queue();
4039
}
4140
}

0 commit comments

Comments
 (0)