Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.togetherjava.tjbot.config;


/**
* Config for automatic pruning of helper roles, see
* {@link org.togetherjava.tjbot.features.help.AutoPruneHelperRoutine}.
Expand All @@ -15,5 +14,4 @@
* protected from pruning
*/
public record HelperPruneConfig(int roleFullLimit, int roleFullThreshold, int pruneMemberAmount,
int inactivateAfterDays, int recentlyJoinedDays) {
}
int inactivateAfterDays, int recentlyJoinedDays) {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.togetherjava.tjbot.config;


import org.togetherjava.tjbot.features.utils.RateLimiter;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public interface Routine extends Feature {
* @param unit the time unit for both, {@link #initialDuration} and {@link #duration}, e.g.
* seconds
*/
record Schedule(ScheduleMode mode, long initialDuration, long duration, TimeUnit unit) {
}
record Schedule(ScheduleMode mode, long initialDuration, long duration, TimeUnit unit) {}

/**
* Whether subsequent executions of a routine are executed at a fixed rate or are delayed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public interface UserInteractor extends Feature {
*/
String getName();


/**
* Gets the type of interactors this interactor allows.
* <p>
Expand Down Expand Up @@ -78,7 +77,6 @@ public interface UserInteractor extends Feature {
*/
void onSelectMenuSelection(SelectMenuInteractionEvent event, List<String> args);


/**
* Triggered by the core system when a modal corresponding to this implementation (based on
* {@link #getName()}) has been clicked.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ private static void reactWith(String emojiName, Emoji fallbackEmoji, Guild guild
"Unable to vote on a suggestion with the configured emoji ('{}'), using fallback instead.",
emojiName);
return message.addReaction(fallbackEmoji);
}).queue(ignored -> {
}, exception -> {
}).queue(ignored -> {}, exception -> {
if (exception instanceof ErrorResponseException responseException
&& responseException.getErrorResponse() == ErrorResponse.REACTION_BLOCKED) {
// User blocked the bot, hence the bot can not add reactions to their messages.
Expand Down
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 @@ -140,7 +140,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 Expand Up @@ -293,8 +294,7 @@ private enum RequestType {
REMOVE
}

private record PageEntry(int bookmarkNumber, BookmarksRecord bookmark) {
}
private record PageEntry(int bookmarkNumber, BookmarksRecord bookmark) {}

private record Request(RequestType type, String componentName, int pageToDisplayIndex,
Set<Long> bookmarkIdsToRemove) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ public void onMessageUpdated(MessageUpdateEvent event) {

// Re-apply the current action
return codeReplyMessage.editMessageEmbeds(maybeCodeAction.orElseThrow().apply(code));
}).queue(any -> {
}, failure -> logger.warn(
"Attempted to update a code-reply-message ({}), but failed. The original code-message was {}",
codeReplyMessageId, originalMessageId, failure));
})
.queue(any -> {}, failure -> logger.warn(
"Attempted to update a code-reply-message ({}), but failed. The original code-message was {}",
codeReplyMessageId, originalMessageId, failure));
}

private Optional<CodeAction> getCurrentActionFromCodeReply(Message codeReplyMessage) {
Expand All @@ -259,10 +259,11 @@ public void onMessageDeleted(MessageDeleteEvent event) {
// Delete the code reply as well
originalMessageToCodeReply.invalidate(originalMessageId);

event.getChannel().deleteMessageById(codeReplyMessageId).queue(any -> {
}, failure -> logger.warn(
"Attempted to delete a code-reply-message ({}), but failed. The original code-message was {}",
codeReplyMessageId, originalMessageId, failure));
event.getChannel()
.deleteMessageById(codeReplyMessageId)
.queue(any -> {}, failure -> logger.warn(
"Attempted to delete a code-reply-message ({}), but failed. The original code-message was {}",
codeReplyMessageId, originalMessageId, failure));
}

private static CodeFence extractCodeOrFallback(String content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
* this component ID, when triggered
* @param elements the additional elements to carry along this component ID, empty if not desired
*/
public record ComponentId(String userInteractorName, List<String> elements) {
}
public record ComponentId(String userInteractorName, List<String> elements) {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public final class InvalidComponentIdFormatException extends RuntimeException {
/**
* Creates a new instance.
*/
public InvalidComponentIdFormatException() {}
public InvalidComponentIdFormatException() {
}

/**
* Creates a new instance with a given cause.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ private void handleArchiveFlow(ThreadChannel threadChannel, MessageEmbed embed)
.retrieveMemberById(threadChannel.getOwnerIdLong())
.flatMap(author -> threadChannel.sendMessage(author.getAsMention()).addEmbeds(embed))
.flatMap(any -> threadChannel.getManager().setArchived(true))
.queue(any -> {
}, handleFailure);
.queue(any -> {}, handleFailure);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,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 @@ -68,16 +68,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 @@ -90,8 +90,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 @@ -6,5 +6,4 @@
* @param exceptionClass the class of the exception
* @param exceptionMessage the message of the exception
*/
public record JShellExceptionResult(String exceptionClass, String exceptionMessage) {
}
public record JShellExceptionResult(String exceptionClass, String exceptionMessage) {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
* @param id the session of the id
* @param result the JShell eval result
*/
public record JShellResultWithId(String id, JShellResult result) {
}
public record JShellResultWithId(String id, JShellResult result) {}
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ private String buildTitle() {
return query + " - " + SERVICE_NAME;
}

record HandlerResponse(List<MessageEmbed> embeds, List<Attachment> attachments) {
}
record HandlerResponse(List<MessageEmbed> embeds, List<Attachment> attachments) {}

record Attachment(String name, byte[] data) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ static BufferedImage renderSubPod(SubPod subPod) throws IOException, URISyntaxEx
graphics.drawImage(ImageIO.read(new URI(sourceImage.getSource()).toURL()), IMAGE_MARGIN_PX,
IMAGE_MARGIN_PX, null);


return destinationImage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public void onMessageReceived(MessageReceivedEvent event) {
}

if (messageHasNoMediaAttached(message)) {
message.delete().flatMap(any -> dmUser(message)).queue(any -> {
}, failure -> tempNotifyUserInChannel(message));
message.delete()
.flatMap(any -> dmUser(message))
.queue(any -> {}, failure -> tempNotifyUserInChannel(message));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public BanCommand(ModerationActionsStore actionsStore) {
.addOption(OptionType.STRING, REASON_OPTION, "Why the user should be banned", true)
.addOptions(new OptionData(OptionType.INTEGER, DELETE_HISTORY_OPTION,
"the amount of days of the message history to delete, none means no messages are deleted.",
true).addChoice("none", 0).addChoice("recent", 1).addChoice("all", 7));
true)
.addChoice("none", 0)
.addChoice("recent", 1)
.addChoice("all", 7));

this.actionsStore = Objects.requireNonNull(actionsStore);
}
Expand Down Expand Up @@ -133,7 +136,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 @@ -208,8 +212,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 @@ -437,6 +437,5 @@ static RestAction<Boolean> sendModActionDm(RestAction<EmbedBuilder> embedBuilder
* @param duration a human-readable text representing the duration of the temporary action, such
* as {@code "1 day"}.
*/
record TemporaryData(Instant expiresAt, String duration) {
}
record TemporaryData(Instant expiresAt, String duration) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,5 @@ private static void applyModerationRole(ModerationRole moderationRole, Member me
}

private record ModerationRole(String actionName, ModerationAction applyAction,
ModerationAction revokeAction, Function<Guild, Role> guildToRole) {
}
ModerationAction revokeAction, Function<Guild, Role> guildToRole) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public final class TransferQuestionCommand extends BotCommandAdapter
private final Predicate<String> isHelpForumName;
private final List<String> tags;


/**
* Creates a new instance.
*
Expand Down Expand Up @@ -165,7 +164,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 Expand Up @@ -282,8 +282,7 @@ private MessageEmbed makeEmbedForPost(User originalUser, String originalMessage)
.build();
}

private record ForumPostData(ForumPost forumPost, User author) {
}
private record ForumPostData(ForumPost forumPost, User author) {}

private boolean isBotMessageTransfer(User author) {
return author.isBot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ private static ReplyCallbackAction handleWhoIsUser(final IReplyCallback event, f
+ DATE_TIME_FORMAT.format(user.getTimeCreated());

EmbedBuilder embedBuilder =
generateEmbedBuilder(event, user, profile, profile.getAccentColor()).setAuthor(
user.getName(), user.getEffectiveAvatarUrl(), user.getEffectiveAvatarUrl())
generateEmbedBuilder(event, user, profile, profile.getAccentColor())
.setAuthor(user.getName(), user.getEffectiveAvatarUrl(),
user.getEffectiveAvatarUrl())
.setDescription(description);

return sendEmbedWithProfileAction(event, embedBuilder.build(), user.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,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 @@ -272,6 +273,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();
}
}
Loading