当前位置: 首页>>代码示例>>Java>>正文


Java Command类代码示例

本文整理汇总了Java中de.btobastian.sdcf4j.Command的典型用法代码示例。如果您正苦于以下问题:Java Command类的具体用法?Java Command怎么用?Java Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Command类属于de.btobastian.sdcf4j包,在下文中一共展示了Command类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onPastaCommand

import de.btobastian.sdcf4j.Command; //导入依赖的package包/类
@Command(aliases = {"pasta", "copypasta"}, description = "Gets a random copypasta from /r/copypasta.", usage = "pasta")
public static String onPastaCommand(String[] args, IMessage message) throws OAuthException, RateLimitException, DiscordException, MissingPermissionsException {
    Listing<Submission> copypasta = null;
    RedditClient redditClient;
    try {
        redditClient = Reddit.getRedditClient();
        if (!redditClient.isAuthenticated()) {
            Reddit.authReddit();
        }
        FluentRedditClient fluent = new FluentRedditClient(redditClient);
        copypasta = fluent.subreddit("copypasta").fetch();
    }   catch (NetworkException | NullPointerException e) {
        Reddit.authReddit();
        onPastaCommand(args, message);
    }

    System.out.println("Serving some pasta.");
    Random random = new Random();
    if (copypasta != null) {
        Submission pasta = copypasta.get(random.nextInt(copypasta.size()));
        if (args.length > 0) {
            message.delete();
            return "Too many arguments! Use `~help` to get usages.";
        } else if (args.length == 0) {
            message.delete();
            return StringUtils.abbreviate((":spaghetti: " + "**" + pasta.getTitle() + "**\n" + pasta.getSelftext()), 2000);
        }
    }

    // Something went wrong, display error message
    message.delete();
    return "An error occurred, please try again later.";
}
 
开发者ID:nbd9,项目名称:PastaBot,代码行数:34,代码来源:PastaCommand.java

示例2: onKahootCommand

import de.btobastian.sdcf4j.Command; //导入依赖的package包/类
@Command(aliases = {"kahoot"}, description = "Deploys up to 50 bots to *hack* kahoot", usage = "kahoot [game pin] [bot name] [number of bots]")
public static String onKahootCommand(String[] args) throws IOException {
    if (args.length == 3) {
        if (isInteger(args[0])) {
            int pin = Integer.parseInt(args[0]);
            //TODO: Might want to check if pin is an actual game here...
            if (pin >= 1000000 && pin <= 9999999) {
                if (isInteger(args[2])) {


                    int botsToAdd = Integer.parseInt(args[2]);
                    String botName = args[1];

                    if (botsToAdd + currentBots > maxBots) {

                        currentBots = currentBots + botsToAdd;

                        //spawn in the bots here

                        return "Check kahoot!";


                    } else {
                        return "Too many bots! There is a maximum of " + maxBots + " bots running at once. Please wait until a kahoot game has ended or decrease the number of bots you are adding.";
                    }
                }
            }
        } else {
            return "Invalid Pin!";
        }
    }
    else {
        return "Wrong arguments! Check usage with `~help`";
    }
    return "Something went wrong. Please try again";
}
 
开发者ID:nbd9,项目名称:PastaBot,代码行数:37,代码来源:KahootCommand.java

示例3: onJokeCommand

import de.btobastian.sdcf4j.Command; //导入依赖的package包/类
@Command(aliases = {"joke", "prank"}, description = "Gets a random joke from /r/jokes.", usage = "joke")
public static String onJokeCommand(String[] args, IMessage message) throws OAuthException, RateLimitException, DiscordException, MissingPermissionsException {
    Listing<Submission> jokes = null;
    RedditClient redditClient;
    try {
        redditClient = Reddit.getRedditClient();
        if (!redditClient.isAuthenticated()) {
            Reddit.authReddit();
        }
        FluentRedditClient fluent = new FluentRedditClient(redditClient);
        jokes = fluent.subreddit("jokes").fetch();
    }   catch (NetworkException | NullPointerException e) {
        Reddit.authReddit();
        onJokeCommand(args, message);
    }

    Random random = new Random();
    System.out.println("Telling a bad joke.");

    if (jokes != null) {
        Submission joke = jokes.get(random.nextInt(jokes.size()));
        if (args.length > 0) {
            message.delete();
            return "Too many arguments! Use `~help` to get usages.";
        } else if (args.length == 0) {
            message.delete();
            return StringUtils.abbreviate((":rofl: " + "**" + joke.getTitle() + "**\n" + joke.getSelftext()), 2000);
        }
    }

    // Something went wrong, display error message.
    message.delete();
    return "An error occurred, please try again";
}
 
开发者ID:nbd9,项目名称:PastaBot,代码行数:35,代码来源:JokeCommand.java

示例4: 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

示例5: 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

示例6: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。