use of com.freya02.botcommands.api.runner.KotlinMethodRunnerFactory 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);
}
}
Aggregations