當前位置: 首頁>>代碼示例>>Java>>正文


Java Command.async方法代碼示例

本文整理匯總了Java中de.btobastian.sdcf4j.Command.async方法的典型用法代碼示例。如果您正苦於以下問題:Java Command.async方法的具體用法?Java Command.async怎麽用?Java Command.async使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在de.btobastian.sdcf4j.Command的用法示例。


在下文中一共展示了Command.async方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleMessageCreate

import de.btobastian.sdcf4j.Command; //導入方法依賴的package包/類
/**
 * Handles a received message.
 *
 * @param api The api.
 * @param message The received message.
 */
private void handleMessageCreate(DiscordApi api, final Message message) {
    if (message.getUserAuthor().map(User::isYourself).orElse(false)) {
        return;
    }
    String[] splitMessage = message.getContent().split("[\\s&&[^\\n]]++");
    String commandString = splitMessage[0];
    SimpleCommand command = commands.get(commandString.toLowerCase());
    if (command == null) {
        // maybe it requires a mention
        if (splitMessage.length > 1) {
            command = commands.get(splitMessage[1].toLowerCase());
            if (command == null || !command.getCommandAnnotation().requiresMention()) {
                return;
            }
            // remove the first which is the mention
            splitMessage = Arrays.copyOfRange(splitMessage, 1, splitMessage.length);
        } else {
            return;
        }
    }
    Command commandAnnotation = command.getCommandAnnotation();
    if (commandAnnotation.requiresMention() && !commandString.equals(api.getYourself().getMentionTag())) {
        return;
    }
    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());
        }
        return;
    }
    final Object[] parameters = getParameters(splitMessage, command, message, api);
    if (commandAnnotation.async()) {
        final SimpleCommand commandFinal = command;
        api.getThreadPool().getExecutorService().submit(() -> invokeMethod(commandFinal, message, parameters));
    } else {
        invokeMethod(command, message, parameters);
    }
}
 
開發者ID:BtoBastian,項目名稱:sdcf4j,代碼行數:51,代碼來源:JavacordHandler.java

示例2: handleMessageCreate

import de.btobastian.sdcf4j.Command; //導入方法依賴的package包/類
/**
 * Handles a received message.
 *
 * @param event The MessageReceivedEvent.
 */
private void handleMessageCreate(final MessageReceivedEvent event) {
    JDA jda = event.getJDA();
    if (event.getAuthor() == jda.getSelfUser()) {
        return;
    }
    String[] splitMessage = event.getMessage().getContentRaw().split("[\\s&&[^\\n]]++");
    String commandString = splitMessage[0];
    SimpleCommand command = commands.get(commandString.toLowerCase());
    if (command == null) {
        // maybe it requires a mention
        if (splitMessage.length > 1) {
            command = commands.get(splitMessage[1].toLowerCase());
            if (command == null || !command.getCommandAnnotation().requiresMention()) {
                return;
            }
            // remove the first which is the mention
            splitMessage = Arrays.copyOfRange(splitMessage, 1, splitMessage.length);
        } else {
            return;
        }
    }
    Command commandAnnotation = command.getCommandAnnotation();
    if (commandAnnotation.requiresMention() && !commandString.equals(jda.getSelfUser().getAsMention())) {
        return;
    }
    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();
        }
        return;
    }
    final Object[] parameters = getParameters(splitMessage, command, event);
    if (commandAnnotation.async()) {
        final SimpleCommand commandFinal = command;
        Thread t = new Thread(() -> invokeMethod(commandFinal, event, parameters));
        t.setDaemon(true);
        t.start();
    } else {
        invokeMethod(command, event, parameters);
    }
}
 
開發者ID:BtoBastian,項目名稱:sdcf4j,代碼行數:53,代碼來源:JDA3Handler.java

示例3: handleMessageCreate

import de.btobastian.sdcf4j.Command; //導入方法依賴的package包/類
/**
 * Handles a received message.
 *
 * @param event The MessageReceivedEvent.
 */
private void handleMessageCreate(final MessageReceivedEvent event) {
    String[] splitMessage = event.getMessage().getContent().split("[\\s&&[^\\n]]++");
    String commandString = splitMessage[0];
    SimpleCommand command = commands.get(commandString.toLowerCase());
    if (command == null) {
        // maybe it requires a mention
        if (splitMessage.length > 1) {
            command = commands.get(splitMessage[1].toLowerCase());
            if (command == null || !command.getCommandAnnotation().requiresMention()) {
                return;
            }
            // remove the first which is the mention
            splitMessage = Arrays.copyOfRange(splitMessage, 1, splitMessage.length);
        } else {
            return;
        }
    }
    Command commandAnnotation = command.getCommandAnnotation();
    if (commandAnnotation.requiresMention() &&
            !commandString.equals("<@" + event.getClient().getOurUser().getStringID() + ">")) {
        return;
    }
    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 {
                event.getMessage().getChannel().sendMessage(Sdcf4jMessage.MISSING_PERMISSIONS.getMessage());
            } catch (MissingPermissionsException | RateLimitException | DiscordException ignored) { }
        }
        return;
    }
    final Object[] parameters = getParameters(splitMessage, command, event);
    if (commandAnnotation.async()) {
        final SimpleCommand commandFinal = command;
        Thread t = new Thread(() -> {
            invokeMethod(commandFinal, event, parameters);
        });
        t.setDaemon(true);
        t.start();
    } else {
        invokeMethod(command, event, parameters);
    }
}
 
開發者ID:BtoBastian,項目名稱:sdcf4j,代碼行數:54,代碼來源:Discord4JHandler.java


注:本文中的de.btobastian.sdcf4j.Command.async方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。