♻️ Reformat + Update .editorconfig

This commit is contained in:
Alexander Söderberg 2020-10-06 22:48:30 +02:00 committed by Alexander Söderberg
parent 8bdec87a74
commit 2aac3980d5
169 changed files with 4261 additions and 2448 deletions

View file

@ -75,51 +75,58 @@ public class JDACommandListener<C> extends ListenerAdapter {
content = content.substring(prefix.length());
commandManager.executeCommand(sender, content)
.whenComplete((commandResult, throwable) -> {
if (throwable == null) {
return;
}
.whenComplete((commandResult, throwable) -> {
if (throwable == null) {
return;
}
if (throwable instanceof InvalidSyntaxException) {
this.commandManager.handleException(sender,
InvalidSyntaxException.class,
(InvalidSyntaxException) throwable, (c, e) -> {
this.sendMessage(event,
MESSAGE_INVALID_SYNTAX + prefix + ((InvalidSyntaxException) throwable)
.getCorrectSyntax());
});
} else if (throwable instanceof InvalidCommandSenderException) {
this.commandManager.handleException(sender,
InvalidCommandSenderException.class,
(InvalidCommandSenderException) throwable, (c, e) ->
this.sendMessage(event, throwable.getMessage())
);
} else if (throwable instanceof NoPermissionException) {
this.commandManager.handleException(sender,
NoPermissionException.class,
(NoPermissionException) throwable, (c, e) ->
this.sendMessage(event, MESSAGE_NO_PERMS)
);
} else if (throwable instanceof NoSuchCommandException) {
this.commandManager.handleException(sender,
NoSuchCommandException.class,
(NoSuchCommandException) throwable, (c, e) ->
this.sendMessage(event, MESSAGE_UNKNOWN_COMMAND)
);
} else if (throwable instanceof ArgumentParseException) {
this.commandManager.handleException(sender, ArgumentParseException.class,
(ArgumentParseException) throwable, (c, e) -> {
this.sendMessage(event,
"Invalid Command Argument: " + throwable.getCause()
.getMessage());
});
} else {
this.sendMessage(event, throwable.getMessage());
}
});
if (throwable instanceof InvalidSyntaxException) {
this.commandManager.handleException(sender,
InvalidSyntaxException.class,
(InvalidSyntaxException) throwable, (c, e) -> {
this.sendMessage(
event,
MESSAGE_INVALID_SYNTAX + prefix + ((InvalidSyntaxException) throwable)
.getCorrectSyntax()
);
}
);
} else if (throwable instanceof InvalidCommandSenderException) {
this.commandManager.handleException(sender,
InvalidCommandSenderException.class,
(InvalidCommandSenderException) throwable, (c, e) ->
this.sendMessage(event, throwable.getMessage())
);
} else if (throwable instanceof NoPermissionException) {
this.commandManager.handleException(sender,
NoPermissionException.class,
(NoPermissionException) throwable, (c, e) ->
this.sendMessage(event, MESSAGE_NO_PERMS)
);
} else if (throwable instanceof NoSuchCommandException) {
this.commandManager.handleException(sender,
NoSuchCommandException.class,
(NoSuchCommandException) throwable, (c, e) ->
this.sendMessage(event, MESSAGE_UNKNOWN_COMMAND)
);
} else if (throwable instanceof ArgumentParseException) {
this.commandManager.handleException(sender, ArgumentParseException.class,
(ArgumentParseException) throwable, (c, e) -> {
this.sendMessage(
event,
"Invalid Command Argument: " + throwable.getCause()
.getMessage()
);
}
);
} else {
this.sendMessage(event, throwable.getMessage());
}
});
}
private void sendMessage(final @NonNull MessageReceivedEvent event, final @NonNull String message) {
event.getChannel().sendMessage(message).queue();
}
}

View file

@ -45,6 +45,7 @@ import java.util.function.Function;
* @param <C> Command sender type
*/
public class JDACommandManager<C> extends CommandManager<C> {
private final long botId;
private final Function<@NonNull C, @NonNull String> prefixMapper;
@ -63,12 +64,14 @@ public class JDACommandManager<C> extends CommandManager<C> {
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link MessageReceivedEvent}
* @throws InterruptedException If the jda instance does not ready correctly
*/
public JDACommandManager(final @NonNull JDA jda,
final @NonNull Function<@NonNull C, @NonNull String> prefixMapper,
final @Nullable BiFunction<@NonNull C, @NonNull String, @NonNull Boolean> permissionMapper,
final @NonNull Function<CommandTree<C>, CommandExecutionCoordinator<C>> commandExecutionCoordinator,
final @NonNull Function<@NonNull MessageReceivedEvent, @NonNull C> commandSenderMapper,
final @NonNull Function<@NonNull C, @NonNull MessageReceivedEvent> backwardsCommandSenderMapper)
public JDACommandManager(
final @NonNull JDA jda,
final @NonNull Function<@NonNull C, @NonNull String> prefixMapper,
final @Nullable BiFunction<@NonNull C, @NonNull String, @NonNull Boolean> permissionMapper,
final @NonNull Function<CommandTree<C>, CommandExecutionCoordinator<C>> commandExecutionCoordinator,
final @NonNull Function<@NonNull MessageReceivedEvent, @NonNull C> commandSenderMapper,
final @NonNull Function<@NonNull C, @NonNull MessageReceivedEvent> backwardsCommandSenderMapper
)
throws InterruptedException {
super(commandExecutionCoordinator, CommandRegistrationHandler.nullCommandRegistrationHandler());
this.prefixMapper = prefixMapper;
@ -130,4 +133,5 @@ public class JDACommandManager<C> extends CommandManager<C> {
public final @NonNull CommandMeta createDefaultCommandMeta() {
return SimpleCommandMeta.empty();
}
}

View file

@ -31,6 +31,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
* Wrapper for {@link MessageReceivedEvent}
*/
public class JDACommandSender {
private final MessageReceivedEvent event;
/**
@ -42,15 +43,6 @@ public class JDACommandSender {
this.event = event;
}
/**
* Get the {@link MessageReceivedEvent}
*
* @return Message Received Event
*/
public @NonNull MessageReceivedEvent getEvent() {
return event;
}
/**
* Create a JDA Command Sender from a {@link MessageReceivedEvent}
*
@ -64,4 +56,14 @@ public class JDACommandSender {
return new JDAGuildSender(event);
}
/**
* Get the {@link MessageReceivedEvent}
*
* @return Message Received Event
*/
public @NonNull MessageReceivedEvent getEvent() {
return event;
}
}

View file

@ -34,4 +34,5 @@ public class JDAGuildSender extends JDACommandSender {
JDAGuildSender(final @NonNull MessageReceivedEvent event) {
super(event);
}
}

View file

@ -34,4 +34,5 @@ public class JDAPrivateSender extends JDACommandSender {
JDAPrivateSender(final @NonNull MessageReceivedEvent event) {
super(event);
}
}

View file

@ -43,10 +43,13 @@ import java.util.Queue;
*/
@SuppressWarnings("unused")
public final class UserArgument<C> extends CommandArgument<C, User> {
private final List<ParserMode> modes;
private UserArgument(final boolean required, final @NonNull String name,
final @NonNull JDA jda, final @NonNull List<ParserMode> modes) {
private UserArgument(
final boolean required, final @NonNull String name,
final @NonNull JDA jda, final @NonNull List<ParserMode> modes
) {
super(required, name, new UserParser<>(jda, modes), User.class);
this.modes = modes;
}
@ -105,6 +108,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
public static final class Builder<C> extends CommandArgument.Builder<C, User> {
private final JDA jda;
private List<ParserMode> modes = new ArrayList<>();
@ -138,6 +142,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
public static final class UserParser<C> implements ArgumentParser<C, User> {
private final JDA jda;
private final List<ParserMode> modes;
@ -149,7 +154,8 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
@Override
public @NonNull ArgumentParseResult<User> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
final @NonNull Queue<@NonNull String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
@ -218,6 +224,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
return ArgumentParseResult.success(user);
}
}
}
@ -242,10 +249,12 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
public final @NonNull String getInput() {
return input;
}
}
public static final class TooManyUsersFoundParseException extends UserParseException {
/**
* Construct a new UUID parse exception
*
@ -259,10 +268,12 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
public @NonNull String getMessage() {
return String.format("Too many users found for '%s'.", getInput());
}
}
public static final class UserNotFoundParseException extends UserParseException {
/**
* Construct a new UUID parse exception
*
@ -276,5 +287,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
public @NonNull String getMessage() {
return String.format("User not found for '%s'.", getInput());
}
}
}