Cleanup annotations and remove Cloud Brigs Pair (#32)

This commit is contained in:
Josh Taylor 2020-10-06 11:40:35 +01:00 committed by GitHub
parent c3469706ab
commit f1d4529276
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 93 additions and 117 deletions

View file

@ -58,14 +58,14 @@ public class JDACommandListener<C> extends ListenerAdapter {
@Override
public final void onMessageReceived(final @NonNull MessageReceivedEvent event) {
Message message = event.getMessage();
C sender = commandManager.getCommandSenderMapper().apply(event);
final Message message = event.getMessage();
final C sender = this.commandManager.getCommandSenderMapper().apply(event);
if (commandManager.getBotId() == event.getAuthor().getIdLong()) {
if (this.commandManager.getBotId() == event.getAuthor().getIdLong()) {
return;
}
String prefix = commandManager.getPrefixMapper().apply(sender);
final String prefix = this.commandManager.getPrefixMapper().apply(sender);
String content = message.getContentRaw();
if (!content.startsWith(prefix)) {
@ -81,40 +81,40 @@ public class JDACommandListener<C> extends ListenerAdapter {
}
if (throwable instanceof InvalidSyntaxException) {
commandManager.handleException(sender,
InvalidSyntaxException.class,
(InvalidSyntaxException) throwable, (c, e) -> {
sendMessage(event,
MESSAGE_INVALID_SYNTAX + prefix + ((InvalidSyntaxException) throwable)
.getCorrectSyntax());
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) {
commandManager.handleException(sender,
InvalidCommandSenderException.class,
(InvalidCommandSenderException) throwable, (c, e) ->
sendMessage(event, throwable.getMessage())
this.commandManager.handleException(sender,
InvalidCommandSenderException.class,
(InvalidCommandSenderException) throwable, (c, e) ->
this.sendMessage(event, throwable.getMessage())
);
} else if (throwable instanceof NoPermissionException) {
commandManager.handleException(sender,
NoPermissionException.class,
(NoPermissionException) throwable, (c, e) ->
sendMessage(event, MESSAGE_NO_PERMS)
this.commandManager.handleException(sender,
NoPermissionException.class,
(NoPermissionException) throwable, (c, e) ->
this.sendMessage(event, MESSAGE_NO_PERMS)
);
} else if (throwable instanceof NoSuchCommandException) {
commandManager.handleException(sender,
NoSuchCommandException.class,
(NoSuchCommandException) throwable, (c, e) ->
sendMessage(event, MESSAGE_UNKNOWN_COMMAND)
this.commandManager.handleException(sender,
NoSuchCommandException.class,
(NoSuchCommandException) throwable, (c, e) ->
this.sendMessage(event, MESSAGE_UNKNOWN_COMMAND)
);
} else if (throwable instanceof ArgumentParseException) {
commandManager.handleException(sender, ArgumentParseException.class,
(ArgumentParseException) throwable, (c, e) -> {
sendMessage(event,
"Invalid Command Argument: " + throwable.getCause()
.getMessage());
this.commandManager.handleException(sender, ArgumentParseException.class,
(ArgumentParseException) throwable, (c, e) -> {
this.sendMessage(event,
"Invalid Command Argument: " + throwable.getCause()
.getMessage());
});
} else {
sendMessage(event, throwable.getMessage());
this.sendMessage(event, throwable.getMessage());
}
});
}

View file

@ -53,7 +53,6 @@ public class JDACommandManager<C> extends CommandManager<C> {
private final Function<@NonNull C, @NonNull MessageReceivedEvent> backwardsCommandSenderMapper;
/**
* final
* Construct a new JDA Command Manager
*
* @param jda JDA instance to register against
@ -86,7 +85,7 @@ public class JDACommandManager<C> extends CommandManager<C> {
*
* @return Prefix mapper
*/
public final @NonNull Function<C, String> getPrefixMapper() {
public final @NonNull Function<@NonNull C, @NonNull String> getPrefixMapper() {
return this.prefixMapper;
}

View file

@ -87,13 +87,6 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
return UserArgument.<C>newBuilder(name, jda).asOptional().build();
}
public enum ParserMode {
MENTION,
ID,
NAME
}
/**
* Get the modes enabled on the parser
*
@ -103,6 +96,14 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
return modes;
}
public enum ParserMode {
MENTION,
ID,
NAME
}
public static final class Builder<C> extends CommandArgument.Builder<C, User> {
private final JDA jda;
private List<ParserMode> modes = new ArrayList<>();
@ -158,7 +159,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
if (modes.contains(ParserMode.MENTION)) {
if (input.endsWith(">")) {
String id;
final String id;
if (input.startsWith("<@!")) {
id = input.substring(3, input.length() - 1);
} else {
@ -166,10 +167,10 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
}
try {
final ArgumentParseResult<User> result = userFromId(input, id);
final ArgumentParseResult<User> result = this.userFromId(input, id);
inputQueue.remove();
return result;
} catch (UserNotFoundParseException | NumberFormatException e) {
} catch (final UserNotFoundParseException | NumberFormatException e) {
exception = e;
}
}
@ -177,16 +178,16 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
if (modes.contains(ParserMode.ID)) {
try {
final ArgumentParseResult<User> result = userFromId(input, input);
final ArgumentParseResult<User> result = this.userFromId(input, input);
inputQueue.remove();
return result;
} catch (UserNotFoundParseException | NumberFormatException e) {
} catch (final UserNotFoundParseException | NumberFormatException e) {
exception = e;
}
}
if (modes.contains(ParserMode.NAME)) {
List<User> users = jda.getUsersByName(input, true);
final List<User> users = jda.getUsersByName(input, true);
if (users.size() == 0) {
exception = new UserNotFoundParseException(input);
@ -209,7 +210,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
private @NonNull ArgumentParseResult<User> userFromId(final @NonNull String input, final @NonNull String id)
throws UserNotFoundParseException, NumberFormatException {
User user = jda.getUserById(id);
final User user = jda.getUserById(id);
if (user == null) {
throw new UserNotFoundParseException(input);