More work on suggestion modal
This commit is contained in:
parent
6a05dec5b9
commit
49a5903da0
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.alttd.database.queries.commandOutputChannels;
|
||||||
|
|
||||||
|
import com.alttd.database.Database;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class CommandOutputChannels {
|
||||||
|
|
||||||
|
public static boolean setOutputChannel(long guildId, OutputType outputType, long channelId) {
|
||||||
|
String sql = "INSERT INTO output_channel (guild, output_type, channel) VALUES (?, ?, ?)";
|
||||||
|
try {
|
||||||
|
PreparedStatement preparedStatement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||||
|
preparedStatement.setLong(1, guildId);
|
||||||
|
preparedStatement.setString(2, outputType.name());
|
||||||
|
preparedStatement.setLong(3, channelId);
|
||||||
|
|
||||||
|
return preparedStatement.executeUpdate() == 1;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Logger.exception(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the channelId of the channel in the specified guild for the specified output type
|
||||||
|
* @param guildId id of the guild to check in
|
||||||
|
* @param outputType output type to check for
|
||||||
|
* @return long channel id or 0 if it errors or can't be found
|
||||||
|
*/
|
||||||
|
public static long getOutputChannel(long guildId, OutputType outputType) {
|
||||||
|
String sql = "SELECT channel FROM output_channel WHERE guild = ? AND output_type = ?";
|
||||||
|
try {
|
||||||
|
PreparedStatement preparedStatement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||||
|
preparedStatement.setLong(1, guildId);
|
||||||
|
preparedStatement.setString(2, outputType.name());
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
if (resultSet.next())
|
||||||
|
return resultSet.getLong("channel");
|
||||||
|
else
|
||||||
|
return 0L;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Logger.exception(e);
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package com.alttd.database.queries.commandOutputChannels;
|
||||||
|
|
||||||
|
public enum OutputType {
|
||||||
|
SUGGESTION,
|
||||||
|
SUGGESTION_REVIEW
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,21 @@
|
||||||
package com.alttd.modalManager.modals;
|
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.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.MessageEmbed;
|
||||||
|
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||||
import net.dv8tion.jda.api.interactions.components.Modal;
|
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.TextInput;
|
||||||
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle;
|
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle;
|
||||||
|
import net.dv8tion.jda.api.interactions.modals.ModalMapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ModalSuggestion extends DiscordModal {
|
public class ModalSuggestion extends DiscordModal {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -15,6 +25,38 @@ public class ModalSuggestion extends DiscordModal {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(ModalInteractionEvent event) {
|
public void execute(ModalInteractionEvent event) {
|
||||||
|
List<ModalMapping> modalMappings = event.getValues();
|
||||||
|
if (modalMappings.size() != 2) {
|
||||||
|
event.replyEmbeds(Util.genericErrorEmbed("Error",
|
||||||
|
"Found the wrong number of fields in your form input")).setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String title = modalMappings.get(0).getAsString();
|
||||||
|
String desc = modalMappings.get(1).getAsString();
|
||||||
|
|
||||||
|
Guild guild = event.getGuild();
|
||||||
|
if (guild == null) {
|
||||||
|
event.replyEmbeds(Util.genericErrorEmbed("Error", "Couldn't find this guild")).setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GuildMessageChannel channel = guild.getChannelById(GuildMessageChannel.class, CommandOutputChannels.getOutputChannel(guild.getIdLong(), OutputType.SUGGESTION_REVIEW));
|
||||||
|
if (channel == null) {
|
||||||
|
event.replyEmbeds(Util.genericErrorEmbed("Error",
|
||||||
|
"This guild does not have a suggestion review channel or it's not the right channel type")).setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO add user tag in description
|
||||||
|
MessageEmbed reviewMessage = new EmbedBuilder().setTitle("New suggestion").appendDescription("USER").addField(title, desc, false).build();
|
||||||
|
channel.sendMessageEmbeds(reviewMessage).queue(success -> success.addReaction(null /*TODO FIX EMOTE this should be buttons*/).queue(aa -> {
|
||||||
|
MessageEmbed responseEmbed = new EmbedBuilder().setTitle("Your submitted suggestion").addField(title, desc, false).build();
|
||||||
|
event.replyEmbeds(responseEmbed).setEphemeral(true).queue();
|
||||||
|
//TODO this should have something incase it errors
|
||||||
|
}), failure -> {
|
||||||
|
event.replyEmbeds(Util.genericErrorEmbed("Error", "Couldn't submit suggestion for review")).setEphemeral(true).queue();
|
||||||
|
//TODO include their suggestion in this error (you can send more than one embed)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user