From 8e4a6841ccdbe9b977e117f7a35fb639979e024c Mon Sep 17 00:00:00 2001 From: Renovate Date: Thu, 24 Apr 2025 06:37:58 +0000 Subject: [PATCH] fix(deps): update dependency net.dv8tion:jda to v5.4.0 --- .gitlab-ci.yml | 2 + checkstyle.xml | 37 ++++++++++ pom.xml | 38 +++++++++- .../bobert/netneutrality/NetNeutrality.java | 8 +-- .../command/admin/BlacklistCommand.java | 14 ++-- .../command/admin/ReactionCommand.java | 72 +++++++++---------- .../command/basic/HelpCommand.java | 7 +- .../command/basic/PingCommand.java | 2 +- .../command/bot/ConfigureCommand.java | 22 +++--- .../command/crypto/CryptoPriceCommand.java | 16 ++--- .../command/git/ReportIssueCommand.java | 2 +- .../command/music/BitconnectCommand.java | 2 +- .../command/music/ClearQueueCommand.java | 2 +- .../music/CurrentlyPlayingCommand.java | 2 +- .../command/music/JoinCommand.java | 2 +- .../command/music/LeaveCommand.java | 2 +- .../command/music/PlayCommand.java | 4 +- .../command/music/QueueCommand.java | 24 +++---- .../command/music/ResumeCommand.java | 2 +- .../command/music/ShuffleCommand.java | 2 +- .../command/music/SkipCommand.java | 6 +- .../command/music/StopCommand.java | 2 +- .../command/music/ViewQueueCommand.java | 2 +- .../command/music/VolumeCommand.java | 6 +- .../command/music/VoteSkipCommand.java | 2 +- .../command/react/CreateEmojiReaction.java | 2 +- .../command/react/ModifyEmojiReaction.java | 2 +- .../command/MessageCommandContext.java | 15 ++-- .../context/tasks/EmojiTaskContext.java | 3 - .../bobert/netneutrality/core/LogHandler.java | 22 +++--- .../core/command/CommandContainer.java | 15 ++-- .../core/command/CommandOptionsBuilder.java | 6 +- .../core/command/CommandProcessor.java | 7 +- .../core/command/impl/MusicCommand.java | 3 +- .../core/command/options/CommandOption.java | 68 ++++++------------ .../command/options/MessageCommandOption.java | 14 ++-- .../command/options/SlashCommandOption.java | 6 +- .../core/context/AbstractContext.java | 1 - .../core/context/CommandContext.java | 20 ++++-- .../netneutrality/core/context/Context.java | 10 ++- .../core/db/DatabaseMigration.java | 6 +- .../core/tasks/AbstractTask.java | 8 ++- .../bobert/netneutrality/core/tasks/Task.java | 10 ++- .../netneutrality/core/tasks/TaskManager.java | 24 ++++--- .../core/tasks/impl/ModalTask.java | 8 +-- .../core/tasks/impl/StepTask.java | 4 +- .../core/thread/ThreadManager.java | 22 +++--- .../bobert/netneutrality/db/Repository.java | 2 +- .../netneutrality/db/entities/OBlacklist.java | 10 ++- .../netneutrality/db/entities/OGuild.java | 12 ++-- .../db/entities/OGuildSetting.java | 15 +++- .../db/entities/OLogMessage.java | 11 ++- .../netneutrality/db/entities/OLogging.java | 9 ++- .../netneutrality/db/entities/OLoggingId.java | 10 ++- .../netneutrality/db/entities/OTask.java | 9 ++- .../netneutrality/db/entities/OWebUser.java | 6 +- .../db/repository/BlacklistRepository.java | 2 +- .../db/repository/GuildRepository.java | 2 +- .../db/repository/GuildSettingRepository.java | 2 +- .../db/repository/MessageRepository.java | 2 +- .../db/repository/TaskRepository.java | 2 +- .../db/service/BlacklistService.java | 6 +- .../netneutrality/hooks/EventsHandler.java | 8 ++- .../bobert/netneutrality/http/WebModule.java | 67 +++++++++-------- .../netneutrality/music/MusicManager.java | 4 +- .../netneutrality/music/QueueManager.java | 5 +- .../netneutrality/music/SourceFinder.java | 18 +++-- .../bobert/netneutrality/music/TrackInfo.java | 16 +++-- .../music/TrackLoadingHandler.java | 7 +- .../music/source/UdioAudioSourceManager.java | 12 +--- .../music/source/UdioAudioTrack.java | 2 +- .../tasks/generic/AcceptButton.java | 1 + .../tasks/git/ReportIssueTask.java | 20 +++--- .../netneutrality/tasks/help/BotInfo.java | 2 +- .../netneutrality/tasks/help/ReportBug.java | 2 +- .../tasks/music/LoadPlaylistTask.java | 8 +-- .../tasks/reaction/EmojiRoleFirstStep.java | 4 +- .../tasks/reaction/EmojiRoleSecondStep.java | 12 ++-- .../thread/CleanupTaskThread.java | 10 +-- .../utils/ChannelMessagePurger.java | 9 +-- .../netneutrality/utils/ContextUtils.java | 4 +- .../bobert/netneutrality/utils/JpaUtils.java | 16 ++--- .../netneutrality/utils/MessageFunction.java | 29 ++++---- .../bobert/netneutrality/utils/Settings.java | 6 +- .../netneutrality/utils/UserFunction.java | 31 ++++---- 85 files changed, 564 insertions(+), 385 deletions(-) create mode 100644 checkstyle.xml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dc1470d..b347068 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -48,6 +48,8 @@ test: reports: junit: - "**/target/*-reports/TEST-*.xml" + codequality: + - "target/gl-code-quality-report.json" rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == "main"' diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 0000000..53d9aeb --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 1316731..237ea4f 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,42 @@ + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.6.0 + + + checkstyle + test + + check + + + + + checkstyle.xml + true + false + target/checkstyle-result.xml + xml + + + + + de.chkal.maven + gitlab-code-quality-plugin + 1.1.0 + + + test + + generate + + + + @@ -100,7 +136,7 @@ net.dv8tion JDA - 5.3.2 + 5.4.0 dev.arbjerg diff --git a/src/main/java/me/bobert/netneutrality/NetNeutrality.java b/src/main/java/me/bobert/netneutrality/NetNeutrality.java index 980fbdb..67b7ebe 100644 --- a/src/main/java/me/bobert/netneutrality/NetNeutrality.java +++ b/src/main/java/me/bobert/netneutrality/NetNeutrality.java @@ -94,10 +94,10 @@ public class NetNeutrality { try { jda = JDABuilder - .createDefault(token) - .enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.MESSAGE_CONTENT) - .setActivity(Activity.watching("me load...")) - .build(); + .createDefault(token) + .enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.MESSAGE_CONTENT) + .setActivity(Activity.watching("me load...")) + .build(); jda.awaitReady(); } catch (InvalidTokenException | IllegalArgumentException | InterruptedException e) { LogHandler.log(e); diff --git a/src/main/java/me/bobert/netneutrality/command/admin/BlacklistCommand.java b/src/main/java/me/bobert/netneutrality/command/admin/BlacklistCommand.java index 205ddac..39ed23b 100644 --- a/src/main/java/me/bobert/netneutrality/command/admin/BlacklistCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/admin/BlacklistCommand.java @@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.admin; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.AdminCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; -import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.AdminCommand; +import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.db.entities.OBlacklist; import me.bobert.netneutrality.db.service.BlacklistService; @@ -43,11 +43,11 @@ public class BlacklistCommand extends AdminCommand { @Override public void registerCommandOptions(CommandOptionsBuilder builder) { builder.addSubcommands( - new SubcommandData("get", "Get all blacklisted words for this guild"), - new SubcommandData("add", "Add a word to the blacklist") - .addOption(OptionType.STRING, "word", "Word to add", true), - new SubcommandData("remove", "Remove a word from the blacklist") - .addOption(OptionType.STRING, "word", "Word to remove", true) + new SubcommandData("get", "Get all blacklisted words for this guild"), + new SubcommandData("add", "Add a word to the blacklist") + .addOption(OptionType.STRING, "word", "Word to add", true), + new SubcommandData("remove", "Remove a word from the blacklist") + .addOption(OptionType.STRING, "word", "Word to remove", true) ); } diff --git a/src/main/java/me/bobert/netneutrality/command/admin/ReactionCommand.java b/src/main/java/me/bobert/netneutrality/command/admin/ReactionCommand.java index 0eabce6..3f36c70 100644 --- a/src/main/java/me/bobert/netneutrality/command/admin/ReactionCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/admin/ReactionCommand.java @@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.admin; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.AdminCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; -import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.AdminCommand; +import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.core.tasks.TaskManager; import me.bobert.netneutrality.tasks.emoji.EmojiReactionRoleTask; @@ -49,30 +49,30 @@ public class ReactionCommand extends AdminCommand { @Override public void registerCommandOptions(CommandOptionsBuilder builder) { builder.addSubcommandGroups( - new SubcommandGroupData("emoji", "Give roles to users using emojis").addSubcommands( - new SubcommandData("list", "Lists all registered tasks for this guild"), - new SubcommandData("setup", "Add a role to a message").addOptions( - new OptionData(OptionType.STRING, "messageid", "The ID of the message", true) - .setRequiredLength(19, 19), - new OptionData(OptionType.STRING, "emoji", "Emoji associated with the role", true), - new OptionData(OptionType.ROLE, "role", "Role to add to the emoji", true) - ), - new SubcommandData("add", "Add a role to an existing message").addOptions( - new OptionData(OptionType.STRING, "messageid", "The ID of the message", true) - .setRequiredLength(19, 19), - new OptionData(OptionType.STRING, "emoji", "Emoji associated with the role", true), - new OptionData(OptionType.ROLE, "role", "Role to add to the emoji", true) - ), - new SubcommandData("remove", "Remove a role from a message").addOptions( - new OptionData(OptionType.STRING, "messageid", "The ID of the message", true) - .setRequiredLength(19, 19), - new OptionData(OptionType.STRING, "emoji", "Emoji to remove from the message", true) - ), - new SubcommandData("delete", "Remove all roles from a message").addOptions( - new OptionData(OptionType.STRING, "messageid", "The ID of the message", true) - .setRequiredLength(19, 19) - ) + new SubcommandGroupData("emoji", "Give roles to users using emojis").addSubcommands( + new SubcommandData("list", "Lists all registered tasks for this guild"), + new SubcommandData("setup", "Add a role to a message").addOptions( + new OptionData(OptionType.STRING, "messageid", "The ID of the message", true) + .setRequiredLength(19, 19), + new OptionData(OptionType.STRING, "emoji", "Emoji associated with the role", true), + new OptionData(OptionType.ROLE, "role", "Role to add to the emoji", true) + ), + new SubcommandData("add", "Add a role to an existing message").addOptions( + new OptionData(OptionType.STRING, "messageid", "The ID of the message", true) + .setRequiredLength(19, 19), + new OptionData(OptionType.STRING, "emoji", "Emoji associated with the role", true), + new OptionData(OptionType.ROLE, "role", "Role to add to the emoji", true) + ), + new SubcommandData("remove", "Remove a role from a message").addOptions( + new OptionData(OptionType.STRING, "messageid", "The ID of the message", true) + .setRequiredLength(19, 19), + new OptionData(OptionType.STRING, "emoji", "Emoji to remove from the message", true) + ), + new SubcommandData("delete", "Remove all roles from a message").addOptions( + new OptionData(OptionType.STRING, "messageid", "The ID of the message", true) + .setRequiredLength(19, 19) ) + ) ); } @@ -107,24 +107,24 @@ public class ReactionCommand extends AdminCommand { for (EmojiReactionRoleTask item : tasks) { Map mapping = item.getEmojiMapping().entrySet().stream() - .map(entry -> { - Role role = context.getGuild().getRoleById(entry.getValue()); - return role != null ? Map.entry(entry.getKey(), role.getAsMention()) : null; - }) - .filter(Objects::nonNull) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + .map(entry -> { + Role role = context.getGuild().getRoleById(entry.getValue()); + return role != null ? Map.entry(entry.getKey(), role.getAsMention()) : null; + }) + .filter(Objects::nonNull) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); builder.append("\n- Task ID: ").append(item.getId()).append("\n") - .append(" Message: ") - .append(String.format(Message.JUMP_URL, item.getGuildId(), item.getChannelId(), item.getMessageId())) - .append("\n") - .append(" Emoji Mappings:\n"); + .append(" Message: ") + .append(String.format(Message.JUMP_URL, item.getGuildId(), item.getChannelId(), item.getMessageId())) + .append("\n") + .append(" Emoji Mappings:\n"); if (mapping.isEmpty()) { builder.append(" No emoji mappings found\n"); } else { mapping.forEach((emoji, roleMention) -> - builder.append(" - ").append(emoji).append(" → ").append(roleMention).append("\n") + builder.append(" - ").append(emoji).append(" → ").append(roleMention).append("\n") ); } } diff --git a/src/main/java/me/bobert/netneutrality/command/basic/HelpCommand.java b/src/main/java/me/bobert/netneutrality/command/basic/HelpCommand.java index 794ba99..7ad68cf 100644 --- a/src/main/java/me/bobert/netneutrality/command/basic/HelpCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/basic/HelpCommand.java @@ -5,10 +5,13 @@ package me.bobert.netneutrality.command.basic; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.*; +import me.bobert.netneutrality.core.command.CommandCategory; +import me.bobert.netneutrality.core.command.CommandContainer; +import me.bobert.netneutrality.core.command.CommandExecutionResult; +import me.bobert.netneutrality.core.command.CommandManager; +import me.bobert.netneutrality.core.command.CommandOptionsBuilder; import me.bobert.netneutrality.core.command.impl.AbstractCommand; import me.bobert.netneutrality.core.command.options.CommandOption; -import me.bobert.netneutrality.core.command.CommandOptionsBuilder; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.core.tasks.BuiltInTask; import me.bobert.netneutrality.tasks.help.BotInfo; diff --git a/src/main/java/me/bobert/netneutrality/command/basic/PingCommand.java b/src/main/java/me/bobert/netneutrality/command/basic/PingCommand.java index 801f96f..2183a9b 100644 --- a/src/main/java/me/bobert/netneutrality/command/basic/PingCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/basic/PingCommand.java @@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.basic; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.AbstractCommand; import me.bobert.netneutrality.core.command.CommandCategory; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.AbstractCommand; import me.bobert.netneutrality.core.context.CommandContext; public class PingCommand extends AbstractCommand { diff --git a/src/main/java/me/bobert/netneutrality/command/bot/ConfigureCommand.java b/src/main/java/me/bobert/netneutrality/command/bot/ConfigureCommand.java index 70891d7..10f3b24 100644 --- a/src/main/java/me/bobert/netneutrality/command/bot/ConfigureCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/bot/ConfigureCommand.java @@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.bot; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.AdminCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; -import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.AdminCommand; +import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.db.GSettings; import me.bobert.netneutrality.db.service.GuildService; @@ -48,15 +48,15 @@ public class ConfigureCommand extends AdminCommand { @Override public void registerCommandOptions(CommandOptionsBuilder builder) { builder.addSubcommands( - new SubcommandData("music-volume", "Volume for the music player") - .addOptions(new OptionData(OptionType.INTEGER, "volume", "Playback volume for every session", true) - .setRequiredRange(0, 100)), - new SubcommandData("error-logging", "Send errors to #error and/or #log channel") - .addOption(OptionType.BOOLEAN, "debug", "Enable or disable the fonctionnality", true), - new SubcommandData("music-role", "Role needed to use music commands") - .addOption(OptionType.ROLE, "role", "Name of role", true), - new SubcommandData("music-channel", "Only allow music commands on this channel") - .addOption(OptionType.CHANNEL, "channel", "Leave empty to allow everywhere") + new SubcommandData("music-volume", "Volume for the music player") + .addOptions(new OptionData(OptionType.INTEGER, "volume", "Playback volume for every session", true) + .setRequiredRange(0, 100)), + new SubcommandData("error-logging", "Send errors to #error and/or #log channel") + .addOption(OptionType.BOOLEAN, "debug", "Enable or disable the fonctionnality", true), + new SubcommandData("music-role", "Role needed to use music commands") + .addOption(OptionType.ROLE, "role", "Name of role", true), + new SubcommandData("music-channel", "Only allow music commands on this channel") + .addOption(OptionType.CHANNEL, "channel", "Leave empty to allow everywhere") ); } diff --git a/src/main/java/me/bobert/netneutrality/command/crypto/CryptoPriceCommand.java b/src/main/java/me/bobert/netneutrality/command/crypto/CryptoPriceCommand.java index cfb820d..24f9ee2 100644 --- a/src/main/java/me/bobert/netneutrality/command/crypto/CryptoPriceCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/crypto/CryptoPriceCommand.java @@ -6,11 +6,11 @@ package me.bobert.netneutrality.command.crypto; */ import me.bobert.netneutrality.core.LogHandler; -import me.bobert.netneutrality.core.command.impl.AbstractCommand; import me.bobert.netneutrality.core.command.CommandCategory; import me.bobert.netneutrality.core.command.CommandExecutionResult; -import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.AbstractCommand; +import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.http.WebModule; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -56,9 +56,9 @@ public class CryptoPriceCommand extends AbstractCommand { @Override public void registerCommandOptions(CommandOptionsBuilder builder) { builder.addOptions( - new OptionData(OptionType.STRING, "symbol", "The crypto symbol to fetch price for", true), - new OptionData(OptionType.STRING, "currency", "In which currency should the price be displayed") - .setRequiredLength(3, 3) + new OptionData(OptionType.STRING, "symbol", "The crypto symbol to fetch price for", true), + new OptionData(OptionType.STRING, "currency", "In which currency should the price be displayed") + .setRequiredLength(3, 3) ); } @@ -118,9 +118,9 @@ public class CryptoPriceCommand extends AbstractCommand { JSONObject json = http.getAsObject(); JSONObject pairs = json.getJSONObject("Data") - .getJSONObject("exchanges") - .getJSONObject(exchange) - .getJSONObject("pairs"); + .getJSONObject("exchanges") + .getJSONObject(exchange) + .getJSONObject("pairs"); return pairs.has(symbol); diff --git a/src/main/java/me/bobert/netneutrality/command/git/ReportIssueCommand.java b/src/main/java/me/bobert/netneutrality/command/git/ReportIssueCommand.java index b9c5322..9492d98 100644 --- a/src/main/java/me/bobert/netneutrality/command/git/ReportIssueCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/git/ReportIssueCommand.java @@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.git; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.AbstractCommand; import me.bobert.netneutrality.core.command.CommandCategory; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.AbstractCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.http.WebModule; import me.bobert.netneutrality.tasks.git.ReportIssueTask; diff --git a/src/main/java/me/bobert/netneutrality/command/music/BitconnectCommand.java b/src/main/java/me/bobert/netneutrality/command/music/BitconnectCommand.java index f899d8f..82e38da 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/BitconnectCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/BitconnectCommand.java @@ -6,10 +6,10 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandCategory; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; diff --git a/src/main/java/me/bobert/netneutrality/command/music/ClearQueueCommand.java b/src/main/java/me/bobert/netneutrality/command/music/ClearQueueCommand.java index 5397662..1bf96b1 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/ClearQueueCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/ClearQueueCommand.java @@ -6,9 +6,9 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; import me.bobert.netneutrality.utils.MusicUtils; diff --git a/src/main/java/me/bobert/netneutrality/command/music/CurrentlyPlayingCommand.java b/src/main/java/me/bobert/netneutrality/command/music/CurrentlyPlayingCommand.java index 63781fc..c60b45f 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/CurrentlyPlayingCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/CurrentlyPlayingCommand.java @@ -6,9 +6,9 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; import me.bobert.netneutrality.utils.MessageFunction; diff --git a/src/main/java/me/bobert/netneutrality/command/music/JoinCommand.java b/src/main/java/me/bobert/netneutrality/command/music/JoinCommand.java index 77d36f1..36a6efd 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/JoinCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/JoinCommand.java @@ -6,9 +6,9 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.utils.MusicUtils; diff --git a/src/main/java/me/bobert/netneutrality/command/music/LeaveCommand.java b/src/main/java/me/bobert/netneutrality/command/music/LeaveCommand.java index 8fe6c61..567d3fc 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/LeaveCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/LeaveCommand.java @@ -6,9 +6,9 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; import me.bobert.netneutrality.utils.MusicUtils; diff --git a/src/main/java/me/bobert/netneutrality/command/music/PlayCommand.java b/src/main/java/me/bobert/netneutrality/command/music/PlayCommand.java index 1dd2c58..8b02d7f 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/PlayCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/PlayCommand.java @@ -6,10 +6,10 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; -import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; +import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; import net.dv8tion.jda.api.interactions.commands.OptionType; diff --git a/src/main/java/me/bobert/netneutrality/command/music/QueueCommand.java b/src/main/java/me/bobert/netneutrality/command/music/QueueCommand.java index 8280697..17698a7 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/QueueCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/QueueCommand.java @@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; -import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; +import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; import me.bobert.netneutrality.utils.MessageFunction; @@ -43,16 +43,16 @@ public class QueueCommand extends MusicCommand { @Override public void registerCommandOptions(CommandOptionsBuilder builder) { builder.addSubcommands( - new SubcommandData("clear-all", "Clear all queued tracks"), - new SubcommandData("delete-track", "Remove a single track from the queue") - .addOptions(new OptionData(OptionType.INTEGER, "position", "Position of track", true) - .setMinValue(1)), - new SubcommandData("show-queue", "Display current queue"), - new SubcommandData("shuffle", "Shuffle the queue"), - new SubcommandData("from-user", "View tracks added by a user") - .addOption(OptionType.USER, "user", "Which user?", true), - new SubcommandData("remove-from-user", "Remove all tracks added by a user") - .addOption(OptionType.USER, "user", "Which user?", true) + new SubcommandData("clear-all", "Clear all queued tracks"), + new SubcommandData("delete-track", "Remove a single track from the queue") + .addOptions(new OptionData(OptionType.INTEGER, "position", "Position of track", true) + .setMinValue(1)), + new SubcommandData("show-queue", "Display current queue"), + new SubcommandData("shuffle", "Shuffle the queue"), + new SubcommandData("from-user", "View tracks added by a user") + .addOption(OptionType.USER, "user", "Which user?", true), + new SubcommandData("remove-from-user", "Remove all tracks added by a user") + .addOption(OptionType.USER, "user", "Which user?", true) ); } diff --git a/src/main/java/me/bobert/netneutrality/command/music/ResumeCommand.java b/src/main/java/me/bobert/netneutrality/command/music/ResumeCommand.java index 4a80b34..e0d699b 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/ResumeCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/ResumeCommand.java @@ -4,9 +4,9 @@ package me.bobert.netneutrality.command.music;/* * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; import me.bobert.netneutrality.utils.MusicUtils; diff --git a/src/main/java/me/bobert/netneutrality/command/music/ShuffleCommand.java b/src/main/java/me/bobert/netneutrality/command/music/ShuffleCommand.java index a004ff0..caeb025 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/ShuffleCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/ShuffleCommand.java @@ -6,9 +6,9 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; import me.bobert.netneutrality.utils.MusicUtils; diff --git a/src/main/java/me/bobert/netneutrality/command/music/SkipCommand.java b/src/main/java/me/bobert/netneutrality/command/music/SkipCommand.java index 59bbba2..b96c3a4 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/SkipCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/SkipCommand.java @@ -6,10 +6,10 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; -import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; +import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; import me.bobert.netneutrality.utils.MusicUtils; @@ -37,7 +37,7 @@ public class SkipCommand extends MusicCommand { @Override public void registerCommandOptions(CommandOptionsBuilder builder) { builder.addOptions(new OptionData(OptionType.INTEGER, "skip", "Number of tracks to skip") - .setMinValue(1)); + .setMinValue(1)); } @Override diff --git a/src/main/java/me/bobert/netneutrality/command/music/StopCommand.java b/src/main/java/me/bobert/netneutrality/command/music/StopCommand.java index 407126d..9c71355 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/StopCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/StopCommand.java @@ -6,9 +6,9 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; import me.bobert.netneutrality.utils.MusicUtils; diff --git a/src/main/java/me/bobert/netneutrality/command/music/ViewQueueCommand.java b/src/main/java/me/bobert/netneutrality/command/music/ViewQueueCommand.java index 767bbf8..48141d4 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/ViewQueueCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/ViewQueueCommand.java @@ -5,9 +5,9 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; import me.bobert.netneutrality.utils.MessageFunction; diff --git a/src/main/java/me/bobert/netneutrality/command/music/VolumeCommand.java b/src/main/java/me/bobert/netneutrality/command/music/VolumeCommand.java index 1ab6fef..cf21b6e 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/VolumeCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/VolumeCommand.java @@ -6,10 +6,10 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; -import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; +import me.bobert.netneutrality.core.command.options.CommandOption; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; import me.bobert.netneutrality.utils.MusicUtils; @@ -37,7 +37,7 @@ public class VolumeCommand extends MusicCommand { @Override public void registerCommandOptions(CommandOptionsBuilder builder) { builder.addOptions(new OptionData(OptionType.INTEGER, "volume", "Playback volume for this session", true) - .setRequiredRange(0, 100)); + .setRequiredRange(0, 100)); } @Override diff --git a/src/main/java/me/bobert/netneutrality/command/music/VoteSkipCommand.java b/src/main/java/me/bobert/netneutrality/command/music/VoteSkipCommand.java index 7889578..65f7488 100644 --- a/src/main/java/me/bobert/netneutrality/command/music/VoteSkipCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/music/VoteSkipCommand.java @@ -5,9 +5,9 @@ package me.bobert.netneutrality.command.music; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.CommandOptionsBuilder; +import me.bobert.netneutrality.core.command.impl.MusicCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.music.MusicManager; import me.bobert.netneutrality.utils.MusicUtils; diff --git a/src/main/java/me/bobert/netneutrality/command/react/CreateEmojiReaction.java b/src/main/java/me/bobert/netneutrality/command/react/CreateEmojiReaction.java index a7710a4..ccced89 100644 --- a/src/main/java/me/bobert/netneutrality/command/react/CreateEmojiReaction.java +++ b/src/main/java/me/bobert/netneutrality/command/react/CreateEmojiReaction.java @@ -6,8 +6,8 @@ package me.bobert.netneutrality.command.react; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MessageMenuCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; +import me.bobert.netneutrality.core.command.impl.MessageMenuCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.core.tasks.TaskManager; import me.bobert.netneutrality.tasks.emoji.EmojiReactionRoleTask; diff --git a/src/main/java/me/bobert/netneutrality/command/react/ModifyEmojiReaction.java b/src/main/java/me/bobert/netneutrality/command/react/ModifyEmojiReaction.java index 47d4032..0f66051 100644 --- a/src/main/java/me/bobert/netneutrality/command/react/ModifyEmojiReaction.java +++ b/src/main/java/me/bobert/netneutrality/command/react/ModifyEmojiReaction.java @@ -6,8 +6,8 @@ package me.bobert.netneutrality.command.react; * https://discord.gg/qUa6zNFZsd */ -import me.bobert.netneutrality.core.command.impl.MessageMenuCommand; import me.bobert.netneutrality.core.command.CommandExecutionResult; +import me.bobert.netneutrality.core.command.impl.MessageMenuCommand; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.core.tasks.TaskManager; import me.bobert.netneutrality.tasks.emoji.EmojiReactionRoleTask; diff --git a/src/main/java/me/bobert/netneutrality/context/command/MessageCommandContext.java b/src/main/java/me/bobert/netneutrality/context/command/MessageCommandContext.java index 7864318..b47efde 100644 --- a/src/main/java/me/bobert/netneutrality/context/command/MessageCommandContext.java +++ b/src/main/java/me/bobert/netneutrality/context/command/MessageCommandContext.java @@ -10,7 +10,10 @@ import me.bobert.netneutrality.core.command.options.MessageCommandOption; import me.bobert.netneutrality.core.context.CommandContext; import me.bobert.netneutrality.core.context.MessageContext; import me.bobert.netneutrality.utils.Settings; -import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Mentions; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -41,10 +44,10 @@ public class MessageCommandContext extends CommandContext implements MessageCont @Override public String getId() { return String.format("%s:%s:%s:%s", - getGuild() == null ? "PrivateMessage" : getGuild().getId(), - getChannel().getId(), - getDiscordUser().getId(), - message.getId()); + getGuild() == null ? "PrivateMessage" : getGuild().getId(), + getChannel().getId(), + getDiscordUser().getId(), + message.getId()); } @Override @@ -208,7 +211,7 @@ public class MessageCommandContext extends CommandContext implements MessageCont if (!requiredChannelTypes.contains(channel.getType())) { invalidateContext(data, "not a valid channel type at index " + (index + 1) + - " , valid types are: " + validTypes(requiredChannelTypes)); + " , valid types are: " + validTypes(requiredChannelTypes)); break; } diff --git a/src/main/java/me/bobert/netneutrality/context/tasks/EmojiTaskContext.java b/src/main/java/me/bobert/netneutrality/context/tasks/EmojiTaskContext.java index 3a93ede..b9b9563 100644 --- a/src/main/java/me/bobert/netneutrality/context/tasks/EmojiTaskContext.java +++ b/src/main/java/me/bobert/netneutrality/context/tasks/EmojiTaskContext.java @@ -8,11 +8,8 @@ package me.bobert.netneutrality.context.tasks; import me.bobert.netneutrality.context.AsyncContext; import me.bobert.netneutrality.core.context.NoMessageContext; import me.bobert.netneutrality.core.context.TaskContext; -import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; -import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.interactions.components.LayoutComponent; -import net.dv8tion.jda.api.interactions.modals.Modal; import net.dv8tion.jda.api.utils.messages.MessageCreateData; import java.util.List; diff --git a/src/main/java/me/bobert/netneutrality/core/LogHandler.java b/src/main/java/me/bobert/netneutrality/core/LogHandler.java index 790036a..2efc046 100644 --- a/src/main/java/me/bobert/netneutrality/core/LogHandler.java +++ b/src/main/java/me/bobert/netneutrality/core/LogHandler.java @@ -51,10 +51,10 @@ public class LogHandler { public static void sendMessageToDebugChannel(Guild guild, String message) { guild.getTextChannels() - .stream() - .filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log")) - .filter(TextChannel::canTalk) - .forEach(textChannel -> textChannel.sendMessage(message).queue()); + .stream() + .filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log")) + .filter(TextChannel::canTalk) + .forEach(textChannel -> textChannel.sendMessage(message).queue()); } @@ -63,8 +63,8 @@ public class LogHandler { String guildId = context.getGuild() == null ? "PrivateMessage" : context.getGuild().getId(); logger.error("Exception thrown from context (guild: {}, user: {}): {}", guildId, - context.getDiscordUser().getId(), - exception.getMessage() + context.getDiscordUser().getId(), + exception.getMessage() ); if (context instanceof CommandContext commandContext) { @@ -82,11 +82,11 @@ public class LogHandler { if (context.getGuild() != null) { if (GuildService.get(context.getGuild()).isDebugEnabled()) { context.getGuild() - .getTextChannels() - .stream() - .filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log")) - .filter(TextChannel::canTalk) - .forEach(textChannel -> textChannel.sendMessageEmbeds(MessageFunction.buildDebugMessage(exception)).queue()); + .getTextChannels() + .stream() + .filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log")) + .filter(TextChannel::canTalk) + .forEach(textChannel -> textChannel.sendMessageEmbeds(MessageFunction.buildDebugMessage(exception)).queue()); } } } diff --git a/src/main/java/me/bobert/netneutrality/core/command/CommandContainer.java b/src/main/java/me/bobert/netneutrality/core/command/CommandContainer.java index 1960f14..f44b126 100644 --- a/src/main/java/me/bobert/netneutrality/core/command/CommandContainer.java +++ b/src/main/java/me/bobert/netneutrality/core/command/CommandContainer.java @@ -94,14 +94,14 @@ public class CommandContainer { if (!subcommandGroups.isEmpty()) { for (SubcommandGroupData subcommandGroup : subcommandGroups) { usage.append("- Subcommand: /").append(command.getCommandName()) - .append(" ").append(subcommandGroup.getName()) - .append(" (").append(subcommandGroup.getDescription()).append(")") - .append("\n"); + .append(" ").append(subcommandGroup.getName()) + .append(" (").append(subcommandGroup.getDescription()).append(")") + .append("\n"); for (SubcommandData subcommand : subcommandGroup.getSubcommands()) { usage.append(" - Usage: /").append(command.getCommandName()) - .append(" ").append(subcommandGroup.getName()) - .append(" ").append(subcommand.getName()); + .append(" ").append(subcommandGroup.getName()) + .append(" ").append(subcommand.getName()); for (OptionData option : subcommand.getOptions()) { usage.append(" <").append(option.getName()).append(">"); @@ -130,7 +130,10 @@ public class CommandContainer { for (OptionData option : options) { usage.append("\n"); - if (group) usage.append(" "); + if (group) { + usage.append(" "); + } + usage.append(" - "); if (option.isRequired()) { usage.append("*"); diff --git a/src/main/java/me/bobert/netneutrality/core/command/CommandOptionsBuilder.java b/src/main/java/me/bobert/netneutrality/core/command/CommandOptionsBuilder.java index a3ca2dd..d3459f0 100644 --- a/src/main/java/me/bobert/netneutrality/core/command/CommandOptionsBuilder.java +++ b/src/main/java/me/bobert/netneutrality/core/command/CommandOptionsBuilder.java @@ -9,7 +9,11 @@ import net.dv8tion.jda.api.interactions.DiscordLocale; import net.dv8tion.jda.api.interactions.IntegrationType; import net.dv8tion.jda.api.interactions.InteractionContextType; import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions; -import net.dv8tion.jda.api.interactions.commands.build.*; +import net.dv8tion.jda.api.interactions.commands.build.Commands; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData; +import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; +import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData; import net.dv8tion.jda.api.interactions.commands.localization.LocalizationFunction; import net.dv8tion.jda.api.interactions.commands.localization.LocalizationMap; import net.dv8tion.jda.api.utils.data.DataObject; diff --git a/src/main/java/me/bobert/netneutrality/core/command/CommandProcessor.java b/src/main/java/me/bobert/netneutrality/core/command/CommandProcessor.java index 0673248..77615ba 100644 --- a/src/main/java/me/bobert/netneutrality/core/command/CommandProcessor.java +++ b/src/main/java/me/bobert/netneutrality/core/command/CommandProcessor.java @@ -27,7 +27,10 @@ import java.util.List; import java.util.Map; import static java.util.function.Predicate.not; -import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.*; +import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.ERROR; +import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.NOACTION; +import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.TASK; +import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.WARN; public class CommandProcessor { @@ -239,7 +242,7 @@ public class CommandProcessor { private String invalidUsage(String message) { return String.format("Invalid usage for command: %s\n" + - "Use **/help %s** for information on how to use this command", message, context.getCommand().getCommandName()); + "Use **/help %s** for information on how to use this command", message, context.getCommand().getCommandName()); } private void configureSentry(Command command) { diff --git a/src/main/java/me/bobert/netneutrality/core/command/impl/MusicCommand.java b/src/main/java/me/bobert/netneutrality/core/command/impl/MusicCommand.java index 9fdadec..953e678 100644 --- a/src/main/java/me/bobert/netneutrality/core/command/impl/MusicCommand.java +++ b/src/main/java/me/bobert/netneutrality/core/command/impl/MusicCommand.java @@ -64,8 +64,9 @@ public abstract class MusicCommand extends AbstractCommand { @Override public boolean canBeExecutedFrom(MessageChannel channel) { if (channel instanceof GuildMessageChannel guildMessageChannel) { - if (channel.getType() != ChannelType.TEXT) + if (channel.getType() != ChannelType.TEXT) { return false; + } String channelDb = GuildService.get(guildMessageChannel.getGuild()).getGuildSettingService().getSetting(GSettings.MUSIC_CHANNEL); if (channelDb != null && !channelDb.isEmpty()) { diff --git a/src/main/java/me/bobert/netneutrality/core/command/options/CommandOption.java b/src/main/java/me/bobert/netneutrality/core/command/options/CommandOption.java index 0a17ae2..54430eb 100644 --- a/src/main/java/me/bobert/netneutrality/core/command/options/CommandOption.java +++ b/src/main/java/me/bobert/netneutrality/core/command/options/CommandOption.java @@ -5,7 +5,11 @@ package me.bobert.netneutrality.core.command.options; * https://discord.gg/qUa6zNFZsd */ -import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.IMentionable; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -29,10 +33,8 @@ public interface CommandOption { *
This is represented as an {@link Message.Attachment#isEphemeral() ephemeral} attachment which will only be hosted for up to 2 weeks. * If you want a permanent reference, you must download it. * - * @throws IllegalStateException - * If this option {@link #getType() type} is not {@link OptionType#ATTACHMENT} - * * @return {@link net.dv8tion.jda.api.entities.Message.Attachment Attachment} + * @throws IllegalStateException If this option {@link #getType() type} is not {@link OptionType#ATTACHMENT} */ Message.Attachment getAsAttachment(); @@ -48,10 +50,8 @@ public interface CommandOption { /** * The boolean value. * - * @throws IllegalStateException - * If this option is not of type {@link OptionType#BOOLEAN BOOLEAN} - * * @return The boolean value + * @throws IllegalStateException If this option is not of type {@link OptionType#BOOLEAN BOOLEAN} */ boolean getAsBoolean(); @@ -59,12 +59,9 @@ public interface CommandOption { * The long value for this option. *
This will be the ID of any resolved entity such as {@link Role} or {@link Member}. * - * @throws IllegalStateException - * If this option {@link #getType() type} cannot be converted to a long - * @throws NumberFormatException - * If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid long value - * * @return The long value + * @throws IllegalStateException If this option {@link #getType() type} cannot be converted to a long + * @throws NumberFormatException If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid long value */ long getAsLong(); @@ -74,36 +71,27 @@ public interface CommandOption { * *

It is highly recommended to assert int values by using {@link OptionData#setRequiredRange(long, long)} * - * @throws IllegalStateException - * If this option {@link #getType() type} cannot be converted to a long - * @throws NumberFormatException - * If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid long value - * @throws ArithmeticException - * If the provided integer value cannot fit into a 32bit signed int - * * @return The int value + * @throws IllegalStateException If this option {@link #getType() type} cannot be converted to a long + * @throws NumberFormatException If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid long value + * @throws ArithmeticException If the provided integer value cannot fit into a 32bit signed int */ int getAsInt(); /** * The double value for this option. * - * @throws IllegalStateException - * If this option {@link #getType() type} cannot be converted to a double - * @throws NumberFormatException - * If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid double value - * * @return The double value + * @throws IllegalStateException If this option {@link #getType() type} cannot be converted to a double + * @throws NumberFormatException If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid double value */ double getAsDouble(); /** * The resolved {@link IMentionable} instance for this option value. * - * @throws IllegalStateException - * If the mentioned entity is not resolvable - * * @return The resolved {@link IMentionable} + * @throws IllegalStateException If the mentioned entity is not resolvable */ IMentionable getAsMentionable(); @@ -111,42 +99,34 @@ public interface CommandOption { * The resolved {@link Member} for this option value. *
Note that {@link OptionType#USER OptionType.USER} can also accept users that are not members of a guild, in which case this will be null! * - * @throws IllegalStateException - * If this option is not of type {@link OptionType#USER USER} or {@link OptionType#MENTIONABLE MENTIONABLE} - * * @return The resolved {@link Member}, or null + * @throws IllegalStateException If this option is not of type {@link OptionType#USER USER} or {@link OptionType#MENTIONABLE MENTIONABLE} */ Member getAsMember(); /** * The resolved {@link User} for this option value. * - * @throws IllegalStateException - * If this option is not of type {@link OptionType#USER USER} or - * {@link OptionType#MENTIONABLE MENTIONABLE} without a resolved user - * * @return The resolved {@link User} + * @throws IllegalStateException If this option is not of type {@link OptionType#USER USER} or + * {@link OptionType#MENTIONABLE MENTIONABLE} without a resolved user */ User getAsUser(); /** * The resolved {@link Role} for this option value. * - * @throws IllegalStateException - * If this option is not of type {@link OptionType#ROLE ROLE} or - * {@link OptionType#MENTIONABLE MENTIONABLE} without a resolved role - * * @return The resolved {@link Role} + * @throws IllegalStateException If this option is not of type {@link OptionType#ROLE ROLE} or + * {@link OptionType#MENTIONABLE MENTIONABLE} without a resolved role */ Role getAsRole(); /** * The {@link ChannelType} for the resolved channel. * - * @throws IllegalStateException - * If this option is not of type {@link OptionType#CHANNEL CHANNEL} - * * @return The {@link ChannelType} + * @throws IllegalStateException If this option is not of type {@link OptionType#CHANNEL CHANNEL} */ ChannelType getChannelType(); @@ -154,11 +134,9 @@ public interface CommandOption { * The resolved {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel} for this option value. *
Note that {@link OptionType#CHANNEL OptionType.CHANNEL} can accept channels of any type! * - * @throws IllegalStateException - * If this option is not of type {@link OptionType#CHANNEL CHANNEL} - * or could not be resolved for unexpected reasons - * * @return The resolved {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel} + * @throws IllegalStateException If this option is not of type {@link OptionType#CHANNEL CHANNEL} + * or could not be resolved for unexpected reasons */ GuildChannelUnion getAsChannel(); } diff --git a/src/main/java/me/bobert/netneutrality/core/command/options/MessageCommandOption.java b/src/main/java/me/bobert/netneutrality/core/command/options/MessageCommandOption.java index ab1f0b3..e07b385 100644 --- a/src/main/java/me/bobert/netneutrality/core/command/options/MessageCommandOption.java +++ b/src/main/java/me/bobert/netneutrality/core/command/options/MessageCommandOption.java @@ -5,7 +5,11 @@ package me.bobert.netneutrality.core.command.options; * https://discord.gg/qUa6zNFZsd */ -import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.IMentionable; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -149,9 +153,9 @@ public class MessageCommandOption implements CommandOption { @Override public String toString() { return "MessageCommandOption{" + - "name=" + data.getName() + - ", type=" + type + - ", value=" + value + - '}'; + "name=" + data.getName() + + ", type=" + type + + ", value=" + value + + '}'; } } diff --git a/src/main/java/me/bobert/netneutrality/core/command/options/SlashCommandOption.java b/src/main/java/me/bobert/netneutrality/core/command/options/SlashCommandOption.java index 90a8c0d..56e631d 100644 --- a/src/main/java/me/bobert/netneutrality/core/command/options/SlashCommandOption.java +++ b/src/main/java/me/bobert/netneutrality/core/command/options/SlashCommandOption.java @@ -5,7 +5,11 @@ package me.bobert.netneutrality.core.command.options; * https://discord.gg/qUa6zNFZsd */ -import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.IMentionable; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion; import net.dv8tion.jda.api.interactions.commands.OptionMapping; diff --git a/src/main/java/me/bobert/netneutrality/core/context/AbstractContext.java b/src/main/java/me/bobert/netneutrality/core/context/AbstractContext.java index ca55682..7d45998 100644 --- a/src/main/java/me/bobert/netneutrality/core/context/AbstractContext.java +++ b/src/main/java/me/bobert/netneutrality/core/context/AbstractContext.java @@ -6,7 +6,6 @@ package me.bobert.netneutrality.core.context; */ import io.sentry.Sentry; -import me.bobert.netneutrality.context.command.SlashCommandContext; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; diff --git a/src/main/java/me/bobert/netneutrality/core/context/CommandContext.java b/src/main/java/me/bobert/netneutrality/core/context/CommandContext.java index a950e28..55983d2 100644 --- a/src/main/java/me/bobert/netneutrality/core/context/CommandContext.java +++ b/src/main/java/me/bobert/netneutrality/core/context/CommandContext.java @@ -17,7 +17,12 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData; import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -26,7 +31,7 @@ public abstract class CommandContext extends AbstractContext { private Command command; private SubcommandGroupData subcommandGroup; private SubcommandData subcommand; - private final Map invalidOptions = new HashMap<>(); + private final Map invalidOptions = new HashMap<>(); private final List options; public CommandContext(JDA jda, Guild guild, MessageChannel channel, Member member, User user) { @@ -70,16 +75,20 @@ public abstract class CommandContext extends AbstractContext { public T getOption(String name, Supplier fallback, Function resolver) { Objects.requireNonNull(resolver, "resolver cannot be null"); CommandOption mapping = getOption(name); - if (mapping != null) + if (mapping != null) { return resolver.apply(mapping); + } + return fallback == null ? null : fallback.get(); } public T getOption(String name, T fallback, Function resolver) { Objects.requireNonNull(resolver, "resolver cannot be null"); CommandOption mapping = getOption(name); - if (mapping != null) + if (mapping != null) { return resolver.apply(mapping); + } + return fallback; } @@ -132,7 +141,4 @@ public abstract class CommandContext extends AbstractContext { public abstract String parseCommandName(); public abstract String getFullCommand(); - - - } diff --git a/src/main/java/me/bobert/netneutrality/core/context/Context.java b/src/main/java/me/bobert/netneutrality/core/context/Context.java index bcf7ebd..d9a5504 100644 --- a/src/main/java/me/bobert/netneutrality/core/context/Context.java +++ b/src/main/java/me/bobert/netneutrality/core/context/Context.java @@ -8,7 +8,11 @@ package me.bobert.netneutrality.core.context; import me.bobert.netneutrality.context.AsyncContext; import me.bobert.netneutrality.utils.ContextUtils; import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.MessageEmbed; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.Event; @@ -159,8 +163,8 @@ public interface Context { User user = getDiscordUser(); if (user != null) { user.openPrivateChannel() - .flatMap(channel -> channel.sendMessage(messageCreateData).setComponents(components)) - .queue(message -> consumer.accept(new AsyncContext(message))); + .flatMap(channel -> channel.sendMessage(messageCreateData).setComponents(components)) + .queue(message -> consumer.accept(new AsyncContext(message))); } } diff --git a/src/main/java/me/bobert/netneutrality/core/db/DatabaseMigration.java b/src/main/java/me/bobert/netneutrality/core/db/DatabaseMigration.java index fe846e5..f0b49af 100644 --- a/src/main/java/me/bobert/netneutrality/core/db/DatabaseMigration.java +++ b/src/main/java/me/bobert/netneutrality/core/db/DatabaseMigration.java @@ -21,9 +21,9 @@ public class DatabaseMigration { try { Flyway flyway = Flyway.configure() - .dataSource(String.format("jdbc:mysql://%s:3306/%s", dbHost, dbName), dbUser, dbPass) - .baselineOnMigrate(true) - .load(); + .dataSource(String.format("jdbc:mysql://%s:3306/%s", dbHost, dbName), dbUser, dbPass) + .baselineOnMigrate(true) + .load(); flyway.migrate(); } catch (Exception e) { diff --git a/src/main/java/me/bobert/netneutrality/core/tasks/AbstractTask.java b/src/main/java/me/bobert/netneutrality/core/tasks/AbstractTask.java index ba5d5a1..a50c620 100644 --- a/src/main/java/me/bobert/netneutrality/core/tasks/AbstractTask.java +++ b/src/main/java/me/bobert/netneutrality/core/tasks/AbstractTask.java @@ -29,8 +29,12 @@ public abstract class AbstractTask implements Task { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } AbstractTask that = (AbstractTask) o; return Objects.equals(getId(), that.getId()); diff --git a/src/main/java/me/bobert/netneutrality/core/tasks/Task.java b/src/main/java/me/bobert/netneutrality/core/tasks/Task.java index bc2a084..3b337bb 100644 --- a/src/main/java/me/bobert/netneutrality/core/tasks/Task.java +++ b/src/main/java/me/bobert/netneutrality/core/tasks/Task.java @@ -20,12 +20,13 @@ public interface Task { REMOVE_SELF, REMOVE_SELF_AND_CHILDREN } + /** * This method should generate a unique ID to differentiate it from other tasks. *

- * This determines what triggers a task to be executed. - * For example, a modal or button would use the component id. - * For an emoji reaction, the guild and message id would be combined. + * This determines what triggers a task to be executed. + * For example, a modal or button would use the component id. + * For an emoji reaction, the guild and message id would be combined. *

* * @return a unique ID for this task @@ -44,6 +45,7 @@ public interface Task { /** * This is only used for debugging purpose. + * * @return Name of the task */ String getName(); @@ -55,6 +57,7 @@ public interface Task { /** * When this returns true, the task will get removed by the cleanup thread. + * * @return If the task is expired */ boolean isExpired(); @@ -71,6 +74,7 @@ public interface Task { /** * Executes the task. + * * @param context The context for this task. */ Lifecycle execute(TaskContext context); diff --git a/src/main/java/me/bobert/netneutrality/core/tasks/TaskManager.java b/src/main/java/me/bobert/netneutrality/core/tasks/TaskManager.java index cd13aa0..52d7a0f 100644 --- a/src/main/java/me/bobert/netneutrality/core/tasks/TaskManager.java +++ b/src/main/java/me/bobert/netneutrality/core/tasks/TaskManager.java @@ -25,7 +25,11 @@ import org.reflections.Reflections; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; @@ -125,7 +129,7 @@ public class TaskManager { if (pendingTasks.remove(task)) { tasks.put(task.getId(), task); logger.info("Updating task {} with new id: {} (was: {})", - task.getName(), task.getId(), oldId); + task.getName(), task.getId(), oldId); } } @@ -206,18 +210,18 @@ public class TaskManager { public List findTasksByPartialId(Class clazz, String partialId) { return tasks.values().stream() - .filter(clazz::isInstance) - .map(clazz::cast) - .filter(task -> task.getId().contains(partialId)) - .collect(Collectors.toList()); + .filter(clazz::isInstance) + .map(clazz::cast) + .filter(task -> task.getId().contains(partialId)) + .collect(Collectors.toList()); } public BuiltInTask findBuiltInTaskByClass(Class clazz) { return tasks.values().stream() - .filter(clazz::isInstance) - .map(task -> (BuiltInTask) task) - .findFirst() - .orElse(null); + .filter(clazz::isInstance) + .map(task -> (BuiltInTask) task) + .findFirst() + .orElse(null); } public void insertPersistableTask(PersistableTask task) { diff --git a/src/main/java/me/bobert/netneutrality/core/tasks/impl/ModalTask.java b/src/main/java/me/bobert/netneutrality/core/tasks/impl/ModalTask.java index 94db7a9..beb5a01 100644 --- a/src/main/java/me/bobert/netneutrality/core/tasks/impl/ModalTask.java +++ b/src/main/java/me/bobert/netneutrality/core/tasks/impl/ModalTask.java @@ -22,9 +22,9 @@ public abstract class ModalTask extends GenericRandomIdTask { public ModalMapping getValue(String key, TaskContext context) { List mappings = (List) context.getContextData("values"); return mappings.stream() - .filter(o -> o instanceof ModalMapping) - .map(o -> (ModalMapping) o) - .filter(mapping -> mapping.getId().equals(key)) - .findFirst().orElse(null); + .filter(o -> o instanceof ModalMapping) + .map(o -> (ModalMapping) o) + .filter(mapping -> mapping.getId().equals(key)) + .findFirst().orElse(null); } } diff --git a/src/main/java/me/bobert/netneutrality/core/tasks/impl/StepTask.java b/src/main/java/me/bobert/netneutrality/core/tasks/impl/StepTask.java index 0c7f92a..f0466ab 100644 --- a/src/main/java/me/bobert/netneutrality/core/tasks/impl/StepTask.java +++ b/src/main/java/me/bobert/netneutrality/core/tasks/impl/StepTask.java @@ -63,9 +63,9 @@ public abstract class StepTask extends AbstractTask implements IStepTask { context.replyEphemeral("Please follow the instructions sent in DM."); context.sendMessageInPrivate(getStepDescription() + "\n\n" + getStepQuestion(), - asyncContext -> assignId(asyncContext.getMessageId())); + asyncContext -> assignId(asyncContext.getMessageId())); } - + @Override public Lifecycle execute(TaskContext context) { synchronized (stepLock) { diff --git a/src/main/java/me/bobert/netneutrality/core/thread/ThreadManager.java b/src/main/java/me/bobert/netneutrality/core/thread/ThreadManager.java index a08fb9e..1f03be1 100644 --- a/src/main/java/me/bobert/netneutrality/core/thread/ThreadManager.java +++ b/src/main/java/me/bobert/netneutrality/core/thread/ThreadManager.java @@ -6,7 +6,11 @@ package me.bobert.netneutrality.core.thread; */ import java.util.Map; -import java.util.concurrent.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; public class ThreadManager { @@ -14,11 +18,11 @@ public class ThreadManager { public static ScheduledExecutorService getScheduledExecutor() { return (ScheduledExecutorService) executors.computeIfAbsent( - "scheduled-executor", - s -> Executors.newScheduledThreadPool( - Runtime.getRuntime().availableProcessors(), - new BaseThreadFactory(s) - ) + "scheduled-executor", + s -> Executors.newScheduledThreadPool( + Runtime.getRuntime().availableProcessors(), + new BaseThreadFactory(s) + ) ); } @@ -38,11 +42,9 @@ public class ThreadManager { ex.shutdown(); ex.awaitTermination(1, TimeUnit.SECONDS); } - } - catch (InterruptedException e) { + } catch (InterruptedException e) { System.err.println("[Executor] Running tasks interrupted"); - } - finally { + } finally { executors.forEach((name, ex) -> { if (!ex.isTerminated()) { System.err.println("[Executor: " + name + "] Forcing shutdown of running tasks.."); diff --git a/src/main/java/me/bobert/netneutrality/db/Repository.java b/src/main/java/me/bobert/netneutrality/db/Repository.java index 09494a6..572ad9b 100644 --- a/src/main/java/me/bobert/netneutrality/db/Repository.java +++ b/src/main/java/me/bobert/netneutrality/db/Repository.java @@ -24,7 +24,7 @@ public interface Repository { default void save(O entity) { Transaction transaction = null; - try(Session session = SessionManager.getSessionFactory().openSession()) { + try (Session session = SessionManager.getSessionFactory().openSession()) { transaction = session.beginTransaction(); session.merge(entity); transaction.commit(); diff --git a/src/main/java/me/bobert/netneutrality/db/entities/OBlacklist.java b/src/main/java/me/bobert/netneutrality/db/entities/OBlacklist.java index 6a44f51..3c92d90 100644 --- a/src/main/java/me/bobert/netneutrality/db/entities/OBlacklist.java +++ b/src/main/java/me/bobert/netneutrality/db/entities/OBlacklist.java @@ -6,7 +6,15 @@ package me.bobert.netneutrality.db.entities; * https://discord.gg/qUa6zNFZsd */ -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; @Entity @Table(name = "blacklist") diff --git a/src/main/java/me/bobert/netneutrality/db/entities/OGuild.java b/src/main/java/me/bobert/netneutrality/db/entities/OGuild.java index 021b560..0690ee2 100644 --- a/src/main/java/me/bobert/netneutrality/db/entities/OGuild.java +++ b/src/main/java/me/bobert/netneutrality/db/entities/OGuild.java @@ -6,7 +6,11 @@ package me.bobert.netneutrality.db.entities; * https://discord.gg/qUa6zNFZsd */ -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; import java.util.LinkedHashSet; import java.util.Optional; @@ -108,9 +112,9 @@ public class OGuild { public OGuildSetting getSettingByName(String name) { Optional setting = getGuildSettings() - .stream() - .filter(setting1 -> setting1.getName().equalsIgnoreCase(name)) - .findFirst(); + .stream() + .filter(setting1 -> setting1.getName().equalsIgnoreCase(name)) + .findFirst(); return setting.orElse(null); } diff --git a/src/main/java/me/bobert/netneutrality/db/entities/OGuildSetting.java b/src/main/java/me/bobert/netneutrality/db/entities/OGuildSetting.java index a868311..fe6ad73 100644 --- a/src/main/java/me/bobert/netneutrality/db/entities/OGuildSetting.java +++ b/src/main/java/me/bobert/netneutrality/db/entities/OGuildSetting.java @@ -6,12 +6,23 @@ package me.bobert.netneutrality.db.entities; * https://discord.gg/qUa6zNFZsd */ -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.NamedQueries; +import jakarta.persistence.NamedQuery; +import jakarta.persistence.Table; @Entity @Table(name = "guild_settings") @NamedQueries({ - @NamedQuery(name = "settings_findByName", query = "select o from OGuildSetting o where o.guild.id = :id and upper(o.name) = upper(:name)") + @NamedQuery(name = "settings_findByName", query = "select o from OGuildSetting o where o.guild.id = :id and upper(o.name) = upper(:name)") }) public class OGuildSetting { @Id diff --git a/src/main/java/me/bobert/netneutrality/db/entities/OLogMessage.java b/src/main/java/me/bobert/netneutrality/db/entities/OLogMessage.java index 4211dc7..1814850 100644 --- a/src/main/java/me/bobert/netneutrality/db/entities/OLogMessage.java +++ b/src/main/java/me/bobert/netneutrality/db/entities/OLogMessage.java @@ -6,7 +6,16 @@ package me.bobert.netneutrality.db.entities; * https://discord.gg/qUa6zNFZsd */ -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Convert; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import java.time.Instant; diff --git a/src/main/java/me/bobert/netneutrality/db/entities/OLogging.java b/src/main/java/me/bobert/netneutrality/db/entities/OLogging.java index 7dd2992..09808c6 100644 --- a/src/main/java/me/bobert/netneutrality/db/entities/OLogging.java +++ b/src/main/java/me/bobert/netneutrality/db/entities/OLogging.java @@ -6,7 +6,14 @@ package me.bobert.netneutrality.db.entities; * https://discord.gg/qUa6zNFZsd */ -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.MapsId; +import jakarta.persistence.Table; @Entity @Table(name = "logging") diff --git a/src/main/java/me/bobert/netneutrality/db/entities/OLoggingId.java b/src/main/java/me/bobert/netneutrality/db/entities/OLoggingId.java index 9cf3671..256d2cb 100644 --- a/src/main/java/me/bobert/netneutrality/db/entities/OLoggingId.java +++ b/src/main/java/me/bobert/netneutrality/db/entities/OLoggingId.java @@ -46,10 +46,14 @@ public class OLoggingId implements Serializable { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; + if (this == o) { + return true; + } + if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) { + return false; + } OLoggingId entity = (OLoggingId) o; return Objects.equals(this.guildId, entity.guildId) && - Objects.equals(this.channelId, entity.channelId); + Objects.equals(this.channelId, entity.channelId); } } \ No newline at end of file diff --git a/src/main/java/me/bobert/netneutrality/db/entities/OTask.java b/src/main/java/me/bobert/netneutrality/db/entities/OTask.java index 035d3bf..385bb70 100644 --- a/src/main/java/me/bobert/netneutrality/db/entities/OTask.java +++ b/src/main/java/me/bobert/netneutrality/db/entities/OTask.java @@ -5,7 +5,14 @@ package me.bobert.netneutrality.db.entities; * https://discord.gg/qUa6zNFZsd */ -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; @Entity @Table(name = "tasks", uniqueConstraints = {@UniqueConstraint(columnNames = {"task_id"})}) diff --git a/src/main/java/me/bobert/netneutrality/db/entities/OWebUser.java b/src/main/java/me/bobert/netneutrality/db/entities/OWebUser.java index 808bf7b..87e983e 100644 --- a/src/main/java/me/bobert/netneutrality/db/entities/OWebUser.java +++ b/src/main/java/me/bobert/netneutrality/db/entities/OWebUser.java @@ -6,7 +6,11 @@ package me.bobert.netneutrality.db.entities; * https://discord.gg/qUa6zNFZsd */ -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; import org.hibernate.annotations.ColumnDefault; import java.time.Instant; diff --git a/src/main/java/me/bobert/netneutrality/db/repository/BlacklistRepository.java b/src/main/java/me/bobert/netneutrality/db/repository/BlacklistRepository.java index b6bd763..6c794a5 100644 --- a/src/main/java/me/bobert/netneutrality/db/repository/BlacklistRepository.java +++ b/src/main/java/me/bobert/netneutrality/db/repository/BlacklistRepository.java @@ -92,7 +92,7 @@ public class BlacklistRepository implements Repository { } private OBlacklist getWordFromDb(String guildId, String word) { - try(Session session = SessionManager.getSessionFactory().openSession()) { + try (Session session = SessionManager.getSessionFactory().openSession()) { Query query = session.createQuery("SELECT o FROM OBlacklist o WHERE upper(o.word) = upper(:word) AND o.guild.guildId = :guildId", OBlacklist.class); query.setParameter("guildId", guildId); query.setParameter("word", word); diff --git a/src/main/java/me/bobert/netneutrality/db/repository/GuildRepository.java b/src/main/java/me/bobert/netneutrality/db/repository/GuildRepository.java index dadeb3b..0738e6b 100644 --- a/src/main/java/me/bobert/netneutrality/db/repository/GuildRepository.java +++ b/src/main/java/me/bobert/netneutrality/db/repository/GuildRepository.java @@ -30,7 +30,7 @@ public class GuildRepository implements Repository { @Override public OGuild findById(String id) { - try(Session session = SessionManager.getSessionFactory().openSession()) { + try (Session session = SessionManager.getSessionFactory().openSession()) { Query query = session.createQuery("SELECT o FROM OGuild o WHERE o.guildId = :guildId", OGuild.class); query.setParameter("guildId", id); diff --git a/src/main/java/me/bobert/netneutrality/db/repository/GuildSettingRepository.java b/src/main/java/me/bobert/netneutrality/db/repository/GuildSettingRepository.java index 66a5a02..921579b 100644 --- a/src/main/java/me/bobert/netneutrality/db/repository/GuildSettingRepository.java +++ b/src/main/java/me/bobert/netneutrality/db/repository/GuildSettingRepository.java @@ -32,7 +32,7 @@ public class GuildSettingRepository implements Repository { @Override public OGuildSetting findById(String id) { - try(Session session = SessionManager.getSessionFactory().openSession()) { + try (Session session = SessionManager.getSessionFactory().openSession()) { Query query = session.createQuery("SELECT o FROM OGuildSetting o WHERE o.id = :id", OGuildSetting.class); query.setParameter("id", id); diff --git a/src/main/java/me/bobert/netneutrality/db/repository/MessageRepository.java b/src/main/java/me/bobert/netneutrality/db/repository/MessageRepository.java index 2294701..e65b9ec 100644 --- a/src/main/java/me/bobert/netneutrality/db/repository/MessageRepository.java +++ b/src/main/java/me/bobert/netneutrality/db/repository/MessageRepository.java @@ -35,7 +35,7 @@ public class MessageRepository implements Repository { @Override public OLogMessage findById(String id) { - try(Session session = SessionManager.getSessionFactory().openSession()) { + try (Session session = SessionManager.getSessionFactory().openSession()) { Query query = session.createQuery("SELECT o FROM OLogMessage o WHERE o.messageId = :messageId", OLogMessage.class); query.setParameter("messageId", id); diff --git a/src/main/java/me/bobert/netneutrality/db/repository/TaskRepository.java b/src/main/java/me/bobert/netneutrality/db/repository/TaskRepository.java index 127fd0a..48535c1 100644 --- a/src/main/java/me/bobert/netneutrality/db/repository/TaskRepository.java +++ b/src/main/java/me/bobert/netneutrality/db/repository/TaskRepository.java @@ -33,7 +33,7 @@ public class TaskRepository implements Repository { @Override public OTask findById(String id) { - try(Session session = SessionManager.getSessionFactory().openSession()) { + try (Session session = SessionManager.getSessionFactory().openSession()) { Query query = session.createQuery("SELECT o FROM OTask o WHERE o.taskId = :taskId", OTask.class); query.setParameter("taskId", id); diff --git a/src/main/java/me/bobert/netneutrality/db/service/BlacklistService.java b/src/main/java/me/bobert/netneutrality/db/service/BlacklistService.java index 2a07ac4..9d95f3b 100644 --- a/src/main/java/me/bobert/netneutrality/db/service/BlacklistService.java +++ b/src/main/java/me/bobert/netneutrality/db/service/BlacklistService.java @@ -44,9 +44,9 @@ public class BlacklistService { JpaUtils.getWithSession(oGuild, oGuild.getGuildId(), session -> { Set blacklistWords = oGuild.getBlacklists().stream() - .filter(OBlacklist::getEnabled) - .map(OBlacklist::getWord) - .collect(Collectors.toSet()); + .filter(OBlacklist::getEnabled) + .map(OBlacklist::getWord) + .collect(Collectors.toSet()); blacklistCache.put(oGuild.getGuildId(), blacklistWords); }); diff --git a/src/main/java/me/bobert/netneutrality/hooks/EventsHandler.java b/src/main/java/me/bobert/netneutrality/hooks/EventsHandler.java index 3f5b930..e749e54 100644 --- a/src/main/java/me/bobert/netneutrality/hooks/EventsHandler.java +++ b/src/main/java/me/bobert/netneutrality/hooks/EventsHandler.java @@ -53,8 +53,12 @@ public class EventsHandler implements EventListener { static { addListener(MessageReceivedEvent.class, event -> { - if (event.getAuthor().isBot()) return null; - if (event.isWebhookMessage()) return null; + if (event.getAuthor().isBot()) { + return null; + } + if (event.isWebhookMessage()) { + return null; + } Message message = event.getMessage(); String rawMessage = message.getContentDisplay().trim(); diff --git a/src/main/java/me/bobert/netneutrality/http/WebModule.java b/src/main/java/me/bobert/netneutrality/http/WebModule.java index 907d836..5723a67 100644 --- a/src/main/java/me/bobert/netneutrality/http/WebModule.java +++ b/src/main/java/me/bobert/netneutrality/http/WebModule.java @@ -10,14 +10,23 @@ import com.google.gson.Gson; import io.sentry.Breadcrumb; import io.sentry.Sentry; import me.bobert.netneutrality.utils.Settings; -import okhttp3.*; +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; import org.json.JSONArray; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Optional; import java.util.concurrent.TimeUnit; public class WebModule { @@ -28,12 +37,12 @@ public class WebModule { private static final String USER_AGENT = "Net Neutrality/%s (Discord bot, discord.gg/trAqhQ5Wsr)"; private static final Logger log = LoggerFactory.getLogger(WebModule.class); private static final Map cache = Collections.synchronizedMap( - new LinkedHashMap<>(100, 0.75f, true) { - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > 50; // Limit cache to 50 entries - } + new LinkedHashMap<>(100, 0.75f, true) { + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > 50; // Limit cache to 50 entries } + } ); private final Method method; @@ -95,12 +104,12 @@ public class WebModule { String body = response.body() != null ? response.body().string() : null; this.cachedResponse = new CachedResponse( - response.code(), - response.headers(), - elapsedTime, - body, - System.currentTimeMillis() + cacheExpirationMillis, - null + response.code(), + response.headers(), + elapsedTime, + body, + System.currentTimeMillis() + cacheExpirationMillis, + null ); } catch (IOException e) { long elapsedTime = System.currentTimeMillis() - startTime; @@ -108,12 +117,12 @@ public class WebModule { Sentry.captureException(e); this.cachedResponse = new CachedResponse( - 0, // Status code 0 indicates a failure - new Headers.Builder().build(), - elapsedTime, - null, - System.currentTimeMillis() + cacheExpirationMillis, - e.getMessage() + 0, // Status code 0 indicates a failure + new Headers.Builder().build(), + elapsedTime, + null, + System.currentTimeMillis() + cacheExpirationMillis, + e.getMessage() ); } @@ -132,22 +141,22 @@ public class WebModule { StringBuilder keyBuilder = new StringBuilder(method.name()).append(":").append(url); if (headers != null) { headers.entrySet().stream() - .sorted(Map.Entry.comparingByKey()) - .forEach(entry -> keyBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append(";")); + .sorted(Map.Entry.comparingByKey()) + .forEach(entry -> keyBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append(";")); } return keyBuilder.toString(); } public JSONObject getAsObject() { return cachedResponse.getBody() - .map(JSONObject::new) - .orElseThrow(() -> new IllegalStateException("No body available for this response")); + .map(JSONObject::new) + .orElseThrow(() -> new IllegalStateException("No body available for this response")); } public JSONArray getAsArray() { return cachedResponse.getBody() - .map(JSONArray::new) - .orElseThrow(() -> new IllegalStateException("No body available for this response")); + .map(JSONArray::new) + .orElseThrow(() -> new IllegalStateException("No body available for this response")); } public String getRawData() { @@ -303,10 +312,10 @@ public class WebModule { */ public WebModule build() { this.client = new OkHttpClient.Builder() - .connectTimeout(connectTimeout, TimeUnit.MILLISECONDS) - .writeTimeout(writeTimeout, TimeUnit.MILLISECONDS) - .readTimeout(readTimeout, TimeUnit.MILLISECONDS) - .build(); + .connectTimeout(connectTimeout, TimeUnit.MILLISECONDS) + .writeTimeout(writeTimeout, TimeUnit.MILLISECONDS) + .readTimeout(readTimeout, TimeUnit.MILLISECONDS) + .build(); this.request = createRequest(); return new WebModule(this); diff --git a/src/main/java/me/bobert/netneutrality/music/MusicManager.java b/src/main/java/me/bobert/netneutrality/music/MusicManager.java index 3a44a69..1af9447 100644 --- a/src/main/java/me/bobert/netneutrality/music/MusicManager.java +++ b/src/main/java/me/bobert/netneutrality/music/MusicManager.java @@ -204,8 +204,8 @@ public class MusicManager { } return CommandExecutionResult.success(String.format("Adding your vote to skip the current track. Current votes: %d/%d", - info.getSkips().size(), - (int) Math.ceil(needed)) + info.getSkips().size(), + (int) Math.ceil(needed)) ); } diff --git a/src/main/java/me/bobert/netneutrality/music/QueueManager.java b/src/main/java/me/bobert/netneutrality/music/QueueManager.java index acdd29c..daf8549 100644 --- a/src/main/java/me/bobert/netneutrality/music/QueueManager.java +++ b/src/main/java/me/bobert/netneutrality/music/QueueManager.java @@ -13,7 +13,10 @@ import net.dv8tion.jda.api.entities.Member; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Deque; +import java.util.List; import java.util.concurrent.LinkedBlockingDeque; import java.util.function.Predicate; diff --git a/src/main/java/me/bobert/netneutrality/music/SourceFinder.java b/src/main/java/me/bobert/netneutrality/music/SourceFinder.java index b42bc6f..9e70b27 100644 --- a/src/main/java/me/bobert/netneutrality/music/SourceFinder.java +++ b/src/main/java/me/bobert/netneutrality/music/SourceFinder.java @@ -37,23 +37,29 @@ public class SourceFinder { Matcher udioMatcher = udioPattern.matcher(url); Matcher mp3Matcher = mp3Pattern.matcher(url); - if (youtubeMatcher.find()) + if (youtubeMatcher.find()) { return AudioSourceType.Youtube; + } - if (youtubeMusicMatcher.find()) + if (youtubeMusicMatcher.find()) { return AudioSourceType.YTMusic; + } - if (soundcloudMatcher.find()) + if (soundcloudMatcher.find()) { return AudioSourceType.Soundcloud; + } - if (udioMatcher.find()) + if (udioMatcher.find()) { return AudioSourceType.Udio; + } - if (mp3Matcher.find()) + if (mp3Matcher.find()) { return AudioSourceType.DirectLinkMp3; + } - if (!(url.startsWith("http://") || url.startsWith("https://"))) + if (!(url.startsWith("http://") || url.startsWith("https://"))) { return AudioSourceType.YTSearch; + } return AudioSourceType.Nothing; } diff --git a/src/main/java/me/bobert/netneutrality/music/TrackInfo.java b/src/main/java/me/bobert/netneutrality/music/TrackInfo.java index b711421..11d1b3c 100644 --- a/src/main/java/me/bobert/netneutrality/music/TrackInfo.java +++ b/src/main/java/me/bobert/netneutrality/music/TrackInfo.java @@ -50,8 +50,12 @@ public class TrackInfo { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } TrackInfo trackInfo = (TrackInfo) o; return track.equals(trackInfo.track); } @@ -64,9 +68,9 @@ public class TrackInfo { @Override public String toString() { return "TrackInfo{" + - "track=" + track.getInfo().title + - ", member=" + member.getEffectiveName() + - ", skips=" + skips + - '}'; + "track=" + track.getInfo().title + + ", member=" + member.getEffectiveName() + + ", skips=" + skips + + '}'; } } diff --git a/src/main/java/me/bobert/netneutrality/music/TrackLoadingHandler.java b/src/main/java/me/bobert/netneutrality/music/TrackLoadingHandler.java index 2fe3ade..00ca26f 100644 --- a/src/main/java/me/bobert/netneutrality/music/TrackLoadingHandler.java +++ b/src/main/java/me/bobert/netneutrality/music/TrackLoadingHandler.java @@ -12,7 +12,6 @@ import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import me.bobert.netneutrality.core.LogHandler; import me.bobert.netneutrality.core.context.CommandContext; -import me.bobert.netneutrality.core.tasks.TaskManager; import me.bobert.netneutrality.tasks.music.LoadPlaylistTask; import me.bobert.netneutrality.utils.MessageFunction; import me.bobert.netneutrality.utils.MusicUtils; @@ -64,8 +63,9 @@ public class TrackLoadingHandler implements AudioLoadResultHandler { public void noMatches() { logger.debug("Guild {}: no matches for identifier {}", guild.getId(), identifier); - if (!silent) + if (!silent) { context.reply("No matches found"); + } } @Override @@ -76,7 +76,8 @@ public class TrackLoadingHandler implements AudioLoadResultHandler { RuntimeException exception = new RuntimeException("Failed to load track: " + e.getMessage(), e); LogHandler.log(exception); - if (!silent) + if (!silent) { context.reply(MessageFunction.buildSentryErrorMessage(exception)); + } } } diff --git a/src/main/java/me/bobert/netneutrality/music/source/UdioAudioSourceManager.java b/src/main/java/me/bobert/netneutrality/music/source/UdioAudioSourceManager.java index cd79651..50a1db3 100644 --- a/src/main/java/me/bobert/netneutrality/music/source/UdioAudioSourceManager.java +++ b/src/main/java/me/bobert/netneutrality/music/source/UdioAudioSourceManager.java @@ -35,13 +35,9 @@ import java.util.regex.Pattern; import static com.sedmelluq.discord.lavaplayer.tools.FriendlyException.Severity.SUSPICIOUS; public class UdioAudioSourceManager implements AudioSourceManager { - private static final Logger log = LogManager.getLogger(UdioAudioSourceManager.class); - - private static final String TRACK_URL_REGEX = "^https://www.udio.com/songs/[0-9A-Za-z]+$"; private static final Pattern trackUrlPattern = Pattern.compile(TRACK_URL_REGEX); - private final HttpInterfaceManager httpInterfaceManager; public UdioAudioSourceManager() { @@ -64,11 +60,8 @@ public class UdioAudioSourceManager implements AudioSourceManager { } catch (IOException e) { throw new FriendlyException("Loading Udio track information failed.", SUSPICIOUS, e); } - } - - @Override public boolean isTrackEncodable(AudioTrack track) { return true; @@ -94,7 +87,6 @@ public class UdioAudioSourceManager implements AudioSourceManager { } private AudioItem loadFromTrackPage(HttpInterface httpInterface, String trackUrl) throws IOException { - try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(trackUrl))) { int statusCode = response.getStatusLine().getStatusCode(); @@ -102,7 +94,7 @@ public class UdioAudioSourceManager implements AudioSourceManager { return AudioReference.NO_TRACK; } else if (!HttpClientTools.isSuccessWithContent(statusCode)) { throw new FriendlyException("Server responded with an error.", SUSPICIOUS, - new IllegalStateException("Response code is " + statusCode)); + new IllegalStateException("Response code is " + statusCode)); } return loadTrackFromPageContent(trackUrl, IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8)); @@ -124,7 +116,6 @@ public class UdioAudioSourceManager implements AudioSourceManager { String artworkUrl = getArtworkUrlFromImagePath(trackInfo); AudioTrackInfo audioTrackInfo = new AudioTrackInfo(title, artist, duration, trackUrl, false, playbackUrl, artworkUrl, null); - return new UdioAudioTrack(audioTrackInfo, this); } @@ -155,5 +146,4 @@ public class UdioAudioSourceManager implements AudioSourceManager { return imagePath.replace("public", artworkOptions); } - } diff --git a/src/main/java/me/bobert/netneutrality/music/source/UdioAudioTrack.java b/src/main/java/me/bobert/netneutrality/music/source/UdioAudioTrack.java index 7b90151..9662b80 100644 --- a/src/main/java/me/bobert/netneutrality/music/source/UdioAudioTrack.java +++ b/src/main/java/me/bobert/netneutrality/music/source/UdioAudioTrack.java @@ -71,7 +71,7 @@ public class UdioAudioTrack extends DelegatedAudioTrack { if (!HttpClientTools.isSuccessWithContent(statusCode)) { throw new FriendlyException("Server responded with an error.", SUSPICIOUS, - new IllegalStateException("Response code for player config is " + statusCode)); + new IllegalStateException("Response code for player config is " + statusCode)); } return sourceManager.loadTrackInfoFromPageContent(IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8)); diff --git a/src/main/java/me/bobert/netneutrality/tasks/generic/AcceptButton.java b/src/main/java/me/bobert/netneutrality/tasks/generic/AcceptButton.java index 30624e9..59a58e6 100644 --- a/src/main/java/me/bobert/netneutrality/tasks/generic/AcceptButton.java +++ b/src/main/java/me/bobert/netneutrality/tasks/generic/AcceptButton.java @@ -17,6 +17,7 @@ import java.util.function.Function; /** * A generic button task that represents a button to accept a choice. + * * @param

the type of the parent task, which must implement WithChildren */ public class AcceptButton

extends ButtonTask implements WithParent

, NotAcknowledgeable { diff --git a/src/main/java/me/bobert/netneutrality/tasks/git/ReportIssueTask.java b/src/main/java/me/bobert/netneutrality/tasks/git/ReportIssueTask.java index 8e9c0ad..a71551f 100644 --- a/src/main/java/me/bobert/netneutrality/tasks/git/ReportIssueTask.java +++ b/src/main/java/me/bobert/netneutrality/tasks/git/ReportIssueTask.java @@ -45,20 +45,20 @@ public class ReportIssueTask extends ModalTask { @Override public void replyToInteraction(CommandContext context) { TextInput title = TextInput.create("title", "Title", TextInputStyle.SHORT) - .setPlaceholder("Brief description of the issue.") - .setMinLength(10) - .setMaxLength(100) - .build(); + .setPlaceholder("Brief description of the issue.") + .setMinLength(10) + .setMaxLength(100) + .build(); TextInput body = TextInput.create("description", "Description", TextInputStyle.PARAGRAPH) - .setPlaceholder("And I scream from the top of my lungs What's going on?") - .setMinLength(30) - .setMaxLength(1000) - .build(); + .setPlaceholder("And I scream from the top of my lungs What's going on?") + .setMinLength(30) + .setMaxLength(1000) + .build(); Modal modal = Modal.create(getId(), "Report a bug") - .addComponents(ActionRow.of(title), ActionRow.of(body)) - .build(); + .addComponents(ActionRow.of(title), ActionRow.of(body)) + .build(); context.reply(modal); } diff --git a/src/main/java/me/bobert/netneutrality/tasks/help/BotInfo.java b/src/main/java/me/bobert/netneutrality/tasks/help/BotInfo.java index 014b908..8c02b71 100644 --- a/src/main/java/me/bobert/netneutrality/tasks/help/BotInfo.java +++ b/src/main/java/me/bobert/netneutrality/tasks/help/BotInfo.java @@ -24,6 +24,6 @@ public class BotInfo extends AbstractBuiltInTask { @Override public void executeTask(TaskContext context) { context.sendMessageInPrivate("For information about the bot and to follow the development, " + - "you can join the discord here: https://discord.gg/udVJwTgV"); + "you can join the discord here: https://discord.gg/udVJwTgV"); } } diff --git a/src/main/java/me/bobert/netneutrality/tasks/help/ReportBug.java b/src/main/java/me/bobert/netneutrality/tasks/help/ReportBug.java index 7555581..70ec080 100644 --- a/src/main/java/me/bobert/netneutrality/tasks/help/ReportBug.java +++ b/src/main/java/me/bobert/netneutrality/tasks/help/ReportBug.java @@ -24,6 +24,6 @@ public class ReportBug extends AbstractBuiltInTask { @Override public void executeTask(TaskContext context) { context.sendMessageInPrivate("To report a bug with the bot, you can either use the /report-bug command " + - "or join the discord here: https://discord.gg/udVJwTgV"); + "or join the discord here: https://discord.gg/udVJwTgV"); } } diff --git a/src/main/java/me/bobert/netneutrality/tasks/music/LoadPlaylistTask.java b/src/main/java/me/bobert/netneutrality/tasks/music/LoadPlaylistTask.java index b31eb16..18d4df3 100644 --- a/src/main/java/me/bobert/netneutrality/tasks/music/LoadPlaylistTask.java +++ b/src/main/java/me/bobert/netneutrality/tasks/music/LoadPlaylistTask.java @@ -58,8 +58,8 @@ public class LoadPlaylistTask extends ButtonTask implements WithChildren, Deleta int searchResultsLimit = 5; // Max number of buttons per row int maxPlaylistSizeBeforeAsking = Integer.parseInt(GuildService.get(context.getGuild()) - .getGuildSettingService() - .getSetting(GSettings.MUSIC_MAXPLAYLISTSIZE)); + .getGuildSettingService() + .getSetting(GSettings.MUSIC_MAXPLAYLISTSIZE)); // Search results if (playlist.isSearchResult()) { @@ -115,8 +115,8 @@ public class LoadPlaylistTask extends ButtonTask implements WithChildren, Deleta addChild(accept, cancel); return ActionRow.of( - accept.createButton().withEmoji(Emoji.fromFormatted("U+1F60E")), - cancel.createButton().withEmoji(Emoji.fromFormatted("U+1F92E")) + accept.createButton().withEmoji(Emoji.fromFormatted("U+1F60E")), + cancel.createButton().withEmoji(Emoji.fromFormatted("U+1F92E")) ); } diff --git a/src/main/java/me/bobert/netneutrality/tasks/reaction/EmojiRoleFirstStep.java b/src/main/java/me/bobert/netneutrality/tasks/reaction/EmojiRoleFirstStep.java index 65c3213..83aeaa8 100644 --- a/src/main/java/me/bobert/netneutrality/tasks/reaction/EmojiRoleFirstStep.java +++ b/src/main/java/me/bobert/netneutrality/tasks/reaction/EmojiRoleFirstStep.java @@ -30,8 +30,8 @@ public class EmojiRoleFirstStep extends StepTask { @Override public String getStepDescription() { return String.format("Creating a new emoji role mapping in guild %s for message %s", - getGuild().getId(), - target.getJumpUrl()); + getGuild().getId(), + target.getJumpUrl()); } @Override diff --git a/src/main/java/me/bobert/netneutrality/tasks/reaction/EmojiRoleSecondStep.java b/src/main/java/me/bobert/netneutrality/tasks/reaction/EmojiRoleSecondStep.java index 4371d13..92c3a60 100644 --- a/src/main/java/me/bobert/netneutrality/tasks/reaction/EmojiRoleSecondStep.java +++ b/src/main/java/me/bobert/netneutrality/tasks/reaction/EmojiRoleSecondStep.java @@ -32,9 +32,9 @@ public class EmojiRoleSecondStep extends StepTask { @Override public String getStepDescription() { return String.format("Creating a new emoji role mapping in guild %s for message %s and role %s", - getGuild().getId(), - target.getJumpUrl(), - role.getName()); + getGuild().getId(), + target.getJumpUrl(), + role.getName()); } @Override @@ -46,9 +46,9 @@ public class EmojiRoleSecondStep extends StepTask { public StepResult executeStep(Object answer) { String emoji = (String) answer; Task emojiTask = new EmojiReactionRoleTask(target.getGuildId(), - target.getChannelId(), - target.getId(), - Map.of(emoji, role.getId())); + target.getChannelId(), + target.getId(), + Map.of(emoji, role.getId())); if (TaskManager.getInstance().hasTask(emojiTask.getId())) { return StepResult.failure("The message ID is already registered with the bot, please use the modify mapping command instead"); diff --git a/src/main/java/me/bobert/netneutrality/thread/CleanupTaskThread.java b/src/main/java/me/bobert/netneutrality/thread/CleanupTaskThread.java index 35931ca..6022b37 100644 --- a/src/main/java/me/bobert/netneutrality/thread/CleanupTaskThread.java +++ b/src/main/java/me/bobert/netneutrality/thread/CleanupTaskThread.java @@ -21,11 +21,11 @@ public class CleanupTaskThread implements Runnable { TaskManager manager = TaskManager.getInstance(); List expiredTasks = manager.getTasks() - .stream() - .filter(task -> !(task instanceof PersistableTask)) - .filter(task -> !(task instanceof BuiltInTask)) - .filter(Task::isExpired) - .toList(); + .stream() + .filter(task -> !(task instanceof PersistableTask)) + .filter(task -> !(task instanceof BuiltInTask)) + .filter(Task::isExpired) + .toList(); if (!expiredTasks.isEmpty()) { logger.info("Cleaning up {} expired tasks..", expiredTasks.size()); diff --git a/src/main/java/me/bobert/netneutrality/utils/ChannelMessagePurger.java b/src/main/java/me/bobert/netneutrality/utils/ChannelMessagePurger.java index bf9f955..90e5d84 100644 --- a/src/main/java/me/bobert/netneutrality/utils/ChannelMessagePurger.java +++ b/src/main/java/me/bobert/netneutrality/utils/ChannelMessagePurger.java @@ -40,8 +40,9 @@ public class ChannelMessagePurger { public boolean canLockBeAcquired() { boolean acquired = lock.tryLock(); - if (acquired) + if (acquired) { lock.unlock(); + } return acquired; } @@ -126,9 +127,9 @@ public class ChannelMessagePurger { } MessageCreateBuilder builder = new MessageCreateBuilder() - .addContent("Finished purging ") - .addContent(String.valueOf(toPurge)) - .addContent(" messages."); + .addContent("Finished purging ") + .addContent(String.valueOf(toPurge)) + .addContent(" messages."); if (olderThan2Weeks) { builder.addContent("\n").addContent("Messages older than two weeks weren't deleted."); diff --git a/src/main/java/me/bobert/netneutrality/utils/ContextUtils.java b/src/main/java/me/bobert/netneutrality/utils/ContextUtils.java index 059b6fe..995cc33 100644 --- a/src/main/java/me/bobert/netneutrality/utils/ContextUtils.java +++ b/src/main/java/me/bobert/netneutrality/utils/ContextUtils.java @@ -58,8 +58,8 @@ public class ContextUtils { private static int findLastBoundary(String chunk) { // Find the last sentence-ending punctuation or space within the chunk int lastSentenceBoundary = Math.max( - Math.max(chunk.lastIndexOf("."), Math.max(chunk.lastIndexOf("!"), chunk.lastIndexOf("?"))), - chunk.lastIndexOf("\n") + Math.max(chunk.lastIndexOf("."), Math.max(chunk.lastIndexOf("!"), chunk.lastIndexOf("?"))), + chunk.lastIndexOf("\n") ); int lastSpace = chunk.lastIndexOf(" "); return Math.max(lastSentenceBoundary, lastSpace); diff --git a/src/main/java/me/bobert/netneutrality/utils/JpaUtils.java b/src/main/java/me/bobert/netneutrality/utils/JpaUtils.java index b6b33fa..7f55a3b 100644 --- a/src/main/java/me/bobert/netneutrality/utils/JpaUtils.java +++ b/src/main/java/me/bobert/netneutrality/utils/JpaUtils.java @@ -32,8 +32,8 @@ public class JpaUtils { *

* * @param session The session in which to load the persistent object - * @param object The persistent object - * @param id Identifier + * @param object The persistent object + * @param id Identifier */ public static void tryLoad(Session session, Object object, Serializable id) { try { @@ -57,13 +57,13 @@ public class JpaUtils { } public static void runWithSession(Consumer consumer) { - try(Session session = SessionManager.getSessionFactory().openSession()) { + try (Session session = SessionManager.getSessionFactory().openSession()) { consumer.accept(session); } } public static void runWithTransaction(Consumer consumer) { - try(Session session = SessionManager.getSessionFactory().openSession()) { + try (Session session = SessionManager.getSessionFactory().openSession()) { session.beginTransaction(); consumer.accept(session); session.getTransaction().commit(); @@ -71,7 +71,7 @@ public class JpaUtils { } public static void updateWithTransaction(Object persistantEntity, Runnable runnable) { - try(Session session = SessionManager.getSessionFactory().openSession()) { + try (Session session = SessionManager.getSessionFactory().openSession()) { Transaction transaction = session.beginTransaction(); try { @@ -94,11 +94,11 @@ public class JpaUtils { * This will load all Lazy relationships defined in the entity. * * @param persistantEntity The entity to load - * @param id The identifier for the entity - * @param consumer The comsumer, which exposes the session + * @param id The identifier for the entity + * @param consumer The comsumer, which exposes the session */ public static void getWithSession(Object persistantEntity, Serializable id, Consumer consumer) { - try(Session session = SessionManager.getSessionFactory().openSession()) { + try (Session session = SessionManager.getSessionFactory().openSession()) { tryLoad(session, persistantEntity, id); consumer.accept(session); } diff --git a/src/main/java/me/bobert/netneutrality/utils/MessageFunction.java b/src/main/java/me/bobert/netneutrality/utils/MessageFunction.java index 7a3a7dd..b6c894c 100644 --- a/src/main/java/me/bobert/netneutrality/utils/MessageFunction.java +++ b/src/main/java/me/bobert/netneutrality/utils/MessageFunction.java @@ -29,10 +29,11 @@ import org.apache.commons.lang3.time.DurationFormatUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.awt.*; +import java.awt.Color; import java.time.OffsetDateTime; +import java.util.HashMap; import java.util.List; -import java.util.*; +import java.util.Map; public class MessageFunction { @@ -119,11 +120,11 @@ public class MessageFunction { StringBuilder message = new StringBuilder(); message.append("Here is the current queue of the bot ") - .append("(showing ") - .append(numberofTracksShown) - .append(" out of ") - .append(tracks.size()) - .append(" items):\n"); + .append("(showing ") + .append(numberofTracksShown) + .append(" out of ") + .append(tracks.size()) + .append(" items):\n"); int index = 0; for (AudioTrack track : tracks) { @@ -137,7 +138,9 @@ public class MessageFunction { message.append("- ").append(info.title); } - if (index == limit) break; + if (index == limit) { + break; + } } return message.toString(); @@ -162,7 +165,9 @@ public class MessageFunction { message.addField("Track #" + ++index, info.title, false); } - if (index == 10) break; + if (index == 10) { + break; + } } message.setTimestamp(OffsetDateTime.now()); @@ -233,9 +238,9 @@ public class MessageFunction { } String subtext = "\n\n" + - "-# The bot supports both types of commands: slash (/) and message ($), " + - "however not all slash commands might have a corresponding message command.\n" + - "-# To get help for a specific command, please use /help "; + "-# The bot supports both types of commands: slash (/) and message ($), " + + "however not all slash commands might have a corresponding message command.\n" + + "-# To get help for a specific command, please use /help "; return String.join("\n", help.values()) + subtext; } diff --git a/src/main/java/me/bobert/netneutrality/utils/Settings.java b/src/main/java/me/bobert/netneutrality/utils/Settings.java index 2a9415b..fce7c92 100644 --- a/src/main/java/me/bobert/netneutrality/utils/Settings.java +++ b/src/main/java/me/bobert/netneutrality/utils/Settings.java @@ -71,8 +71,9 @@ public class Settings { public String get(String key, String def) { String property = get(key); - if (property == null || property.isEmpty()) + if (property == null || property.isEmpty()) { return def; + } return property; } @@ -91,7 +92,8 @@ public class Settings { p.load(is); version = p.getProperty("app.version", ""); } - } catch (Exception ignored) {} + } catch (Exception ignored) { + } if (version == null) { version = "0.0.0"; diff --git a/src/main/java/me/bobert/netneutrality/utils/UserFunction.java b/src/main/java/me/bobert/netneutrality/utils/UserFunction.java index 1f99800..530112f 100644 --- a/src/main/java/me/bobert/netneutrality/utils/UserFunction.java +++ b/src/main/java/me/bobert/netneutrality/utils/UserFunction.java @@ -14,22 +14,23 @@ import net.dv8tion.jda.api.entities.Role; public class UserFunction { - public static boolean isAdmin(Context context) { - if (context instanceof SlashCommandContext) { - return true; - } + public static boolean isAdmin(Context context) { + if (context instanceof SlashCommandContext) { + return true; + } - return isAdmin(context.getGuildUser()); - } + return isAdmin(context.getGuildUser()); + } - public static boolean isAdmin(Member user) { - boolean isAdmin = false; - for(Role role : user.getRoles()) { - if (role.getPermissions().contains(Permission.MANAGE_SERVER) || role.getPermissions().contains(Permission.ADMINISTRATOR)) - isAdmin = true; - } - - return isAdmin; - } + public static boolean isAdmin(Member user) { + boolean isAdmin = false; + for (Role role : user.getRoles()) { + if (role.getPermissions().contains(Permission.MANAGE_SERVER) || role.getPermissions().contains(Permission.ADMINISTRATOR)) { + isAdmin = true; + } + } + + return isAdmin; + } }