2022-09-14 19:36:59 +00:00
|
|
|
package com.alttd.modalManager;
|
|
|
|
|
|
2022-09-15 19:34:27 +00:00
|
|
|
import com.alttd.buttonManager.ButtonManager;
|
2022-10-01 01:39:51 +00:00
|
|
|
import com.alttd.modalManager.modals.*;
|
2022-09-15 19:34:27 +00:00
|
|
|
import com.alttd.util.Util;
|
2022-09-14 19:36:59 +00:00
|
|
|
import net.dv8tion.jda.api.EmbedBuilder;
|
|
|
|
|
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
|
|
|
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
2024-01-13 07:27:42 +00:00
|
|
|
import net.dv8tion.jda.api.interactions.modals.Modal;
|
2022-09-15 19:34:27 +00:00
|
|
|
import net.dv8tion.jda.api.requests.RestAction;
|
2022-09-14 19:36:59 +00:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
public class ModalManager extends ListenerAdapter {
|
|
|
|
|
|
|
|
|
|
private final List<DiscordModal> modals;
|
|
|
|
|
|
2022-09-15 19:34:27 +00:00
|
|
|
public ModalManager(ButtonManager buttonManager) {
|
2022-09-14 19:36:59 +00:00
|
|
|
modals = List.of(
|
2022-09-15 20:03:36 +00:00
|
|
|
new ModalSuggestion(buttonManager),
|
2022-09-16 19:34:57 +00:00
|
|
|
new ModalEvidence(),
|
2022-09-21 19:49:42 +00:00
|
|
|
new ModalReplySuggestion(),
|
2022-10-01 01:39:51 +00:00
|
|
|
new ModalRemindMe(buttonManager),
|
|
|
|
|
new ModalCrateItem());
|
2022-09-14 19:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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()) {
|
2023-01-08 02:48:45 +00:00
|
|
|
// 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);
|
2022-09-14 19:36:59 +00:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|