Search in sources :

Example 1 with CommandListener

use of com.freya02.botcommands.internal.prefixed.CommandListener in project BotCommands by freya022.

the class CommandsBuilderImpl method build.

/**
 * Builds the command listener and automatically registers all listener to the JDA instance
 *
 * @param jda The JDA instance of your bot
 */
public void build(JDA jda) throws Exception {
    if (jda.getShardInfo().getShardId() != 0) {
        LOGGER.warn("A shard other than 0 was passed to CommandsBuilder#build, shard 0 is needed to handle DMing exceptions, manually retrieving shard 0...");
        final ShardManager manager = jda.getShardManager();
        if (manager == null)
            throw new IllegalArgumentException("Unable to retrieve Shard 0 as shard manager is null");
        jda = manager.getShardById(0);
        if (jda == null)
            throw new IllegalArgumentException("Unable to retrieve Shard 0");
    }
    if (jda.getStatus() != JDA.Status.CONNECTED) {
        try {
            LOGGER.warn("JDA should already be ready when you call #build on CommandsBuilder !");
            jda.awaitReady();
        } catch (InterruptedException e) {
            throw new RuntimeException("CommandsBuilder got interrupted while waiting for JDA to be ready", e);
        }
    }
    final List<GatewayIntent> intents = List.of(GatewayIntent.GUILD_MESSAGES);
    if (!jda.getGatewayIntents().containsAll(intents)) {
        throw new IllegalStateException("JDA must have these intents enabled: " + intents.stream().map(Enum::name).collect(Collectors.joining(", ")));
    }
    setupContext(jda);
    ReflectionUtils.scanAnnotations(classes);
    buildClasses();
    context.addEventListeners(new EventWaiter(jda), new CommandListener(context), new ApplicationUpdaterListener(context), new ApplicationCommandListener(context));
    if (!ignoredClasses.isEmpty()) {
        LOGGER.trace("Ignored classes in search paths:");
        for (Class<?> ignoredClass : ignoredClasses) {
            LOGGER.trace("\t{}", ignoredClass.getName());
        }
    }
    ConflictDetector.detectConflicts();
}
Also used : ApplicationCommandListener(com.freya02.botcommands.internal.application.ApplicationCommandListener) CommandListener(com.freya02.botcommands.internal.prefixed.CommandListener) ApplicationUpdaterListener(com.freya02.botcommands.internal.application.ApplicationUpdaterListener) ApplicationCommandListener(com.freya02.botcommands.internal.application.ApplicationCommandListener) ShardManager(net.dv8tion.jda.api.sharding.ShardManager) GatewayIntent(net.dv8tion.jda.api.requests.GatewayIntent) EventWaiter(com.freya02.botcommands.api.waiter.EventWaiter)

Aggregations

EventWaiter (com.freya02.botcommands.api.waiter.EventWaiter)1 ApplicationCommandListener (com.freya02.botcommands.internal.application.ApplicationCommandListener)1 ApplicationUpdaterListener (com.freya02.botcommands.internal.application.ApplicationUpdaterListener)1 CommandListener (com.freya02.botcommands.internal.prefixed.CommandListener)1 GatewayIntent (net.dv8tion.jda.api.requests.GatewayIntent)1 ShardManager (net.dv8tion.jda.api.sharding.ShardManager)1