2022-03-31 20:08:50 +00:00
|
|
|
package com.alttd.commandManager.commands.PollCommand;
|
|
|
|
|
|
|
|
|
|
import com.alttd.commandManager.CommandManager;
|
|
|
|
|
import com.alttd.commandManager.DiscordCommand;
|
2022-04-01 00:54:33 +00:00
|
|
|
import com.alttd.commandManager.SubCommand;
|
2022-03-31 20:08:50 +00:00
|
|
|
import com.alttd.permissions.PermissionManager;
|
|
|
|
|
import com.alttd.util.Logger;
|
|
|
|
|
import com.alttd.util.Util;
|
2022-04-01 00:54:33 +00:00
|
|
|
import net.dv8tion.jda.api.EmbedBuilder;
|
2022-03-31 20:08:50 +00:00
|
|
|
import net.dv8tion.jda.api.JDA;
|
2022-04-01 00:54:33 +00:00
|
|
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
2022-03-31 20:08:50 +00:00
|
|
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
|
|
|
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
|
|
|
|
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
|
|
|
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
|
|
|
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
2022-04-01 00:54:33 +00:00
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.util.HashMap;
|
2022-03-31 20:08:50 +00:00
|
|
|
|
|
|
|
|
public class CommandPoll extends DiscordCommand {
|
|
|
|
|
|
2022-04-01 00:54:33 +00:00
|
|
|
private final HashMap<String, SubCommand> subCommandMap = new HashMap<>();
|
2022-03-31 20:08:50 +00:00
|
|
|
|
|
|
|
|
public CommandPoll(JDA jda, CommandManager commandManager) {
|
|
|
|
|
SlashCommandData slashCommandData = Commands.slash(getName(), "Create, edit, and manage polls")
|
|
|
|
|
.addSubcommands(
|
|
|
|
|
new SubcommandData("add", "Add a new poll to a channel")
|
|
|
|
|
.addOption(OptionType.CHANNEL, "channel", "Channel this poll should go into", true, true)
|
|
|
|
|
.addOption(OptionType.STRING, "title", "Title of the embed (max 256 characters)", true),
|
|
|
|
|
new SubcommandData("edit_title", "Edit the title of a poll")
|
|
|
|
|
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true, true)
|
|
|
|
|
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you're editing", true)
|
|
|
|
|
.addOption(OptionType.STRING, "title", "The new title for the poll (max 256 characters)", true),
|
|
|
|
|
new SubcommandData("edit_description", "Edit the description of a poll")
|
|
|
|
|
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true, true)
|
|
|
|
|
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you're editing", true)
|
|
|
|
|
.addOption(OptionType.STRING, "description", "The new description for the poll (max 2048 characters)", true),
|
|
|
|
|
new SubcommandData("add_button", "Add a button to a poll")
|
|
|
|
|
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true, true)
|
|
|
|
|
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you're adding a button to", true)
|
|
|
|
|
.addOption(OptionType.INTEGER, "button_row", "Row the button should go in (1-5)", true)
|
|
|
|
|
.addOption(OptionType.STRING, "button_name", "Name of the button you're adding"),
|
|
|
|
|
new SubcommandData("remove_button", "Remove a button from a poll")
|
|
|
|
|
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true, true)
|
|
|
|
|
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you're removing a button from", true)
|
|
|
|
|
.addOption(OptionType.STRING, "button_name", "Name of the button you're removing"),
|
|
|
|
|
new SubcommandData("open", "Open a poll")
|
|
|
|
|
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true, true)
|
|
|
|
|
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you're opening", true),
|
|
|
|
|
new SubcommandData("close", "Close a poll")
|
|
|
|
|
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true, true)
|
|
|
|
|
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you're closing", true),
|
|
|
|
|
new SubcommandData("results", "Get the results for a poll")
|
|
|
|
|
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true, true)
|
|
|
|
|
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you want the results for", true));
|
2022-04-01 00:54:33 +00:00
|
|
|
Util.registerSubcommands(subCommandMap, new SubCommandAdd(this),
|
|
|
|
|
new SubCommandAddButton(this),
|
|
|
|
|
new SubCommandClose(this),
|
|
|
|
|
new SubCommandEditDescription(this),
|
|
|
|
|
new SubCommandEditTitle(this),
|
|
|
|
|
new SubCommandOpen(this),
|
|
|
|
|
new SubCommandRemoveButton(this),
|
|
|
|
|
new SubCommandResults(this));
|
|
|
|
|
Util.registerCommand(commandManager, jda, slashCommandData, getName());
|
2022-03-31 20:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getName() {
|
|
|
|
|
return "poll";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void execute(SlashCommandInteractionEvent event) {
|
2022-04-01 00:54:33 +00:00
|
|
|
if (event.getGuild() == null || event.getMember() == null) {
|
2022-03-31 20:08:50 +00:00
|
|
|
event.replyEmbeds(Util.guildOnlyCommand(getName())).setEphemeral(true).queue();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-04-01 00:54:33 +00:00
|
|
|
if (PermissionManager.getInstance().hasPermission(event.getTextChannel(), event.getIdLong(), Util.getGroupIds(event.getMember()), getPermission())) {
|
2022-03-31 20:08:50 +00:00
|
|
|
event.replyEmbeds(Util.noPermission(getName())).setEphemeral(true).queue();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String subcommandName = event.getInteraction().getSubcommandName();
|
|
|
|
|
if (subcommandName == null) {
|
|
|
|
|
Logger.severe("No subcommand found for %", getName());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 00:54:33 +00:00
|
|
|
SubCommand subCommand = subCommandMap.get(subcommandName);
|
|
|
|
|
if (subCommand == null) {
|
|
|
|
|
event.replyEmbeds(new EmbedBuilder()
|
|
|
|
|
.setTitle("Subcommand not found")
|
|
|
|
|
.setDescription("Unable to find subcommand `" + subcommandName + "`")
|
|
|
|
|
.setColor(Color.RED)
|
|
|
|
|
.build())
|
|
|
|
|
.setEphemeral(true)
|
|
|
|
|
.queue();
|
|
|
|
|
return;
|
2022-03-31 20:08:50 +00:00
|
|
|
}
|
2022-04-01 00:54:33 +00:00
|
|
|
|
|
|
|
|
subCommand.execute(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
|
|
|
|
|
2022-03-31 20:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getHelpMessage() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|