Search in sources :

Example 1 with BasicSettingsProvider

use of com.freya02.bot.wiki.slash.BasicSettingsProvider in project BotCommands by freya022.

the class SlashMain method main.

public static void main(String[] args) {
    try {
        final Config config = Config.readConfig();
        final JDA jda = JDABuilder.createLight(config.getToken()).build().awaitReady();
        final CommandsBuilder builder = CommandsBuilder.newBuilder();
        builder.setSettingsProvider(new BasicSettingsProvider(builder.getContext())).build(jda, "com.freya02.bot.wiki.slash.commands");
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
Also used : Config(com.freya02.bot.Config) JDA(net.dv8tion.jda.api.JDA) CommandsBuilder(com.freya02.botcommands.api.CommandsBuilder)

Example 2 with BasicSettingsProvider

use of com.freya02.bot.wiki.slash.BasicSettingsProvider in project BotCommands by freya022.

the class EnableInfoCommand method execute.

@JDATextCommand(name = "enableinfocommand", description = "Enables the /info command")
public void execute(CommandEvent event) {
    if (event.getMember().canInteract(event.getGuild().getSelfMember())) {
        final BasicSettingsProvider settingsProvider = (BasicSettingsProvider) event.getContext().getSettingsProvider();
        if (settingsProvider == null) {
            event.indicateError("No settings provider has been set").queue();
            return;
        }
        settingsProvider.addCommand(event.getGuild(), "info");
        event.reactSuccess().queue();
    } else {
        event.indicateError("You cannot do this").queue();
    }
}
Also used : BasicSettingsProvider(com.freya02.bot.wiki.slash.BasicSettingsProvider) JDATextCommand(com.freya02.botcommands.api.prefixed.annotations.JDATextCommand)

Example 3 with BasicSettingsProvider

use of com.freya02.bot.wiki.slash.BasicSettingsProvider 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

CommandsBuilder (com.freya02.botcommands.api.CommandsBuilder)2 JDA (net.dv8tion.jda.api.JDA)2 Config (com.freya02.bot.Config)1 BasicSettingsProvider (com.freya02.bot.wiki.slash.BasicSettingsProvider)1 Logging (com.freya02.botcommands.api.Logging)1 CommandPath (com.freya02.botcommands.api.application.CommandPath)1 DefaultComponentManager (com.freya02.botcommands.api.components.DefaultComponentManager)1 JDATextCommand (com.freya02.botcommands.api.prefixed.annotations.JDATextCommand)1 KotlinMethodRunnerFactory (com.freya02.botcommands.api.runner.KotlinMethodRunnerFactory)1 LocalDateTime (java.time.LocalDateTime)1 JDABuilder (net.dv8tion.jda.api.JDABuilder)1 Activity (net.dv8tion.jda.api.entities.Activity)1 GatewayIntent (net.dv8tion.jda.api.requests.GatewayIntent)1 Nullable (org.jetbrains.annotations.Nullable)1 Logger (org.slf4j.Logger)1