use of com.freya02.botcommands.api.components.Components in project BotCommands by freya022.
the class CommandsBuilderImpl method buildClasses.
private void buildClasses() throws Exception {
classes.removeIf(c -> {
try {
return !ReflectionUtils.isInstantiable(c);
} catch (IllegalAccessException | InvocationTargetException e) {
LOGGER.error("An error occurred while trying to find if a class is instantiable", e);
throw new RuntimeException("An error occurred while trying to find if a class is instantiable", e);
}
});
for (Class<?> aClass : classes) {
processClass(aClass);
}
if (!context.isHelpDisabled()) {
processClass(HelpCommand.class);
final TextCommandInfo helpInfo = context.findFirstCommand(CommandPath.of("help"));
if (helpInfo == null)
throw new IllegalStateException("HelpCommand did not build properly");
final HelpCommand help = (HelpCommand) helpInfo.getInstance();
help.generate();
}
prefixedCommandsBuilder.postProcess();
if (context.getComponentManager() != null) {
// Load button listeners
for (Class<?> aClass : classes) {
componentsBuilder.processClass(aClass);
}
} else {
LOGGER.info("ComponentManager is not set, the Components API, paginators and menus won't be usable");
}
applicationCommandsBuilder.postProcess();
if (context.getComponentManager() != null) {
componentsBuilder.postProcess();
}
eventListenersBuilder.postProcess();
autocompletionHandlersBuilder.postProcess();
context.getRegistrationListeners().forEach(RegistrationListener::onBuildComplete);
LOGGER.info("Finished registering all commands");
}
use of com.freya02.botcommands.api.components.Components in project BotCommands by freya022.
the class MessageComponents method execute.
@JDATextCommand(name = "components")
public void execute(CommandEvent event) {
final ActionRow firstRow = ActionRow.of(Components.selectionMenu(SELECTION_HANDLER_NAME).addOption("Option 1", "Value 1").addOption("Option 2", "Value 2").addOption("Option 3", "Value 3").setPlaceholder("Select a value").build());
final ActionRow secondRow = ActionRow.of(Components.primaryButton(BUTTON_HANDLER_NAME).build("Primary button (persistent, no group)"));
event.getMessage().reply("Components !").setActionRows(firstRow, secondRow).queue();
}
use of com.freya02.botcommands.api.components.Components in project BotCommands by freya022.
the class ExtensionsBotMain method main.
public static void main(String[] args) {
try {
final CommonMain.CommonStuff commonStuff = CommonMain.start();
final JDA jda = commonStuff.getJDA();
// Build the command framework:
// Prefix: !
// Owner: User with the ID 222046562543468545
// Commands package: com.freya02.bot.extensionsbot.commands
CommandsBuilder.newBuilder(222046562543468545L).textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix("!")).extensionsBuilder(extensionsBuilder -> extensionsBuilder.registerParameterResolver(// Support JDA's Timestamp in application commands and components
new TimestampResolver())).setSettingsProvider(// Add our settings provider for the guilds
new MySettingsProvider()).build(jda, // Registering listeners is taken care of by the lib
"com.freya02.bot.extensionsbot.commands");
} catch (Exception e) {
LOGGER.error("Unable to start the bot", e);
System.exit(-1);
}
}
use of com.freya02.botcommands.api.components.Components in project BotCommands by freya022.
the class SlashInteractiveMenu method interactiveMenu.
@JDASlashCommand(name = "interactive")
public void interactiveMenu(GuildSlashEvent event) {
final InteractiveMenu menu = new InteractiveMenuBuilder().addMenu(SelectContent.of("Joy", "This sparks joy", Emoji.fromMarkdown("\uD83D\uDE02")), (interactiveMenu, messageBuilder, components) -> {
components.addComponents(1, Components.dangerButton(buttonEvent -> {
event.getHook().deleteOriginal().queue();
interactiveMenu.cancelTimeout();
interactiveMenu.cleanup(event.getContext());
}).build("Delete"), Components.secondaryButton(buttonEvent -> {
interactiveMenu.setSelectedItem("Grin");
buttonEvent.editMessage(interactiveMenu.get()).queue();
}).build("Go to 'Grin'"));
return new EmbedBuilder().setTitle("This sparks joy").build();
}).addMenu(SelectContent.of("Grin", "This does not spark joy", Emoji.fromMarkdown("\uD83D\uDE00")), (interactiveMenu, messageBuilder, components) -> {
components.addComponents(1, Components.dangerButton(buttonEvent -> {
event.getHook().deleteOriginal().queue();
interactiveMenu.cancelTimeout();
interactiveMenu.cleanup(event.getContext());
}).build("Delete"), Components.secondaryButton(buttonEvent -> {
interactiveMenu.setSelectedItem(0);
buttonEvent.editMessage(interactiveMenu.get()).queue();
}).build("Go to 'Joy'"));
return new EmbedBuilder().setTitle("This does not spark joy").build();
}).setConstraints(InteractionConstraints.ofUsers(event.getUser())).setTimeout(5, TimeUnit.SECONDS, (interactiveMenu, msg) -> {
System.out.println("bru");
interactiveMenu.cleanup(event.getContext());
}).build();
event.reply(menu.get()).setEphemeral(false).queue();
}
use of com.freya02.botcommands.api.components.Components in project BotCommands by freya022.
the class SlashPaginator method replyPaginator.
private void replyPaginator(GuildSlashEvent event, BContext context, InteractionConstraints constraints) {
final PaginatorBuilder builder = new PaginatorBuilder().setConstraints(constraints).useDeleteButton(true).setTimeout(5, TimeUnit.SECONDS, (paginator, message) -> {
paginator.cleanup(context);
// Remove components on timeout
event.getHook().editOriginalComponents().queue();
// Disable all components on timeout, more expensive
// event.getHook()
// .retrieveOriginal()
// .flatMap(m -> m.editMessageComponents(m.getActionRows().stream().map(ActionRow::asDisabled).toList()))
// .queue();
}).setMaxPages(5).setFirstContent(ButtonContent.withString("←")).setPaginatorSupplier((paginator, messageBuilder, components, page) -> {
components.addComponents(1, Components.primaryButton(btnEvt -> {
// Pages starts at 0
paginator.setPage(2);
btnEvt.editMessage(paginator.get()).queue();
}).build(ButtonContent.withEmoji("Go to page 3", EmojiUtils.resolveJDAEmoji("page_facing_up"))));
components.addComponents(1, Components.primaryButton(btnEvt -> {
// Pages starts at 0
paginator.setPage(4);
btnEvt.editMessage(paginator.get()).queue();
}).build(ButtonContent.withEmoji("Go to page 5", EmojiUtils.resolveJDAEmoji("page_facing_up"))));
return new EmbedBuilder().setTitle(// Pages starts at 0
"Page #" + (page + 1)).build();
});
final Paginator paginator = builder.build();
event.reply(paginator.get()).setEphemeral(false).queue();
}
Aggregations