Search in sources :

Example 1 with RateLimitException

use of net.robinfriedli.aiode.exceptions.RateLimitException in project aiode by robinfriedli.

the class CommandManager method runCommand.

/**
 * Run command in a new thread, to be enqueued in the provided {@link ThreadExecutionQueue}.
 *
 * @param command        the command to run
 * @param executionQueue the target execution queue
 */
public void runCommand(Command command, ThreadExecutionQueue executionQueue) {
    CommandContext context = command.getContext();
    CommandExecutionTask commandExecutionTask = new CommandExecutionTask(command, executionQueue, this);
    commandExecutionTask.setName("command-execution-" + context);
    try {
        boolean queued = !executionQueue.add(commandExecutionTask, false);
        if (queued) {
            MessageService messageService = Aiode.get().getMessageService();
            messageService.sendError("Executing too many commands concurrently. This command will be executed after one has finished. " + "You may use the abort command to cancel queued commands and interrupt running commands.", context.getChannel());
            logger.warn(String.format("Guild %s has reached the max concurrent commands limit.", context.getGuild()));
        }
    } catch (RateLimitException e) {
        if (!e.isTimeout()) {
            throw new InvalidCommandException(e.getMessage());
        }
    }
}
Also used : CommandExecutionTask(net.robinfriedli.aiode.concurrent.CommandExecutionTask) RateLimitException(net.robinfriedli.aiode.exceptions.RateLimitException) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) MessageService(net.robinfriedli.aiode.discord.MessageService)

Aggregations

CommandExecutionTask (net.robinfriedli.aiode.concurrent.CommandExecutionTask)1 MessageService (net.robinfriedli.aiode.discord.MessageService)1 InvalidCommandException (net.robinfriedli.aiode.exceptions.InvalidCommandException)1 RateLimitException (net.robinfriedli.aiode.exceptions.RateLimitException)1