AltitudeBot/src/main/java/com/alttd/modalManager/ModalManager.java
Teriuihi 27f1920081 Create event management system, added event notifier for community events
Added functionalities to create and manage events, including the creation of necessary database tables, context menus, modals, and scheduling tasks. Introduced `UserToMessageTracker` utility for tracking user messages within modals.
2024-08-07 00:18:40 +02:00

56 lines
2.1 KiB
Java

package com.alttd.modalManager;
import com.alttd.buttonManager.ButtonManager;
import com.alttd.modalManager.modals.*;
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.modals.Modal;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
public class ModalManager extends ListenerAdapter {
private final List<DiscordModal> modals;
public ModalManager(ButtonManager buttonManager) {
modals = List.of(
new ModalSuggestion(buttonManager),
new ModalEvidence(),
new ModalReplySuggestion(),
new ModalRemindMe(buttonManager),
new ModalCrateItem(),
new ModalCreateEvent(buttonManager));
}
@Override
public void onModalInteraction(@NotNull ModalInteractionEvent event) {
String modalId = event.getModalId();
Optional<DiscordModal> first = modals.stream()
.filter(discordModal -> discordModal.getModalId().equalsIgnoreCase(modalId))
.findFirst();
if (first.isEmpty()) {
// event.replyEmbeds(new EmbedBuilder()
// .setTitle("Invalid command")
// .setDescription("Unable to process modal with id: [" + modalId + "], please report this issue to a Teri")
// .setColor(Color.RED)
// .build())
// .setEphemeral(true)
// .queue(RestAction.getDefaultSuccess(), Util::handleFailure);
return;
}
first.get().execute(event);
}
public @Nullable Modal getModalFor(String modalId) {
Optional<DiscordModal> first = modals.stream()
.filter(discordModal -> discordModal.getModalId().equalsIgnoreCase(modalId))
.findFirst();
if (first.isEmpty())
return null;
return first.get().getModal();
}
}