Skip to content

Commit b038163

Browse files
committed
Merge remote-tracking branch 'javabot/main' into message-mod-rules
2 parents 3af31e0 + 70172b0 commit b038163

29 files changed

+90
-83
lines changed

src/main/java/net/discordjug/javabot/Bot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void onApplicationEvent(ApplicationReadyEvent event) {
101101
*/
102102
public static void main(String[] args) throws Exception {
103103
TimeZone.setDefault(TimeZone.getTimeZone(ZoneOffset.UTC));
104-
MessageRequest.setDefaultMentions(EnumSet.of(Message.MentionType.ROLE, Message.MentionType.CHANNEL, Message.MentionType.USER, Message.MentionType.EMOJI));
104+
MessageRequest.setDefaultMentions(EnumSet.of(Message.MentionType.CHANNEL, Message.MentionType.USER, Message.MentionType.EMOJI));
105105
SpringApplication.run(Bot.class, args);
106106
}
107107

src/main/java/net/discordjug/javabot/RuntimeHintsConfiguration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
6363
// caffeine
6464
hints.reflection().registerTypeIfPresent(getClass().getClassLoader(), "com.github.benmanes.caffeine.cache.SSW", MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
6565

66+
try {
67+
// These classes are necessary on X11 but may not be loaded on Wayland when generating native hints
68+
for(Class<?> cl : getClass().getClassLoader().loadClass("sun.font.FontConfigManager").getDeclaredClasses()) {
69+
hints.jni().registerType(cl, MemberCategory.ACCESS_DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
70+
}
71+
} catch (ClassNotFoundException e) {
72+
throw new RuntimeException(e);
73+
}
74+
6675
for (Class<?> cl : WebhookEmbed.class.getClasses()) {
6776
hints.reflection().registerType(cl, MemberCategory.ACCESS_DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_METHODS);
6877
}

src/main/java/net/discordjug/javabot/data/h2db/commands/MigrateSubcommand.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,11 @@ public MigrateSubcommand(ExecutorService asyncPool, DataSource dataSource, Syste
6464
}
6565

6666
/**
67-
* Replies with all available migrations to run.
67+
* Finds all all available migrations to run.
6868
*
69-
* @param event The {@link CommandAutoCompleteInteractionEvent} that was fired.
7069
* @return A {@link List} with all Option Choices.
7170
*/
72-
public static @NotNull List<Command.Choice> replyMigrations(CommandAutoCompleteInteractionEvent event) {
71+
public static @NotNull List<Command.Choice> getAvailableMigrations() {
7372
List<Command.Choice> choices = new ArrayList<>(25);
7473
try (Stream<Path> s = Files.list(MigrationUtils.getMigrationsDirectory())) {
7574
List<Path> paths = s.filter(path -> path.getFileName().toString().endsWith(".sql")).toList();
@@ -134,6 +133,6 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
134133

135134
@Override
136135
public void handleAutoComplete(@NotNull CommandAutoCompleteInteractionEvent event, @NotNull AutoCompleteQuery target) {
137-
event.replyChoices(AutoCompleteUtils.filterChoices(event, replyMigrations(event))).queue();
136+
event.replyChoices(AutoCompleteUtils.filterChoices(event, getAvailableMigrations())).queue();
138137
}
139138
}

src/main/java/net/discordjug/javabot/data/h2db/message_cache/MessageCache.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void synchronizeNow() {
109109
public void cache(Message message) {
110110
MessageCacheConfig config = botConfig.get(message.getGuild()).getMessageCacheConfig();
111111
if (cache.size() + 1 > config.getMaxCachedMessages()) {
112-
cache.remove(0);
112+
cache.removeFirst();
113113
}
114114
if (messageCount >= config.getMessageSynchronizationInterval()) {
115115
synchronize();
@@ -131,7 +131,7 @@ public void sendUpdatedMessageToLog(Message updated, CachedMessage before) {
131131
if (config.getMessageCacheLogChannel() == null) return;
132132
if (updated.getContentRaw().trim().equals(before.getMessageContent()) && updated.getAttachments().size() == before.getAttachments().size()) return;
133133
MessageCreateAction action = config.getMessageCacheLogChannel()
134-
.sendMessageEmbeds(buildMessageEditEmbed(updated.getGuild(), updated.getAuthor(), updated.getChannel(), before, updated))
134+
.sendMessageEmbeds(buildMessageEditEmbed(updated.getAuthor(), updated.getChannel(), before, updated))
135135
.addComponents(ActionRow.of(Button.link(updated.getJumpUrl(), "Jump to Message")));
136136
if (before.getMessageContent().length() > MessageEmbed.VALUE_MAX_LENGTH || updated.getContentRaw().length() > MessageEmbed.VALUE_MAX_LENGTH) {
137137
action.addFiles(FileUpload.fromData(buildEditedMessageFile(updated.getAuthor(), before, updated), before.getMessageId() + ".txt"));
@@ -150,7 +150,7 @@ public void sendDeletedMessageToLog(Guild guild, MessageChannel channel, CachedM
150150
MessageCacheConfig config = botConfig.get(guild).getMessageCacheConfig();
151151
if (config.getMessageCacheLogChannel() == null) return;
152152
guild.getJDA().retrieveUserById(message.getAuthorId()).queue(author -> {
153-
MessageCreateAction action = config.getMessageCacheLogChannel().sendMessageEmbeds(buildMessageDeleteEmbed(guild, author, channel, message));
153+
MessageCreateAction action = config.getMessageCacheLogChannel().sendMessageEmbeds(buildMessageDeleteEmbed(author, channel, message));
154154
if (message.getMessageContent().length() > MessageEmbed.VALUE_MAX_LENGTH) {
155155
action.addFiles(FileUpload.fromData(buildDeletedMessageFile(author, message), message.getMessageId() + ".txt"));
156156
}
@@ -209,7 +209,7 @@ public EmbedBuilder buildMessageCacheEmbed(MessageChannel channel, User author,
209209
false);
210210
}
211211

212-
private MessageEmbed buildMessageEditEmbed(Guild guild, User author, MessageChannel channel, CachedMessage before, Message after) {
212+
private MessageEmbed buildMessageEditEmbed(User author, MessageChannel channel, CachedMessage before, Message after) {
213213
EmbedBuilder eb = buildMessageCacheEmbed(channel, author, before, "Before")
214214
.setTitle("Message Edited")
215215
.setColor(Responses.Type.WARN.getColor())
@@ -233,7 +233,7 @@ private MessageEmbed buildMessageEditEmbed(Guild guild, User author, MessageChan
233233
.build();
234234
}
235235

236-
private MessageEmbed buildMessageDeleteEmbed(Guild guild, User author, MessageChannel channel, CachedMessage message) {
236+
private MessageEmbed buildMessageDeleteEmbed(User author, MessageChannel channel, CachedMessage message) {
237237
EmbedBuilder eb = buildMessageCacheEmbed(channel, author, message, "Message Content")
238238
.setTitle("Message Deleted")
239239
.setColor(Responses.Type.ERROR.getColor());

src/main/java/net/discordjug/javabot/systems/configuration/ConfigCommand.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package net.discordjug.javabot.systems.configuration;
22

33
import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand;
4-
import net.discordjug.javabot.data.config.BotConfig;
54
import net.discordjug.javabot.systems.moderation.CommandModerationPermissions;
65
import net.dv8tion.jda.api.interactions.commands.build.Commands;
76

@@ -12,12 +11,11 @@
1211
public class ConfigCommand extends SlashCommand implements CommandModerationPermissions {
1312
/**
1413
* The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
15-
* @param botConfig The main configuration of the bot
1614
* @param exportConfigSubcommand /config export
1715
* @param getConfigSubcommand /config get
1816
* @param setConfigSubcommand /config set
1917
*/
20-
public ConfigCommand(BotConfig botConfig, ExportConfigSubcommand exportConfigSubcommand, GetConfigSubcommand getConfigSubcommand, SetConfigSubcommand setConfigSubcommand) {
18+
public ConfigCommand(ExportConfigSubcommand exportConfigSubcommand, GetConfigSubcommand getConfigSubcommand, SetConfigSubcommand setConfigSubcommand) {
2119
setModerationSlashCommandData(Commands.slash("config", "Administrative Commands for managing the bot's configuration."));
2220
addSubcommands(exportConfigSubcommand, getConfigSubcommand, setConfigSubcommand);
2321
}

src/main/java/net/discordjug/javabot/systems/configuration/ConfigSubcommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
5050
try {
5151
handleConfigSubcommand(event, botConfig.get(event.getGuild())).queue();
5252
} catch (UnknownPropertyException e) {
53-
Responses.warning(event, "Unknown Property", "The provided property could not be found.")
53+
Responses.warnin(event, "Unknown Property", "The provided property could not be found.")
5454
.queue();
5555
}
5656
}

src/main/java/net/discordjug/javabot/systems/help/commands/HelpGuidelinesSubcommand.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.discordjug.javabot.systems.help.commands;
22

3-
import net.discordjug.javabot.data.config.BotConfig;
43
import net.discordjug.javabot.util.Responses;
54
import net.discordjug.javabot.util.StringResourceCache;
65
import net.dv8tion.jda.api.EmbedBuilder;
@@ -16,9 +15,8 @@
1615
public class HelpGuidelinesSubcommand extends SlashCommand.Subcommand {
1716
/**
1817
* The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
19-
* @param botConfig The main configuration of the bot
2018
*/
21-
public HelpGuidelinesSubcommand(BotConfig botConfig) {
19+
public HelpGuidelinesSubcommand() {
2220
setCommandData(new SubcommandData("guidelines", "Show the server's help guidelines in a simple format."));
2321
}
2422

src/main/java/net/discordjug/javabot/systems/help/commands/UnreserveCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private void onCloseRequest(Interaction interaction, IReplyCallback replyCallbac
125125
replyCallback.getUser().getIdLong() == manager.getPostThread().getOwnerIdLong(),
126126
reason);
127127
} else {
128-
Responses.warning(replyCallback, "Could not close this post", "You're not allowed to close this post.").queue();
128+
Responses.warnin(replyCallback, "Could not close this post", "You're not allowed to close this post.").queue();
129129
}
130130
}
131131

@@ -134,7 +134,7 @@ private boolean isReasonInvalid(String reason) {
134134
}
135135

136136
private void replyInvalidChannel(IReplyCallback replyCallback) {
137-
Responses.warning(replyCallback, "Invalid Channel",
137+
Responses.warnin(replyCallback, "Invalid Channel",
138138
"This command may only be used in either the text-channel-based help system, or in our new forum help system.")
139139
.queue();
140140
}

src/main/java/net/discordjug/javabot/systems/help/dao/HelpAccountRepository.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class HelpAccountRepository {
3030
* Inserts a new {@link HelpAccount}.
3131
*
3232
* @param account The account that should be inserted.
33-
* @throws SQLException If an error occurs.
33+
* @throws DataAccessException If an error occurs.
3434
*/
3535
public void insert(HelpAccount account) throws DataAccessException {
3636

@@ -44,7 +44,7 @@ public void insert(HelpAccount account) throws DataAccessException {
4444
* Updates a single {@link HelpAccount}.
4545
*
4646
* @param account The account that should be updated.
47-
* @throws SQLException If an error occurs.
47+
* @throws DataAccessException If an error occurs.
4848
*/
4949
public void update(HelpAccount account) throws DataAccessException {
5050
jdbcTemplate.update("UPDATE help_account SET experience = ? WHERE user_id = ?",
@@ -57,7 +57,7 @@ public void update(HelpAccount account) throws DataAccessException {
5757
*
5858
* @param userId The user's id.
5959
* @return An {@link HelpAccount} object, as an {@link Optional}.
60-
* @throws SQLException If an error occurs.
60+
* @throws DataAccessException If an error occurs.
6161
*/
6262
public Optional<HelpAccount> getByUserId(long userId) throws DataAccessException {
6363
try {
@@ -73,7 +73,7 @@ public Optional<HelpAccount> getByUserId(long userId) throws DataAccessException
7373
* @param page The page.
7474
* @param size The amount of {@link HelpAccount}s to return.
7575
* @return A {@link List} containing the specified amount of {@link HelpAccount}s.
76-
* @throws SQLException If an error occurs.
76+
* @throws DataAccessException If an error occurs.
7777
*/
7878
public List<HelpAccount> getAccounts(int page, int size) throws DataAccessException {
7979
return jdbcTemplate.query("SELECT * FROM help_account WHERE experience > 0 ORDER BY experience DESC LIMIT ? OFFSET ?", (rs, row)->this.read(rs),
@@ -84,7 +84,7 @@ public List<HelpAccount> getAccounts(int page, int size) throws DataAccessExcept
8484
* Gets the total amount of {@link HelpAccount}s stored in the database, that have more than 0 experience.
8585
*
8686
* @return The amount, as an {@link Integer}.
87-
* @throws SQLException If an error occurs.
87+
* @throws DataAccessException If an error occurs.
8888
*/
8989
public int getTotalAccounts() throws DataAccessException {
9090
try {

src/main/java/net/discordjug/javabot/systems/help/dao/HelpTransactionRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class HelpTransactionRepository {
3333
*
3434
* @param transaction The transaction that should be inserted.
3535
* @return The inserted {@link HelpTransaction}.
36-
* @throws SQLException If an error occurs.
36+
* @throws DataAccessException If an error occurs.
3737
*/
3838
public HelpTransaction save(HelpTransaction transaction) throws DataAccessException {
3939
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(jdbcTemplate)
@@ -56,7 +56,7 @@ public HelpTransaction save(HelpTransaction transaction) throws DataAccessExcept
5656
*
5757
* @param id The transaction's id.
5858
* @return A {@link HelpTransaction} object.
59-
* @throws SQLException If an error occurs.
59+
* @throws DataAccessException If an error occurs.
6060
*/
6161
public Optional<HelpTransaction> getTransaction(long id) throws DataAccessException {
6262
try {
@@ -72,7 +72,7 @@ public Optional<HelpTransaction> getTransaction(long id) throws DataAccessExcept
7272
* @param userId The user's id.
7373
* @param count The count of transactions that should be retrieved.
7474
* @return A List with all {@link HelpTransaction}s.
75-
* @throws SQLException If an error occurs.
75+
* @throws DataAccessException If an error occurs.
7676
*/
7777
public List<HelpTransaction> getTransactions(long userId, int count) throws DataAccessException {
7878
return jdbcTemplate.query("SELECT * FROM help_transaction WHERE recipient = ? ORDER BY created_at DESC LIMIT ?", (rs, rowNumber) -> this.read(rs), userId, count);

0 commit comments

Comments
 (0)