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-09-15 20:03:36 +00:00
|
|
|
import com.alttd.modalManager.modals.ModalEvidence;
|
2022-09-14 19:36:59 +00:00
|
|
|
import com.alttd.modalManager.modals.ModalSuggestion;
|
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;
|
|
|
|
|
import net.dv8tion.jda.api.interactions.components.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),
|
|
|
|
|
new ModalEvidence());
|
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()) {
|
|
|
|
|
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)
|
2022-09-15 19:34:27 +00:00
|
|
|
.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();
|
|
|
|
|
}
|
|
|
|
|
}
|