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 @@ -64,12 +64,11 @@ public MigrateSubcommand(ExecutorService asyncPool, DataSource dataSource, Syste
}

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

@Override
public void handleAutoComplete(@NotNull CommandAutoCompleteInteractionEvent event, @NotNull AutoCompleteQuery target) {
event.replyChoices(AutoCompleteUtils.filterChoices(event, replyMigrations(event))).queue();
event.replyChoices(AutoCompleteUtils.filterChoices(event, getAvailableMigrations())).queue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void synchronizeNow() {
public void cache(Message message) {
MessageCacheConfig config = botConfig.get(message.getGuild()).getMessageCacheConfig();
if (cache.size() + 1 > config.getMaxCachedMessages()) {
cache.remove(0);
cache.removeFirst();
}
if (messageCount >= config.getMessageSynchronizationInterval()) {
synchronize();
Expand All @@ -131,7 +131,7 @@ public void sendUpdatedMessageToLog(Message updated, CachedMessage before) {
if (config.getMessageCacheLogChannel() == null) return;
if (updated.getContentRaw().trim().equals(before.getMessageContent()) && updated.getAttachments().size() == before.getAttachments().size()) return;
MessageCreateAction action = config.getMessageCacheLogChannel()
.sendMessageEmbeds(buildMessageEditEmbed(updated.getGuild(), updated.getAuthor(), updated.getChannel(), before, updated))
.sendMessageEmbeds(buildMessageEditEmbed(updated.getAuthor(), updated.getChannel(), before, updated))
.addComponents(ActionRow.of(Button.link(updated.getJumpUrl(), "Jump to Message")));
if (before.getMessageContent().length() > MessageEmbed.VALUE_MAX_LENGTH || updated.getContentRaw().length() > MessageEmbed.VALUE_MAX_LENGTH) {
action.addFiles(FileUpload.fromData(buildEditedMessageFile(updated.getAuthor(), before, updated), before.getMessageId() + ".txt"));
Expand All @@ -150,7 +150,7 @@ public void sendDeletedMessageToLog(Guild guild, MessageChannel channel, CachedM
MessageCacheConfig config = botConfig.get(guild).getMessageCacheConfig();
if (config.getMessageCacheLogChannel() == null) return;
guild.getJDA().retrieveUserById(message.getAuthorId()).queue(author -> {
MessageCreateAction action = config.getMessageCacheLogChannel().sendMessageEmbeds(buildMessageDeleteEmbed(guild, author, channel, message));
MessageCreateAction action = config.getMessageCacheLogChannel().sendMessageEmbeds(buildMessageDeleteEmbed(author, channel, message));
if (message.getMessageContent().length() > MessageEmbed.VALUE_MAX_LENGTH) {
action.addFiles(FileUpload.fromData(buildDeletedMessageFile(author, message), message.getMessageId() + ".txt"));
}
Expand Down Expand Up @@ -198,7 +198,7 @@ private EmbedBuilder buildMessageCacheEmbed(MessageChannel channel, User author,
.setFooter("ID: " + before.getMessageId());
}

private MessageEmbed buildMessageEditEmbed(Guild guild, User author, MessageChannel channel, CachedMessage before, Message after) {
private MessageEmbed buildMessageEditEmbed(User author, MessageChannel channel, CachedMessage before, Message after) {
EmbedBuilder eb = buildMessageCacheEmbed(channel, author, before)
.setTitle("Message Edited")
.setColor(Responses.Type.WARN.getColor())
Expand All @@ -225,7 +225,7 @@ private MessageEmbed buildMessageEditEmbed(Guild guild, User author, MessageChan
.build();
}

private MessageEmbed buildMessageDeleteEmbed(Guild guild, User author, MessageChannel channel, CachedMessage message) {
private MessageEmbed buildMessageDeleteEmbed(User author, MessageChannel channel, CachedMessage message) {
EmbedBuilder eb = buildMessageCacheEmbed(channel, author, message)
.setTitle("Message Deleted")
.setColor(Responses.Type.ERROR.getColor())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.discordjug.javabot.systems.configuration;

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

Expand All @@ -12,12 +11,11 @@
public class ConfigCommand extends SlashCommand implements CommandModerationPermissions {
/**
* The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
* @param botConfig The main configuration of the bot
* @param exportConfigSubcommand /config export
* @param getConfigSubcommand /config get
* @param setConfigSubcommand /config set
*/
public ConfigCommand(BotConfig botConfig, ExportConfigSubcommand exportConfigSubcommand, GetConfigSubcommand getConfigSubcommand, SetConfigSubcommand setConfigSubcommand) {
public ConfigCommand(ExportConfigSubcommand exportConfigSubcommand, GetConfigSubcommand getConfigSubcommand, SetConfigSubcommand setConfigSubcommand) {
setModerationSlashCommandData(Commands.slash("config", "Administrative Commands for managing the bot's configuration."));
addSubcommands(exportConfigSubcommand, getConfigSubcommand, setConfigSubcommand);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
try {
handleConfigSubcommand(event, botConfig.get(event.getGuild())).queue();
} catch (UnknownPropertyException e) {
Responses.warning(event, "Unknown Property", "The provided property could not be found.")
Responses.warnin(event, "Unknown Property", "The provided property could not be found.")
.queue();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.discordjug.javabot.systems.help.commands;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private void onCloseRequest(Interaction interaction, IReplyCallback replyCallbac
replyCallback.getUser().getIdLong() == manager.getPostThread().getOwnerIdLong(),
reason);
} else {
Responses.warning(replyCallback, "Could not close this post", "You're not allowed to close this post.").queue();
Responses.warnin(replyCallback, "Could not close this post", "You're not allowed to close this post.").queue();
}
}

Expand All @@ -134,7 +134,7 @@ private boolean isReasonInvalid(String reason) {
}

private void replyInvalidChannel(IReplyCallback replyCallback) {
Responses.warning(replyCallback, "Invalid Channel",
Responses.warnin(replyCallback, "Invalid Channel",
"This command may only be used in either the text-channel-based help system, or in our new forum help system.")
.queue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class HelpAccountRepository {
* Inserts a new {@link HelpAccount}.
*
* @param account The account that should be inserted.
* @throws SQLException If an error occurs.
* @throws DataAccessException If an error occurs.
*/
public void insert(HelpAccount account) throws DataAccessException {

Expand All @@ -44,7 +44,7 @@ public void insert(HelpAccount account) throws DataAccessException {
* Updates a single {@link HelpAccount}.
*
* @param account The account that should be updated.
* @throws SQLException If an error occurs.
* @throws DataAccessException If an error occurs.
*/
public void update(HelpAccount account) throws DataAccessException {
jdbcTemplate.update("UPDATE help_account SET experience = ? WHERE user_id = ?",
Expand All @@ -57,7 +57,7 @@ public void update(HelpAccount account) throws DataAccessException {
*
* @param userId The user's id.
* @return An {@link HelpAccount} object, as an {@link Optional}.
* @throws SQLException If an error occurs.
* @throws DataAccessException If an error occurs.
*/
public Optional<HelpAccount> getByUserId(long userId) throws DataAccessException {
try {
Expand All @@ -73,7 +73,7 @@ public Optional<HelpAccount> getByUserId(long userId) throws DataAccessException
* @param page The page.
* @param size The amount of {@link HelpAccount}s to return.
* @return A {@link List} containing the specified amount of {@link HelpAccount}s.
* @throws SQLException If an error occurs.
* @throws DataAccessException If an error occurs.
*/
public List<HelpAccount> getAccounts(int page, int size) throws DataAccessException {
return jdbcTemplate.query("SELECT * FROM help_account WHERE experience > 0 ORDER BY experience DESC LIMIT ? OFFSET ?", (rs, row)->this.read(rs),
Expand All @@ -84,7 +84,7 @@ public List<HelpAccount> getAccounts(int page, int size) throws DataAccessExcept
* Gets the total amount of {@link HelpAccount}s stored in the database, that have more than 0 experience.
*
* @return The amount, as an {@link Integer}.
* @throws SQLException If an error occurs.
* @throws DataAccessException If an error occurs.
*/
public int getTotalAccounts() throws DataAccessException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class HelpTransactionRepository {
*
* @param transaction The transaction that should be inserted.
* @return The inserted {@link HelpTransaction}.
* @throws SQLException If an error occurs.
* @throws DataAccessException If an error occurs.
*/
public HelpTransaction save(HelpTransaction transaction) throws DataAccessException {
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(jdbcTemplate)
Expand All @@ -56,7 +56,7 @@ public HelpTransaction save(HelpTransaction transaction) throws DataAccessExcept
*
* @param id The transaction's id.
* @return A {@link HelpTransaction} object.
* @throws SQLException If an error occurs.
* @throws DataAccessException If an error occurs.
*/
public Optional<HelpTransaction> getTransaction(long id) throws DataAccessException {
try {
Expand All @@ -72,7 +72,7 @@ public Optional<HelpTransaction> getTransaction(long id) throws DataAccessExcept
* @param userId The user's id.
* @param count The count of transactions that should be retrieved.
* @return A List with all {@link HelpTransaction}s.
* @throws SQLException If an error occurs.
* @throws DataAccessException If an error occurs.
*/
public List<HelpTransaction> getTransactions(long userId, int count) throws DataAccessException {
return jdbcTemplate.query("SELECT * FROM help_transaction WHERE recipient = ? ORDER BY created_at DESC LIMIT ?", (rs, rowNumber) -> this.read(rs), userId, count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ protected ReplyCallbackAction handleModerationCommand(@NotNull SlashCommandInter
boolean archive = event.getOption("archive", true, OptionMapping::getAsBoolean);

ModerationConfig config = botConfig.get(event.getGuild()).getModerationConfig();
Long amount = (amountOption == null) ? 1 : amountOption.getAsLong();
long amount = (amountOption == null) ? 1 : amountOption.getAsLong();
User user = (userOption == null) ? null : userOption.getAsUser();
int maxAmount = config.getPurgeMaxMessageCount();
if (amount == null || amount > maxAmount) {
if (amount < 1 || amount > maxAmount) {
return Responses.warning(event, "Invalid amount. Should be between 1 and " + maxAmount + ", inclusive.");
}
if (amount == 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.discordjug.javabot.systems.staff_commands.suggestions;

import net.discordjug.javabot.data.config.BotConfig;
import net.discordjug.javabot.data.config.GuildConfig;
import net.discordjug.javabot.util.Responses;
import net.discordjug.javabot.util.UserUtils;
import net.dv8tion.jda.api.EmbedBuilder;
Expand Down Expand Up @@ -31,17 +30,17 @@ public AcceptSuggestionSubcommand(BotConfig botConfig) {
}

@Override
protected WebhookMessageCreateAction<Message> handleSuggestionCommand(@NotNull SlashCommandInteractionEvent event, @NotNull Message message, GuildConfig config) {
protected WebhookMessageCreateAction<Message> handleSuggestionCommand(@NotNull SlashCommandInteractionEvent event, @NotNull Message message) {
MessageEmbed embed = message.getEmbeds().get(0);
MessageEmbed declineEmbed = buildSuggestionAcceptEmbed(event.getUser(), embed, config);
MessageEmbed declineEmbed = buildSuggestionAcceptEmbed(event.getUser(), embed);
message.editMessageEmbeds(declineEmbed).queue(
edit -> edit.addReaction(botConfig.getSystems().getEmojiConfig().getSuccessEmote(event.getJDA())).queue(),
error -> Responses.error(event.getHook(), error.getMessage()).queue());
return Responses.success(event.getHook(), "Suggestion Accepted", "Successfully accepted suggestion with id `%s`", message.getId())
.setComponents(getJumpButton(message));
}

private @NotNull MessageEmbed buildSuggestionAcceptEmbed(@NotNull User user, @NotNull MessageEmbed embed, @NotNull GuildConfig config) {
private @NotNull MessageEmbed buildSuggestionAcceptEmbed(@NotNull User user, @NotNull MessageEmbed embed) {
return new EmbedBuilder()
.setColor(Responses.Type.SUCCESS.getColor())
.setAuthor(embed.getAuthor().getName(), embed.getAuthor().getUrl(), embed.getAuthor().getIconUrl())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.discordjug.javabot.systems.staff_commands.suggestions;

import net.discordjug.javabot.data.config.BotConfig;
import net.discordjug.javabot.data.config.GuildConfig;
import net.discordjug.javabot.data.config.SystemsConfig;
import net.discordjug.javabot.util.Responses;
import net.dv8tion.jda.api.EmbedBuilder;
Expand Down Expand Up @@ -30,9 +29,9 @@ public ClearSuggestionSubcommand(BotConfig botConfig) {
}

@Override
protected WebhookMessageCreateAction<Message> handleSuggestionCommand(@NotNull SlashCommandInteractionEvent event, @NotNull Message message, GuildConfig config) {
protected WebhookMessageCreateAction<Message> handleSuggestionCommand(@NotNull SlashCommandInteractionEvent event, @NotNull Message message) {
MessageEmbed embed = message.getEmbeds().get(0);
MessageEmbed clearEmbed = buildSuggestionClearEmbed(embed, config);
MessageEmbed clearEmbed = buildSuggestionClearEmbed(embed);
SystemsConfig.EmojiConfig emojiConfig = botConfig.getSystems().getEmojiConfig();
message.editMessageEmbeds(clearEmbed).queue(
edit -> {
Expand All @@ -44,7 +43,7 @@ protected WebhookMessageCreateAction<Message> handleSuggestionCommand(@NotNull S
.setComponents(getJumpButton(message));
}

private @NotNull MessageEmbed buildSuggestionClearEmbed(@NotNull MessageEmbed embed, @NotNull GuildConfig config) {
private @NotNull MessageEmbed buildSuggestionClearEmbed(@NotNull MessageEmbed embed) {
return new EmbedBuilder()
.setColor(Responses.Type.DEFAULT.getColor())
.setAuthor(embed.getAuthor().getName(), embed.getAuthor().getUrl(), embed.getAuthor().getIconUrl())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.discordjug.javabot.systems.staff_commands.suggestions;

import net.discordjug.javabot.data.config.BotConfig;
import net.discordjug.javabot.data.config.GuildConfig;
import net.discordjug.javabot.util.Responses;
import net.discordjug.javabot.util.UserUtils;
import net.dv8tion.jda.api.EmbedBuilder;
Expand Down Expand Up @@ -32,7 +31,7 @@ public DeclineSuggestionSubcommand(BotConfig botConfig) {
}

@Override
protected WebhookMessageCreateAction<Message> handleSuggestionCommand(@NotNull SlashCommandInteractionEvent event, @NotNull Message message, GuildConfig config) {
protected WebhookMessageCreateAction<Message> handleSuggestionCommand(@NotNull SlashCommandInteractionEvent event, @NotNull Message message) {
String reason = event.getOption("reason", null, OptionMapping::getAsString);
MessageEmbed embed = message.getEmbeds().get(0);
MessageEmbed declineEmbed = buildSuggestionDeclineEmbed(event.getUser(), embed, reason);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.discordjug.javabot.systems.staff_commands.suggestions;

import net.discordjug.javabot.data.config.BotConfig;
import net.discordjug.javabot.data.config.GuildConfig;
import net.discordjug.javabot.util.Responses;
import net.discordjug.javabot.util.UserUtils;
import net.dv8tion.jda.api.EmbedBuilder;
Expand Down Expand Up @@ -32,17 +31,17 @@ public OnHoldSuggestionSubcommand(BotConfig botConfig) {
}

@Override
protected WebhookMessageCreateAction<Message> handleSuggestionCommand(@NotNull SlashCommandInteractionEvent event, @NotNull Message message, GuildConfig config) {
protected WebhookMessageCreateAction<Message> handleSuggestionCommand(@NotNull SlashCommandInteractionEvent event, @NotNull Message message) {
MessageEmbed embed = message.getEmbeds().get(0);
MessageEmbed onHoldEmbed = buildSuggestionAcceptEmbed(event.getUser(), embed, config);
MessageEmbed onHoldEmbed = buildSuggestionAcceptEmbed(event.getUser(), embed);
message.editMessageEmbeds(onHoldEmbed).queue(
edit -> edit.addReaction(botConfig.getSystems().getEmojiConfig().getClockEmoji()).queue(),
error -> Responses.error(event.getHook(), error.getMessage()).queue());
return Responses.success(event.getHook(), "Suggestion On Hold", "Successfully marked suggestion with id `%s` as On Hold", message.getId())
.setComponents(getJumpButton(message));
}

private @NotNull MessageEmbed buildSuggestionAcceptEmbed(@NotNull User user, @NotNull MessageEmbed embed, @NotNull GuildConfig config) {
private @NotNull MessageEmbed buildSuggestionAcceptEmbed(@NotNull User user, @NotNull MessageEmbed embed) {
return new EmbedBuilder()
.setColor(Responses.Type.WARN.getColor())
.setAuthor(embed.getAuthor().getName(), embed.getAuthor().getUrl(), embed.getAuthor().getIconUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
long messageId = messageIdMapping.getAsLong();
event.deferReply(true).queue();
event.getMessageChannel().retrieveMessageById(messageId).queue(
message -> message.clearReactions().queue(s -> handleSuggestionCommand(event, message, config).queue()),
message -> message.clearReactions().queue(s -> handleSuggestionCommand(event, message).queue()),
e -> Responses.error(event.getHook(), "Could not find suggestion message with id " + messageId).queue());

}

protected abstract WebhookMessageCreateAction<Message> handleSuggestionCommand(@Nonnull SlashCommandInteractionEvent event, @Nonnull Message message, GuildConfig config);
protected abstract WebhookMessageCreateAction<Message> handleSuggestionCommand(@Nonnull SlashCommandInteractionEvent event, @Nonnull Message message);

protected ActionRow getJumpButton(@NotNull Message m) {
return ActionRow.of(Button.link(m.getJumpUrl(), "Jump to Message"));
Expand Down
Loading