Skip to content

Commit

Permalink
Fix: Bump spotless to 21 and remove pinned eclipse jdt formatter vers…
Browse files Browse the repository at this point in the history
…ion. Resolves #605 (#1105)
  • Loading branch information
thrashy authored May 22, 2024
1 parent 9ff5cb8 commit 9cf8944
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public BookmarksCommand(BookmarksSystem bookmarksSystem) {

OptionData addNoteOption = new OptionData(OptionType.STRING, ADD_BOOKMARK_NOTE_OPTION,
"Your personal comment on this bookmark")
.setMaxLength(BookmarksSystem.MAX_NOTE_LENGTH)
.setRequired(false);
.setMaxLength(BookmarksSystem.MAX_NOTE_LENGTH)
.setRequired(false);

SubcommandData addSubCommand = new SubcommandData(SUBCOMMAND_ADD,
"Bookmark this help thread, so that you can easily look it up again")
.addOptions(addNoteOption);
.addOptions(addNoteOption);

SubcommandData listSubCommand =
new SubcommandData(SUBCOMMAND_LIST, "List all of your bookmarks");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ void onButtonClick(ButtonInteractionEvent event, List<String> args) {
removeSelectedBookmarks(bookmarks, event, request);
yield clampPageIndex(bookmarks, request.pageToDisplayIndex);
}
default -> throw new IllegalArgumentException("Unknown button: " + request.componentName);
default ->
throw new IllegalArgumentException("Unknown button: " + request.componentName);
};

updatePagination(event, request.atPage(nextPageIndex), bookmarks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public HelpThreadCommand(Config config, HelpSystemHelper helper) {
Subcommand.CHANGE_TITLE.toSubcommandData().addOptions(changeTitleOption);

SubcommandGroupData changeCommands = new SubcommandGroupData(CHANGE_SUBCOMMAND_GROUP,
"Change the details of this help thread").addSubcommands(changeCategory,
changeTitle);
"Change the details of this help thread")
.addSubcommands(changeCategory, changeTitle);
getData().addSubcommandGroups(changeCommands);

getData().addSubcommands(Subcommand.CLOSE.toSubcommandData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ public JShellCommand(JShellEval jshellEval) {
new SubcommandData(VERSION_SUBCOMMAND, "Get the version of JShell"),
new SubcommandData(EVAL_SUBCOMMAND,
"Evaluate java code in JShell, submit the command without code for inputting longer, multi-line code.")
.addOption(OptionType.STRING, CODE_PARAMETER,
"Code to evaluate. Leave empty to input longer, multi-line code.")
.addOption(OptionType.BOOLEAN, STARTUP_SCRIPT_PARAMETER,
"If the startup script should be loaded, true by default."),
.addOption(OptionType.STRING, CODE_PARAMETER,
"Code to evaluate. Leave empty to input longer, multi-line code.")
.addOption(OptionType.BOOLEAN, STARTUP_SCRIPT_PARAMETER,
"If the startup script should be loaded, true by default."),
new SubcommandData(SNIPPETS_SUBCOMMAND,
"Display your snippets, or the snippets of the specified user if any.")
.addOption(OptionType.USER, USER_PARAMETER,
"User to get the snippets from. If null, get your snippets.")
.addOption(OptionType.BOOLEAN, INCLUDE_STARTUP_SCRIPT_PARAMETER,
"if the startup script should be included, false by default."),
.addOption(OptionType.USER, USER_PARAMETER,
"User to get the snippets from. If null, get your snippets.")
.addOption(OptionType.BOOLEAN, INCLUDE_STARTUP_SCRIPT_PARAMETER,
"if the startup script should be included, false by default."),
new SubcommandData(CLOSE_SUBCOMMAND, "Close your session."),
new SubcommandData(STARTUP_SCRIPT_SUBCOMMAND, "Display the startup script."));
}
Expand All @@ -92,8 +92,8 @@ public void onSlashCommand(SlashCommandInteractionEvent event) {
case SNIPPETS_SUBCOMMAND -> handleSnippetsCommand(event);
case CLOSE_SUBCOMMAND -> handleCloseCommand(event);
case STARTUP_SCRIPT_SUBCOMMAND -> handleStartupScriptCommand(event);
default -> throw new AssertionError(
"Unexpected Subcommand: " + event.getSubcommandName());
default ->
throw new AssertionError("Unexpected Subcommand: " + event.getSubcommandName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public JShellResult evalOnce(String code, boolean startupScript)
baseUrl + "single-eval"
+ (startupScript ? "?startupScriptId=" + STARTUP_SCRIPT_ID : ""),
HttpRequest.newBuilder().POST(BodyPublishers.ofString(code)),
ResponseUtils.ofJson(JShellResult.class, objectMapper)).body();
ResponseUtils.ofJson(JShellResult.class, objectMapper))
.body();
}

/**
Expand All @@ -98,7 +99,8 @@ public JShellResult evalSession(String code, String sessionId, boolean startupSc
baseUrl + "eval/" + sessionId
+ (startupScript ? "?startupScriptId=" + STARTUP_SCRIPT_ID : ""),
HttpRequest.newBuilder().POST(BodyPublishers.ofString(code)),
ResponseUtils.ofJson(JShellResult.class, objectMapper)).body();
ResponseUtils.ofJson(JShellResult.class, objectMapper))
.body();
}

/**
Expand All @@ -116,7 +118,8 @@ public SnippetList snippetsSession(String sessionId, boolean includeStartupScrip
return send(
baseUrl + "snippets/" + sessionId + "?includeStartupScript=" + includeStartupScript,
HttpRequest.newBuilder().GET(),
ResponseUtils.ofJson(SnippetList.class, objectMapper)).body();
ResponseUtils.ofJson(SnippetList.class, objectMapper))
.body();
}

/**
Expand Down Expand Up @@ -144,7 +147,8 @@ public void closeSession(String sessionId)
*/
public String startupScript() throws RequestFailedException, ConnectionFailedException {
return send(baseUrl + "startup_script/" + STARTUP_SCRIPT_ID, HttpRequest.newBuilder().GET(),
BodyHandlers.ofString()).body();
BodyHandlers.ofString())
.body();
}

private <T> HttpResponse<T> send(String url, HttpRequest.Builder builder, BodyHandler<T> body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ record TimeoutAbortionCause() implements JShellEvalAbortionCause {
* @param exceptionMessage the message of the exception
*/
@JsonTypeName("UNCAUGHT_EXCEPTION")
record UnhandledExceptionAbortionCause(String exceptionClass, String exceptionMessage) implements JShellEvalAbortionCause {
record UnhandledExceptionAbortionCause(String exceptionClass,
String exceptionMessage) implements JShellEvalAbortionCause {
}

/**
* The code doesn't compile, but at least the syntax is correct.
*
* @param errors the compilation errors
*/
@JsonTypeName("COMPILE_TIME_ERROR")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ private RendererUtils() {}
static String abortionCauseToString(JShellEvalAbortionCause abortionCause) {
return switch (abortionCause) {
case JShellEvalAbortionCause.TimeoutAbortionCause ignored -> "Allowed time exceeded.";
case JShellEvalAbortionCause.UnhandledExceptionAbortionCause c -> "Uncaught exception:\n" + c.exceptionClass() + ":" + c.exceptionMessage();
case JShellEvalAbortionCause.CompileTimeErrorAbortionCause c -> "The code doesn't compile:\n" + String.join("\n", c.errors());
case JShellEvalAbortionCause.SyntaxErrorAbortionCause ignored -> "The code doesn't compile, there are syntax errors in this code.";
case JShellEvalAbortionCause.UnhandledExceptionAbortionCause c ->
"Uncaught exception:\n" + c.exceptionClass() + ":" + c.exceptionMessage();
case JShellEvalAbortionCause.CompileTimeErrorAbortionCause c ->
"The code doesn't compile:\n" + String.join("\n", c.errors());
case JShellEvalAbortionCause.SyntaxErrorAbortionCause ignored ->
"The code doesn't compile, there are syntax errors in this code.";
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public BanCommand(ModerationActionsStore actionsStore) {
.addOptions(durationData)
.addOption(OptionType.STRING, REASON_OPTION, "Why the user should be banned", true)
.addOptions(new OptionData(OptionType.INTEGER, DELETE_HISTORY_OPTION,
"the message history to delete", true).addChoice("none", 0)
.addChoice("day", 1)
.addChoice("week", 7));
"the message history to delete", true)
.addChoice("none", 0)
.addChoice("day", 1)
.addChoice("week", 7));

this.actionsStore = Objects.requireNonNull(actionsStore);
}
Expand Down Expand Up @@ -138,7 +139,8 @@ private RestAction<Message> banUserFlow(User target, Member author,
int deleteHistoryDays, Guild guild, SlashCommandInteractionEvent event) {
return sendDm(target, temporaryData, reason, guild)
.flatMap(hasSentDm -> banUser(target, author, temporaryData, reason, deleteHistoryDays,
guild).map(banResult -> hasSentDm))
guild)
.map(banResult -> hasSentDm))
.map(hasSentDm -> sendFeedback(hasSentDm, target, author, temporaryData, reason))
.flatMap(event.getHook()::sendMessageEmbeds);
}
Expand Down Expand Up @@ -213,8 +215,8 @@ public void onSlashCommand(SlashCommandInteractionEvent event) {

return handleNotAlreadyBannedResponse(
Objects.requireNonNull(alreadyBanned.getFailure()), hook, guild, target)
.orElseGet(() -> banUserFlow(target, author, temporaryData.orElse(null),
reason, deleteHistoryDays, guild, event));
.orElseGet(() -> banUserFlow(target, author, temporaryData.orElse(null), reason,
deleteHistoryDays, guild, event));
}).queue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ private void transferFlow(ModalInteractionEvent event, String channelId, String
.retrieveUserById(authorId)
.flatMap(fetchedUser -> createForumPost(event, fetchedUser))
.flatMap(createdForumPost -> dmUser(event.getChannel(), createdForumPost,
event.getGuild()).and(sendMessageToTransferrer.apply(createdForumPost)))
event.getGuild())
.and(sendMessageToTransferrer.apply(createdForumPost)))
.flatMap(dmSent -> deleteOriginalMessage(event.getJDA(), channelId, messageId))
.queue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ public void onSlashCommand(SlashCommandInteractionEvent event) {
}

auditUser(MessageCreateBuilder::new, guild.getIdLong(), target.getIdLong(),
event.getMember().getIdLong(), -1, event.getJDA()).map(MessageCreateBuilder::build)
.flatMap(event::reply)
.queue();
event.getMember().getIdLong(), -1, event.getJDA())
.map(MessageCreateBuilder::build)
.flatMap(event::reply)
.queue();
}

private boolean handleChecks(Member bot, Member author, @Nullable Member target,
Expand Down Expand Up @@ -276,6 +277,9 @@ public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
int pageToDisplay = currentPage + turnPageBy;

auditUser(MessageEditBuilder::new, guildId, targetId, buttonUserId, pageToDisplay,
event.getJDA()).map(MessageEditBuilder::build).flatMap(event::editMessage).queue();
event.getJDA())
.map(MessageEditBuilder::build)
.flatMap(event::editMessage)
.queue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ private void takeAction(MessageReceivedEvent event) {
"The OFF-mode should be detected earlier already to prevent expensive computation");
case ONLY_LOG -> takeActionLogOnly(event);
case APPROVE_FIRST -> takeActionApproveFirst(event);
case AUTO_DELETE_BUT_APPROVE_QUARANTINE -> takeActionAutoDeleteButApproveQuarantine(
event);
case AUTO_DELETE_BUT_APPROVE_QUARANTINE ->
takeActionAutoDeleteButApproveQuarantine(event);
case AUTO_DELETE_AND_QUARANTINE -> takeActionAutoDeleteAndQuarantine(event);
default -> throw new IllegalArgumentException("Mode not supported: " + mode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public FailureIdentification handleRevokeFailure(Throwable failure, long targetI
case UNKNOWN_ROLE -> logger.warn(
"Attempted to revoke a temporary {} but the {} role can not be found.",
actionName, actionName);
case MISSING_PERMISSIONS -> logger.warn(
"Attempted to revoke a temporary {} but the bot lacks permission.",
actionName);
case MISSING_PERMISSIONS ->
logger.warn("Attempted to revoke a temporary {} but the bot lacks permission.",
actionName);
default -> {
return FailureIdentification.UNKNOWN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ReminderCommand(Database database) {
// "/remind at" next to "/remind in" and use subcommands then
OptionData timeAmount = new OptionData(OptionType.INTEGER, TIME_AMOUNT_OPTION,
"period to remind you in, the amount of time (e.g. [5] weeks)", true)
.setRequiredRange(MIN_TIME_AMOUNT, MAX_TIME_AMOUNT);
.setRequiredRange(MIN_TIME_AMOUNT, MAX_TIME_AMOUNT);
OptionData timeUnit = new OptionData(OptionType.STRING, TIME_UNIT_OPTION,
"period to remind you in, the unit of time (e.g. 5 [weeks])", true);
TIME_UNITS.forEach(unit -> timeUnit.addChoice(unit, unit));
Expand All @@ -118,8 +118,8 @@ public void onSlashCommand(SlashCommandInteractionEvent event) {
case CREATE_SUBCOMMAND -> handleCreateCommand(event);
case CANCEL_COMMAND -> handleCancelCommand(event);
case LIST_SUBCOMMAND -> handleListCommand(event);
default -> throw new AssertionError(
"Unexpected Subcommand: " + event.getSubcommandName());
default ->
throw new AssertionError("Unexpected Subcommand: " + event.getSubcommandName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
event.getGuild());
COMMAND_SERVICE.execute(
() -> requireUserInteractor(UserInteractionType.SLASH_COMMAND.getPrefixedName(name),
SlashCommand.class).onSlashCommand(event));
SlashCommand.class)
.onSlashCommand(event));
}

@Override
Expand All @@ -267,7 +268,8 @@ public void onCommandAutoCompleteInteraction(final CommandAutoCompleteInteractio
event.getFullCommandName(), event.getId(), event.getGuild());
COMMAND_SERVICE.execute(
() -> requireUserInteractor(UserInteractionType.SLASH_COMMAND.getPrefixedName(name),
SlashCommand.class).onAutoComplete(event));
SlashCommand.class)
.onAutoComplete(event));
}

@Override
Expand Down Expand Up @@ -324,7 +326,8 @@ public void onMessageContextInteraction(final MessageContextInteractionEvent eve
event.getId(), event.getGuild());
COMMAND_SERVICE.execute(() -> requireUserInteractor(
UserInteractionType.MESSAGE_CONTEXT_COMMAND.getPrefixedName(name),
MessageContextCommand.class).onMessageContext(event));
MessageContextCommand.class)
.onMessageContext(event));
}

@Override
Expand All @@ -335,7 +338,8 @@ public void onUserContextInteraction(final UserContextInteractionEvent event) {
event.getGuild());
COMMAND_SERVICE.execute(() -> requireUserInteractor(
UserInteractionType.USER_CONTEXT_COMMAND.getPrefixedName(name),
UserContextCommand.class).onUserContext(event));
UserContextCommand.class)
.onUserContext(event));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,21 @@ public TagManageCommand(TagSystem tagSystem, ModAuditLogWriter modAuditLogWriter
// 'delete'
getData().addSubcommands(new SubcommandData(Subcommand.RAW.name,
"View the raw content of a tag, without Discord interpreting any of its content")
.addOption(OptionType.STRING, ID_OPTION, ID_DESCRIPTION, true),
.addOption(OptionType.STRING, ID_OPTION, ID_DESCRIPTION, true),
new SubcommandData(Subcommand.CREATE.name, "Creates a new tag")
.addOption(OptionType.STRING, ID_OPTION, ID_DESCRIPTION, true)
.addOption(OptionType.STRING, CONTENT_OPTION, CONTENT_DESCRIPTION, true),
new SubcommandData(Subcommand.CREATE_WITH_MESSAGE.name,
"Creates a new tag. Content is retrieved from the given message.")
.addOption(OptionType.STRING, ID_OPTION, ID_DESCRIPTION, true)
.addOption(OptionType.STRING, MESSAGE_ID_OPTION, MESSAGE_ID_DESCRIPTION,
true),
.addOption(OptionType.STRING, ID_OPTION, ID_DESCRIPTION, true)
.addOption(OptionType.STRING, MESSAGE_ID_OPTION, MESSAGE_ID_DESCRIPTION, true),
new SubcommandData(Subcommand.EDIT.name, "Edits a tag, the old content is replaced")
.addOption(OptionType.STRING, ID_OPTION, ID_DESCRIPTION, true)
.addOption(OptionType.STRING, CONTENT_OPTION, CONTENT_DESCRIPTION, true),
new SubcommandData(Subcommand.EDIT_WITH_MESSAGE.name,
"Edits a tag, the old content is replaced. Content is retrieved from the given message.")
.addOption(OptionType.STRING, ID_OPTION, ID_DESCRIPTION, true)
.addOption(OptionType.STRING, MESSAGE_ID_OPTION, MESSAGE_ID_DESCRIPTION,
true),
.addOption(OptionType.STRING, ID_OPTION, ID_DESCRIPTION, true)
.addOption(OptionType.STRING, MESSAGE_ID_OPTION, MESSAGE_ID_DESCRIPTION, true),
new SubcommandData(Subcommand.DELETE.name, "Deletes a tag")
.addOption(OptionType.STRING, ID_OPTION, ID_DESCRIPTION, true));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class RateLimiter {
* Creates a rate limiter.
* <p>
* Defines a window and a number of request, for example, if 10 requests should be allowed per 5
* seconds, so 10/5s, the following should be called: {@snippet java: new
* RateLimit(Duration.of(5, TimeUnit.SECONDS), 10) }
* seconds, so 10/5s, the following should be called:
* {@snippet java: new RateLimit(Duration.of(5, TimeUnit.SECONDS), 10) }
*
* @param duration the duration of window
* @param allowedRequests the number of requests to allow in the window
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private TextChannel createAndSetupUnknownChannel() {
TextChannel channel = jdaTester.createTextChannelSpy(unknownChannelId);
when(jdaTester.getJdaMock()
.getChannelById(ArgumentMatchers.<Class<MessageChannel>>any(), eq(unknownChannelId)))
.thenReturn(null);
.thenReturn(null);

return channel;
}
Expand Down
Loading

0 comments on commit 9cf8944

Please sign in to comment.