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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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 @@ -220,10 +220,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 @@ -249,10 +249,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 @@ -230,8 +230,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 @@ -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 @@ -434,6 +434,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 @@ -36,7 +36,6 @@
import java.util.function.Predicate;
import java.util.regex.Pattern;


/**
* Implements the /modmail command, which allows users to contact a moderator within the server
* which forwards messages to moderators in a dedicated channel given by
Expand All @@ -57,7 +56,6 @@ public final class ModMailCommand extends SlashCommandAdapter {
private final Predicate<String> configModGroupPattern;
private final String configModMailChannelPattern;


/**
* Creates a new instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,11 @@ private void dmUser(MessageReceivedEvent event) {
}

private void dmUser(Guild guild, long userId, JDA jda) {
jda.openPrivateChannelById(userId).flatMap(channel -> dmUser(guild, channel)).queue(any -> {
}, failure -> logger.debug(
"Unable to send dm message to user {} in guild {} to inform them about a scam message being blocked",
userId, guild.getId(), failure));
jda.openPrivateChannelById(userId)
.flatMap(channel -> dmUser(guild, channel))
.queue(any -> {}, failure -> logger.debug(
"Unable to send dm message to user {} in guild {} to inform them about a scam message being blocked",
userId, guild.getId(), failure));
}

private RestAction<Message> dmUser(Guild guild, PrivateChannel channel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ private void revokeAction(RevocationGroupIdentifier groupIdentifier) {

jda.retrieveUserById(groupIdentifier.targetId)
.flatMap(target -> executeRevocation(guild, target, groupIdentifier.type))
.queue(result -> {
}, failure -> handleFailure(failure, groupIdentifier));
.queue(result -> {}, failure -> handleFailure(failure, groupIdentifier));
}

private RestAction<Void> executeRevocation(Guild guild, User target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ private static MessageEmbed createReminderEmbed(CharSequence content,
}

private static <T> Consumer<T> doNothing() {
return a -> {
};
return a -> {};
}

private record ReminderRoute(MessageChannel channel, @Nullable User target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public BotCore(JDA jda, Database database, Config config) {
.getPrefixedName(userInteractor.getName()),
Function.identity()));


// Component Id Store
componentIdStore = new ComponentIdStore(database);
componentIdStore.addComponentIdRemovedListener(BotCore::onComponentIdRemoved);
Expand Down Expand Up @@ -410,7 +409,6 @@ private <T extends UserInteractor> T requireUserInteractor(String prefixedName,
return typeToken.cast(userInteractor);
}


@SuppressWarnings("EmptyMethod")
private static void onComponentIdRemoved(ComponentId componentId) {
// NOTE As of now, we do not act on this event, but we could use it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,9 @@ private static String dataTableToAsciiTable(Collection<List<String>> dataTable,
return AsciiTable.getTable(AsciiTable.BASIC_ASCII_NO_DATA_SEPARATORS, dataTable, columns);
}

private record TimeRange(Instant start, Instant end, String description) {
}
private record TimeRange(Instant start, Instant end, String description) {}

private record TopHelperResult(long authorId, BigDecimal messageLengths) {
}
private record TopHelperResult(long authorId, BigDecimal messageLengths) {}

private record ColumnSetting(String headerName, HorizontalAlign alignment) {
}
private record ColumnSetting(String headerName, HorizontalAlign alignment) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ private static CompletableFuture<Optional<HttpContent>> readLinkContent(String l
});
}

private record HttpContent(String type, InputStream dataStream) {
}
private record HttpContent(String type, InputStream dataStream) {}

private static CompletableFuture<Optional<LinkPreview>> parseWebsite(String link,
String attachmentName, InputStream websiteContent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ final class DiscordLogForwarder {
SERVICE.scheduleWithFixedDelay(this::processPendingLogs, 5, 5, TimeUnit.SECONDS);
}


/**
* Forwards the given log message to Discord.
* <p>
Expand Down Expand Up @@ -157,8 +156,8 @@ private List<LogMessage> validateBatch(List<LogMessage> logBatch) {
return new ArrayList<>(logBatch);
}

private record LogMessage(WebhookEmbed embed,
Instant timestamp) implements Comparable<LogMessage> {
private record LogMessage(WebhookEmbed embed, Instant timestamp)
implements Comparable<LogMessage> {

private static LogMessage ofEvent(LogEvent event) {
String authorName = event.getLoggerName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ void ignoresWrongChannels() {
assertTrue(ignoresWrongParentNames, "Failed to ignore wrong parent channel names");
}


MessageReceivedEvent createMessageReceivedEvent(boolean isBot, boolean isWebhook,
boolean isThread, String parentChannelName) {
try (MessageCreateData message = new MessageCreateBuilder().setContent("Any").build()) {
Expand All @@ -116,7 +115,6 @@ MessageReceivedEvent createMessageReceivedEvent(boolean isBot, boolean isWebhook
}
}


@ParameterizedTest
@MethodSource("provideInvalidCharactersWithDescription")
void excludesInvalidCharacters(String invalidChars, String description) {
Expand All @@ -130,7 +128,6 @@ void excludesInvalidCharacters(String invalidChars, String description) {
"Characters [%s] were not fully ignored".formatted(description));
}


@ParameterizedTest
@MethodSource("provideValidCharacters")
void countsValidCharacters(String validChars) {
Expand All @@ -144,7 +141,6 @@ void countsValidCharacters(String validChars) {
"Characters [%s] were not fully ignored".formatted(validChars));
}


private static Stream<Arguments> provideInvalidCharactersWithDescription() {
return Stream.of( // Invalid characters
Arguments.of("\u061C", "Arabic Letter Mark"),
Expand All @@ -157,7 +153,6 @@ private static Stream<Arguments> provideInvalidCharactersWithDescription() {
Arguments.of("\u200F", "Right-to-Left Mark"));
}


private static List<String> provideValidCharacters() {
return List.of( // Valid characters
"a", "A", "b", "B", "c", "C", "x", "X,", "y", "Y", "z", "Z", // Latin alphabet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ void escapeMarkdown() {
}
}

private record TestCaseEscape(String testName, String escapedMessage, String originalMessage) {
}
private record TestCaseEscape(String testName, String escapedMessage, String originalMessage) {}

@Test
void abbreviate() {
Expand All @@ -192,8 +191,7 @@ void abbreviate() {
}

private record TestCaseAbbreviate(String testName, String abbreviatedMessage,
String originalMessage, int limit) {
}
String originalMessage, int limit) {}

private static List<Arguments> provideExtractCodeTests() {
List<Arguments> tests = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ final class StringDistancesTest {
@Test
void closeMatches() {
record TestCase(String name, Collection<String> expectedSuggestions, String prefix,
Collection<String> candidates, int limit) {
}
Collection<String> candidates, int limit) {}

List<String> candidates = List.of("c", "c#", "c++", "emacs", "foo", "hello", "java", "js",
"key", "nvim", "py", "tag", "taz", "vi", "vim");
Expand All @@ -38,8 +37,7 @@ record TestCase(String name, Collection<String> expectedSuggestions, String pref

@Test
void editDistance() {
record TestCase(String name, int expectedDistance, String source, String destination) {
}
record TestCase(String name, int expectedDistance, String source, String destination) {}
List<TestCase> tests = List.of(new TestCase("identity", 0, "-", "-"),
new TestCase("empty_identity", 0, "", ""), new TestCase("empty_remove", 1, "a", ""),
new TestCase("empty_add", 1, "", "a"), new TestCase("basic", 4, "bloed", "doof"),
Expand All @@ -57,8 +55,7 @@ record TestCase(String name, int expectedDistance, String source, String destina

@Test
void prefixEditDistance() {
record TestCase(String name, int expectedDistance, String source, String destination) {
}
record TestCase(String name, int expectedDistance, String source, String destination) {}
List<TestCase> tests = List.of(new TestCase("identity", 0, "-", "-"),
new TestCase("empty_identity", 0, "", ""), new TestCase("empty_remove", 1, "a", ""),
new TestCase("empty_add", 0, "", "a"), new TestCase("basic", 4, "bloed", "doof"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,5 @@ private SubcommandData requireSubcommand(String name) {
});
}

private record Option<T> (String name, T value, OptionType type) {
}
private record Option<T> (String name, T value, OptionType type) {}
}
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ subprojects {
// empty string '' covers all imports that aren't explicitly specified,
// we use it as catch-all for external dependencies like JDA
// '\\#` is prefix for static imports
importOrder('','org.togetherjava', 'javax', 'java', '\\#')
// TODO Use latest eclipse jdt formatter, issue tracking this: https://github.com/Together-Java/TJ-Bot/issues/605
eclipse('4.19.0').configFile("${rootProject.rootDir}/meta/formatting/google-style-eclipse.xml")
importOrder('', 'org.togetherjava', 'javax', 'java', '\\#')
eclipse().configFile("${rootProject.rootDir}/meta/formatting/google-style-eclipse.xml")
}
}

Expand Down
Loading