Search in sources :

Example 1 with DefaultComponentManager

use of com.freya02.botcommands.api.components.DefaultComponentManager in project BotCommands by freya022.

the class ComponentsBotMain method main.

public static void main(String[] args) {
    try {
        final CommonMain.CommonStuff commonStuff = CommonMain.start();
        final JDA jda = commonStuff.getJDA();
        // Instantiate the database needed for components
        final ComponentsDB componentsDB = new ComponentsDB(commonStuff.getConfig());
        // Build the command framework:
        // Prefix: !
        // Owner: User with the ID 222046562543468545
        // Commands package: com.freya02.bot.componentsbot.commands
        CommandsBuilder.newBuilder(222046562543468545L).textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix("!")).setComponentManager(new DefaultComponentManager(componentsDB::getConnection)).build(jda, // Registering listeners is taken care of by the lib
        "com.freya02.bot.componentsbot.commands");
    } catch (Exception e) {
        LOGGER.error("Unable to start the bot", e);
        System.exit(-1);
    }
}
Also used : JDA(net.dv8tion.jda.api.JDA) CommonMain(com.freya02.bot.CommonMain) ComponentsDB(com.freya02.bot.ComponentsDB) DefaultComponentManager(com.freya02.botcommands.api.components.DefaultComponentManager)

Example 2 with DefaultComponentManager

use of com.freya02.botcommands.api.components.DefaultComponentManager in project BotCommands by freya022.

the class PaginationBotMain method main.

public static void main(String[] args) {
    try {
        final CommonMain.CommonStuff commonStuff = CommonMain.start();
        final JDA jda = commonStuff.getJDA();
        final ComponentsDB componentsDB = new ComponentsDB(commonStuff.getConfig());
        // Build the command framework:
        // Prefix: !
        // Owner: User with the ID 222046562543468545
        // Commands package: com.freya02.bot.paginationbot.commands
        CommandsBuilder.newBuilder(222046562543468545L).textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix("!")).setComponentManager(new DefaultComponentManager(componentsDB::getConnection)).build(jda, // Registering listeners is taken care of by the lib
        "com.freya02.bot.paginationbot.commands");
    } catch (Exception e) {
        LOGGER.error("Unable to start the bot", e);
        System.exit(-1);
    }
}
Also used : JDA(net.dv8tion.jda.api.JDA) CommonMain(com.freya02.bot.CommonMain) ComponentsDB(com.freya02.bot.ComponentsDB) DefaultComponentManager(com.freya02.botcommands.api.components.DefaultComponentManager)

Example 3 with DefaultComponentManager

use of com.freya02.botcommands.api.components.DefaultComponentManager in project BotCommands by freya022.

the class Main method main.

public static void main(String[] args) {
    try {
        // Make sure that the file Config.json exists under src/main/java/resources/com/freya02/bot/Config.json and has a valid token inside
        final Config config = Config.readConfig();
        // Set up JDA
        final JDA jda = JDABuilder.createLight(config.getToken()).setActivity(Activity.playing("Prefix is " + config.getPrefix())).build().awaitReady();
        // Print some information about the bot
        LOGGER.info("Bot connected as {}", jda.getSelfUser().getAsTag());
        LOGGER.info("The bot is present on these guilds :");
        for (Guild guild : jda.getGuildCache()) {
            LOGGER.info("\t- {} ({})", guild.getName(), guild.getId());
        }
        // Instantiate the database needed for components
        final ComponentsDB componentsDB = new ComponentsDB(config);
        // Build the command framework:
        // Prefix: configured in Config.json
        // Owner: configured in Config.json
        // Commands package: com.freya02.bot.commands
        CommandsBuilder.newBuilder(config.getOwnerId()).textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix(config.getPrefix())).setComponentManager(new DefaultComponentManager(componentsDB::getConnection)).build(jda, // Registering listeners is taken care of by the lib
        "com.freya02.bot.commands");
    } catch (IOException | InterruptedException | LoginException | SQLException e) {
        LOGGER.error("Unable to start the bot", e);
        System.exit(-1);
    }
}
Also used : SQLException(java.sql.SQLException) JDA(net.dv8tion.jda.api.JDA) LoginException(javax.security.auth.login.LoginException) IOException(java.io.IOException) Guild(net.dv8tion.jda.api.entities.Guild) DefaultComponentManager(com.freya02.botcommands.api.components.DefaultComponentManager)

Example 4 with DefaultComponentManager

use of com.freya02.botcommands.api.components.DefaultComponentManager in project BotCommands by freya022.

the class SlashCommandsMain method main.

public static void main(@Nullable String[] args) throws NoSuchMethodException {
    try {
        final Config config = Config.readConfig();
        // debug();
        final JDA jda = JDABuilder.createLight(config.getToken()).enableIntents(GatewayIntent.GUILD_MEMBERS).setActivity(Activity.playing("application commands")).build().awaitReady();
        CommandsBuilder.newBuilder(config.getOwnerId()).textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix(config.getPrefix()).addTextFilter(data -> data.event().getChannel().getIdLong() == 722891685755093076L || data.event().getChannel().getIdLong() == 930384760298164235L)).extensionsBuilder(extensionsBuilder -> extensionsBuilder.registerConstructorParameter(LocalDateTime.class, ignored -> LocalDateTime.now()).registerParameterResolver(new DateTimeResolver()).setMethodRunnerFactory(new KotlinMethodRunnerFactory(MethodRunnerScope.getDispatcher(), MethodRunnerScope.getScope()))).applicationCommandBuilder(applicationCommandsBuilder -> applicationCommandsBuilder.addApplicationFilter(data -> {
            final boolean isDoNotRun = data.commandInfo().getPath().equals(CommandPath.ofName("donotrun"));
            if (isDoNotRun) {
                data.event().reply("This command should not be ran").setEphemeral(true).queue();
            }
            return !isDoNotRun;
        }).addComponentFilter(data -> {
            final boolean canRun = data.event().getChannel().getIdLong() != 932902082724380744L;
            if (!canRun) {
                data.event().deferEdit().queue();
            }
            return canRun;
        }).addTestGuilds(config.getTestGuildId())).addSearchPath("com.freya02.botcommands.test.commands").setComponentManager(new DefaultComponentManager(new TestDB(config.getDbConfig()).getConnectionSupplier())).setSettingsProvider(new BasicSettingsProvider()).build(jda);
        LOGGER.info("Finished building");
    } catch (Exception e) {
        LOGGER.error("Could not start the bot", e);
        System.exit(-2);
    }
}
Also used : Nullable(org.jetbrains.annotations.Nullable) CommandsBuilder(com.freya02.botcommands.api.CommandsBuilder) JDA(net.dv8tion.jda.api.JDA) Logger(org.slf4j.Logger) JDABuilder(net.dv8tion.jda.api.JDABuilder) CommandPath(com.freya02.botcommands.api.application.CommandPath) DefaultComponentManager(com.freya02.botcommands.api.components.DefaultComponentManager) LocalDateTime(java.time.LocalDateTime) Activity(net.dv8tion.jda.api.entities.Activity) Logging(com.freya02.botcommands.api.Logging) KotlinMethodRunnerFactory(com.freya02.botcommands.api.runner.KotlinMethodRunnerFactory) GatewayIntent(net.dv8tion.jda.api.requests.GatewayIntent) JDA(net.dv8tion.jda.api.JDA) KotlinMethodRunnerFactory(com.freya02.botcommands.api.runner.KotlinMethodRunnerFactory) DefaultComponentManager(com.freya02.botcommands.api.components.DefaultComponentManager)

Aggregations

DefaultComponentManager (com.freya02.botcommands.api.components.DefaultComponentManager)4 JDA (net.dv8tion.jda.api.JDA)4 CommonMain (com.freya02.bot.CommonMain)2 ComponentsDB (com.freya02.bot.ComponentsDB)2 CommandsBuilder (com.freya02.botcommands.api.CommandsBuilder)1 Logging (com.freya02.botcommands.api.Logging)1 CommandPath (com.freya02.botcommands.api.application.CommandPath)1 KotlinMethodRunnerFactory (com.freya02.botcommands.api.runner.KotlinMethodRunnerFactory)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 LocalDateTime (java.time.LocalDateTime)1 LoginException (javax.security.auth.login.LoginException)1 JDABuilder (net.dv8tion.jda.api.JDABuilder)1 Activity (net.dv8tion.jda.api.entities.Activity)1 Guild (net.dv8tion.jda.api.entities.Guild)1 GatewayIntent (net.dv8tion.jda.api.requests.GatewayIntent)1 Nullable (org.jetbrains.annotations.Nullable)1 Logger (org.slf4j.Logger)1