Added crate item suggestion form (fixed output type table)
This commit is contained in:
parent
e20f81e764
commit
8bcadbba27
|
|
@ -40,6 +40,7 @@ public class CommandManager extends ListenerAdapter {
|
|||
new CommandHelp(jda, this),
|
||||
new CommandPoll(jda, this),
|
||||
new CommandSuggestion(jda, modalManager, this),
|
||||
new CommandSuggestCrateItem(jda, modalManager, this),
|
||||
new CommandSetOutputChannel(jda, this),
|
||||
new CommandUpdateCommands(jda, this),
|
||||
new CommandEvidence(jda, modalManager, this),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
package com.alttd.commandManager.commands;
|
||||
|
||||
import com.alttd.commandManager.CommandManager;
|
||||
import com.alttd.commandManager.DiscordCommand;
|
||||
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.DefaultMemberPermissions;
|
||||
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 net.dv8tion.jda.api.requests.RestAction;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class CommandSuggestCrateItem extends DiscordCommand {
|
||||
|
||||
private final CommandData commandData;
|
||||
private final ModalManager modalManager;
|
||||
|
||||
public CommandSuggestCrateItem(JDA jda, ModalManager modalManager, CommandManager commandManager) {
|
||||
this.modalManager = modalManager;
|
||||
|
||||
commandData = Commands.slash(getName(), "Open crate item suggestion form.")
|
||||
.setGuildOnly(true)
|
||||
.setDefaultPermissions(DefaultMemberPermissions.ENABLED);
|
||||
Util.registerCommand(commandManager, jda, commandData, getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "crateitemsuggestion";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(SlashCommandInteractionEvent event) {
|
||||
Modal modal = modalManager.getModalFor("crate_item");
|
||||
if (modal == null) {
|
||||
event.replyEmbeds(Util.genericErrorEmbed("Error",
|
||||
"Unable to find crate item suggestion modal."))
|
||||
.setEphemeral(true).queue(RestAction.getDefaultSuccess(), Util::handleFailure);
|
||||
return;
|
||||
}
|
||||
event.replyModal(modal).queue(RestAction.getDefaultSuccess(), Util::handleFailure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||
event.replyChoices(Collections.emptyList())
|
||||
.queue(RestAction.getDefaultSuccess(), Util::handleFailure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandData getCommandData() {
|
||||
return commandData;
|
||||
}
|
||||
}
|
||||
|
|
@ -75,7 +75,7 @@ public class DatabaseTables {
|
|||
"output_type VARCHAR(64) NOT NULL, " +
|
||||
"channel BIGINT NOT NULL, " +
|
||||
"channel_type VARCHAR(64) NOT NULL, " +
|
||||
"PRIMARY KEY (guild, output_type, channel)" +
|
||||
"PRIMARY KEY (guild, output_type)" +
|
||||
")";
|
||||
try {
|
||||
connection.prepareStatement(sql).executeUpdate();
|
||||
|
|
|
|||
|
|
@ -4,5 +4,6 @@ public enum OutputType {
|
|||
SUGGESTION,
|
||||
SUGGESTION_REVIEW,
|
||||
MOD_LOG,
|
||||
EVIDENCE
|
||||
EVIDENCE,
|
||||
CRATE_TEAM
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
package com.alttd.modalManager;
|
||||
|
||||
import com.alttd.buttonManager.ButtonManager;
|
||||
import com.alttd.modalManager.modals.ModalEvidence;
|
||||
import com.alttd.modalManager.modals.ModalRemindMe;
|
||||
import com.alttd.modalManager.modals.ModalReplySuggestion;
|
||||
import com.alttd.modalManager.modals.ModalSuggestion;
|
||||
import com.alttd.modalManager.modals.*;
|
||||
import com.alttd.util.Util;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
||||
|
|
@ -27,7 +24,8 @@ public class ModalManager extends ListenerAdapter {
|
|||
new ModalSuggestion(buttonManager),
|
||||
new ModalEvidence(),
|
||||
new ModalReplySuggestion(),
|
||||
new ModalRemindMe(buttonManager));
|
||||
new ModalRemindMe(buttonManager),
|
||||
new ModalCrateItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
143
src/main/java/com/alttd/modalManager/modals/ModalCrateItem.java
Normal file
143
src/main/java/com/alttd/modalManager/modals/ModalCrateItem.java
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
package com.alttd.modalManager.modals;
|
||||
|
||||
import com.alttd.database.queries.commandOutputChannels.CommandOutputChannels;
|
||||
import com.alttd.database.queries.commandOutputChannels.OutputType;
|
||||
import com.alttd.modalManager.DiscordModal;
|
||||
import com.alttd.util.Util;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.Modal;
|
||||
import net.dv8tion.jda.api.interactions.components.text.TextInput;
|
||||
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle;
|
||||
import net.dv8tion.jda.api.interactions.modals.ModalMapping;
|
||||
import net.dv8tion.jda.api.requests.RestAction;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ModalCrateItem extends DiscordModal {
|
||||
@Override
|
||||
public String getModalId() {
|
||||
return "crate_item";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ModalInteractionEvent event) {
|
||||
Member member = event.getMember();
|
||||
Guild guild = event.getGuild();
|
||||
if (member == null || guild == null) {
|
||||
event.replyEmbeds(Util.genericErrorEmbed("Error", "This command can only be used from within a guild."))
|
||||
.setEphemeral(true).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
GuildChannel outputChannel = CommandOutputChannels.getOutputChannel(guild, OutputType.CRATE_TEAM);
|
||||
if (outputChannel == null) {
|
||||
event.replyEmbeds(Util.genericErrorEmbed("Error", "This guild does not have a crate team channel or it's not the right channel type"))
|
||||
.setEphemeral(true).queue(RestAction.getDefaultSuccess(), Util::handleFailure);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(outputChannel instanceof GuildMessageChannel channel)) {
|
||||
event.replyEmbeds(Util.genericErrorEmbed("Error", outputChannel.getType().name() + " is not a valid crate team channel type"))
|
||||
.setEphemeral(true).queue(RestAction.getDefaultSuccess(), Util::handleFailure);
|
||||
return;
|
||||
}
|
||||
|
||||
String item = getValidString(event.getValue("item"), event, true);
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
String itemName = getValidString(event.getValue("item_name"), event, true);
|
||||
if (itemName == null)
|
||||
return;
|
||||
|
||||
String lore = getValidString(event.getValue("lore"), event, true);
|
||||
if (lore == null)
|
||||
return;
|
||||
|
||||
String enchants = getValidString(event.getValue("enchants"), event, false);
|
||||
String explanation = getValidString(event.getValue("explanation"), event, false);
|
||||
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder()
|
||||
.setTitle("Crate Item Suggestion")
|
||||
.setColor(Color.ORANGE)
|
||||
.setAuthor(member.getEffectiveName(), member.getAvatarUrl())
|
||||
.addField("Item", item, false)
|
||||
.addField("Item Name", itemName, false)
|
||||
.addField("Lore", lore, false);
|
||||
if (enchants != null)
|
||||
embedBuilder.addField("Enchants", enchants, false);
|
||||
if (explanation != null)
|
||||
embedBuilder.addField("Explanation", explanation, false);
|
||||
MessageEmbed itemSuggestionEmbed = embedBuilder.build();
|
||||
|
||||
event.deferReply(true).queue(
|
||||
defer ->channel.sendMessageEmbeds(itemSuggestionEmbed).queue(
|
||||
send -> defer.editOriginalEmbeds(Util.genericSuccessEmbed("Success", "Your suggestion has been submitted to the crate team!"),
|
||||
itemSuggestionEmbed).queue(RestAction.getDefaultSuccess(), Util::handleFailure),
|
||||
error -> defer.editOriginalEmbeds(Util.genericErrorEmbed("Error", "Unable to submit your suggestion to the crate team channel..."),
|
||||
itemSuggestionEmbed).queue(RestAction.getDefaultSuccess(), Util::handleFailure)),
|
||||
Util::handleFailure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Modal getModal() {
|
||||
TextInput item = TextInput.create("item", "Item", TextInputStyle.SHORT)
|
||||
.setPlaceholder("Bone")
|
||||
.setRequiredRange(1, 32)
|
||||
.setRequired(true)
|
||||
.build();
|
||||
|
||||
TextInput itemName = TextInput.create("item_name", "Item Name", TextInputStyle.SHORT)
|
||||
.setPlaceholder("Scruff's Bone")
|
||||
.setRequiredRange(1, 32)
|
||||
.setRequired(true)
|
||||
.build();
|
||||
|
||||
TextInput lore = TextInput.create("lore", "Lore", TextInputStyle.PARAGRAPH)
|
||||
.setPlaceholder("A bone owned by the Altitude Mascot")
|
||||
.setRequiredRange(1, 256)
|
||||
.setRequired(true)
|
||||
.build();
|
||||
|
||||
TextInput enchants = TextInput.create("enchants", "Enchants", TextInputStyle.PARAGRAPH)
|
||||
.setPlaceholder("Unbreaking 1")
|
||||
.setRequiredRange(1, 256)
|
||||
.setRequired(false)
|
||||
.build();
|
||||
|
||||
TextInput explanation = TextInput.create("explanation", "The explanation behind your item", TextInputStyle.PARAGRAPH)
|
||||
.setPlaceholder("Scruff loves strong bones")
|
||||
.setRequiredRange(1, 2000)
|
||||
.setRequired(false)
|
||||
.build();
|
||||
|
||||
return Modal.create(getModalId(), "Crate Item Suggestion")
|
||||
.addActionRows(ActionRow.of(item), ActionRow.of(itemName), ActionRow.of(lore), ActionRow.of(enchants), ActionRow.of(explanation))
|
||||
.build();
|
||||
}
|
||||
|
||||
public String getValidString(ModalMapping modalMapping, ModalInteractionEvent event, boolean required) {
|
||||
if (modalMapping == null) {
|
||||
event.replyEmbeds(Util.genericErrorEmbed("Error", "Couldn't find modal"))
|
||||
.setEphemeral(true).queue();
|
||||
return null;
|
||||
}
|
||||
|
||||
String string = modalMapping.getAsString();
|
||||
if (string.isEmpty()) {
|
||||
if (required)
|
||||
event.replyEmbeds(Util.genericErrorEmbed("Error", "Couldn't find contents of modal"))
|
||||
.setEphemeral(true).queue();
|
||||
return null;
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user