/** * Registers an executor. * * @param executor The executor to register. */ public void registerCommand(CommandExecutor executor) { for (Method method : executor.getClass().getMethods()) { Command annotation = method.getAnnotation(Command.class); if (annotation == null) { continue; } if (annotation.aliases().length == 0) { throw new IllegalArgumentException("Aliases array cannot be empty!"); } SimpleCommand command = new SimpleCommand(annotation, method, executor); for (String alias : annotation.aliases()) { // add command to map. It's faster to access it from the map than iterating to the whole list commands.put(defaultPrefix + alias.toLowerCase().replace(" ", ""), command); } // we need a list, too, because a HashMap is not ordered. commandList.add(command); } }
if (command == null || !command.getCommandAnnotation().requiresMention()) { return; if (commandAnnotation.requiresMention()) { Matcher matcher = USER_MENTION.matcher(commandString); if (!matcher.find() || !matcher.group("id").equals(api.getYourself().getIdAsString())) { if (message.getPrivateChannel().isPresent() && !commandAnnotation.privateMessages()) { return; if (!message.getPrivateChannel().isPresent() && !commandAnnotation.channelMessages()) { return; if (!hasPermission(message.getUserAuthor().map(User::getId).map(String::valueOf).orElse("-1"), commandAnnotation.requiredPermissions())) { if (Sdcf4jMessage.MISSING_PERMISSIONS.getMessage() != null) { message.getChannel().sendMessage(Sdcf4jMessage.MISSING_PERMISSIONS.getMessage()); if (commandAnnotation.async()) { final SimpleCommand commandFinal = command; api.getThreadPool().getExecutorService().submit(() -> invokeMethod(commandFinal, message, parameters));
if (command == null || !command.getCommandAnnotation().requiresMention()) { return; if (commandAnnotation.requiresMention()) { Matcher matcher = USER_MENTION.matcher(commandString); if (!matcher.find() || !matcher.group("id").equals(jda.getSelfUser().getId())) { if (event.isFromType(ChannelType.PRIVATE) && !commandAnnotation.privateMessages()) { return; if (!event.isFromType(ChannelType.PRIVATE) && !commandAnnotation.channelMessages()) { return; if (!hasPermission(event.getAuthor(), commandAnnotation.requiredPermissions())) { if (Sdcf4jMessage.MISSING_PERMISSIONS.getMessage() != null) { event.getChannel().sendMessage(Sdcf4jMessage.MISSING_PERMISSIONS.getMessage()).queue(); if (commandAnnotation.async()) { final SimpleCommand commandFinal = command; Thread t = new Thread(() -> invokeMethod(commandFinal, event, parameters));
if (command == null || !command.getCommandAnnotation().requiresMention()) { return; if (commandAnnotation.requiresMention()) { Matcher matcher = USER_MENTION.matcher(commandString); if (!matcher.find() || !matcher.group("id").equals(event.getClient().getOurUser().getStringID())) { if (event.getMessage().getChannel().isPrivate() && !commandAnnotation.privateMessages()) { return; if (!event.getMessage().getChannel().isPrivate() && !commandAnnotation.channelMessages()) { return; if (!hasPermission(event.getMessage().getAuthor(), commandAnnotation.requiredPermissions())) { if (Sdcf4jMessage.MISSING_PERMISSIONS.getMessage() != null) { try { if (commandAnnotation.async()) { final SimpleCommand commandFinal = command; Thread t = new Thread(() -> {