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());
}
}
}
Aggregations