use of net.anweisen.utilities.jda.manager.hooks.event.CommandEvent in project Utility by anweisen.
the class DefaultCommandManager method handleCommand00.
protected Object handleCommand00(@Nonnull CommandPreProcessInfo info, @Nonnull Callback callback, @Nonnull String prefix, @Nonnull String content) {
String lower = content.toLowerCase();
List<RegisteredCommand> matchingName = new ArrayList<>();
Optional<Tuple<String, RegisteredCommand>> optional = findCommand(lower, matchingName);
if (!optional.isPresent()) {
if (matchingName.isEmpty()) {
return callback.call(CommandProcessResult.UNKNOWN_COMMAND, prefix, content);
} else if (matchingName.size() == 1) {
RegisteredCommand matchingCommand = matchingName.get(0);
doCommonChecks(matchingCommand, callback, prefix, matchingCommand.getOptions().getFirstName(), info);
return callback.call(new CommandResultInfo(CommandProcessResult.INCORRECT_ARGUMENTS, matchingName, matchingCommand.getOptions().getFirstName(), prefix));
} else {
return callback.call(new CommandResultInfo(CommandProcessResult.INCORRECT_ARGUMENTS, matchingName, null, prefix));
}
}
Tuple<String, RegisteredCommand> pair = optional.get();
String commandName = pair.getFirst();
RegisteredCommand command = pair.getSecond();
if (doCommonChecks(command, callback, prefix, commandName, info) == CALLBACK_RESULT)
return CALLBACK_RESULT;
if (command.getCoolDown().isOnCoolDown(info.getUser(), info.isFromGuild() ? info.getMember().getGuild() : null))
return callback.call(new CommandResultInfo(CommandProcessResult.COOLDOWN, command, commandName, prefix, command.getCoolDown().getCoolDown(info.getUser(), info.isFromGuild() ? info.getMember().getGuild() : null)));
command.getCoolDown().renewCoolDown(info.getUser(), info.isFromGuild() ? info.getMember().getGuild() : null);
String stripped = content.substring(commandName.length()).trim();
CommandEvent event = eventCreator.createEvent(this, info, command, useEmbeds);
if (command.getOptions().getAutoSendTyping() && info.getMessage() != null)
info.getChannel().sendTyping().queue();
ArgumentParseResult parsed = parseArguments(command, stripped, event);
if (parsed.success == null)
return callback.call(new CommandResultInfo(CommandProcessResult.INCORRECT_ARGUMENTS, command, commandName, prefix, parsed.failure));
CommandArguments args = new CommandArgumentsImpl(parsed.success.getFirst(), parsed.success.getSecond());
if (command.getOptions().isAsync()) {
executor.submit(() -> execute0(command, callback, event, args, prefix, commandName));
} else {
execute0(command, callback, event, args, prefix, commandName);
}
return null;
}
Aggregations