Added a way to make modals and added a suggestion modal
This commit is contained in:
@@ -2,13 +2,14 @@ package com.alttd.commandManager;
|
||||
|
||||
import com.alttd.commandManager.commands.AddCommand.CommandManage;
|
||||
import com.alttd.commandManager.commands.CommandHelp;
|
||||
import com.alttd.commandManager.commands.CommandSuggestion;
|
||||
import com.alttd.commandManager.commands.PollCommand.CommandPoll;
|
||||
import com.alttd.database.Database;
|
||||
import com.alttd.modalManager.ModalManager;
|
||||
import com.alttd.util.Logger;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
@@ -27,14 +28,15 @@ public class CommandManager extends ListenerAdapter {
|
||||
private final List<DiscordCommand> commands;
|
||||
private final HashMap<String, List<ScopeInfo>> commandList = new HashMap<>();
|
||||
|
||||
public CommandManager(JDA jda) {
|
||||
public CommandManager(JDA jda, ModalManager modalManager) {
|
||||
commandList.put("manage", new ArrayList<>(List.of(new ScopeInfo(CommandScope.GLOBAL, 0))));
|
||||
loadCommands();
|
||||
Logger.info("Loading commands...");
|
||||
commands = List.of(
|
||||
new CommandManage(jda, this),
|
||||
new CommandHelp(jda, this),
|
||||
new CommandPoll(jda, this));
|
||||
new CommandPoll(jda, this),
|
||||
new CommandSuggestion(jda, modalManager, this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.alttd.commandManager.commands;
|
||||
|
||||
import com.alttd.commandManager.CommandManager;
|
||||
import com.alttd.commandManager.DiscordCommand;
|
||||
import com.alttd.config.MessagesConfig;
|
||||
import com.alttd.modalManager.ModalManager;
|
||||
import com.alttd.util.Util;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||
import net.dv8tion.jda.api.interactions.components.Modal;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class CommandSuggestion extends DiscordCommand {
|
||||
|
||||
private final CommandManager commandManager;
|
||||
private final CommandData commandData;
|
||||
private final ModalManager modalManager;
|
||||
|
||||
public CommandSuggestion(JDA jda, ModalManager modalManager, CommandManager commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
this.modalManager = modalManager;
|
||||
|
||||
commandData = Commands.slash(getName(), "Open suggestion form.");
|
||||
Util.registerCommand(commandManager, jda, commandData, getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "suggestion";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(SlashCommandInteractionEvent event) {
|
||||
Modal modal = modalManager.getModalFor("suggestion");
|
||||
if (modal == null) {
|
||||
event.replyEmbeds(Util.genericErrorEmbed("Error",
|
||||
"Unable to find suggestion modal, please report this issue to Teri")).queue();
|
||||
return;
|
||||
}
|
||||
event.replyModal(modal).queue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||
event.replyChoices(Collections.emptyList()).queue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return MessagesConfig.HELP_SUGGESTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandData getCommandData() {
|
||||
return commandData;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.alttd.commandManager.listeners;
|
||||
|
||||
import com.alttd.commandManager.CommandManager;
|
||||
import com.alttd.util.Logger;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.events.ReadyEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JDAListener extends ListenerAdapter {
|
||||
|
||||
private final JDA jda;
|
||||
|
||||
public JDAListener(JDA jda) {
|
||||
this.jda = jda;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady(@NotNull ReadyEvent event) {
|
||||
Logger.info("JDA ready to register commands.");
|
||||
jda.addEventListener(new CommandManager(jda));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user