Added what's needed to execute the add subcommand except storing the data
This commit is contained in:
parent
27122538e4
commit
f664f3624e
|
|
@ -2,9 +2,18 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.config.MessagesConfig;
|
||||||
|
import com.alttd.templates.Parser;
|
||||||
|
import com.alttd.templates.Template;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import com.alttd.util.Util;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.*;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
public class SubCommandAdd extends SubCommand {
|
public class SubCommandAdd extends SubCommand {
|
||||||
|
|
||||||
|
|
@ -20,11 +29,55 @@ public class SubCommandAdd extends SubCommand {
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandInteractionEvent event) {
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
||||||
if (channel == null)
|
Member member = event.getMember();
|
||||||
|
if (member == null) {
|
||||||
|
event.replyEmbeds(Util.genericErrorEmbed("Error", "Unable to find valid guild member."))
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!Util.validateGuildMessageChannel(event.getInteraction(), channel, ChannelType.TEXT, member))
|
||||||
return;
|
return;
|
||||||
String title = OptionMappingParsing.getString("title", event, getName());
|
String title = OptionMappingParsing.getString("title", event, getName());
|
||||||
if (title == null)
|
if (title == null) {
|
||||||
|
event.replyEmbeds(Util.genericErrorEmbed("Error", "Unable to retrieve title."))
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
if (title.length() > 256) {
|
||||||
|
event.replyEmbeds(Util.genericErrorEmbed("Error", "Title is too long, max 256 characters."))
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.replyEmbeds(Util.genericWaitingEmbed("Creating Poll...", null))
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue(result -> createPoll(channel, title, result));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createPoll(GuildMessageChannel channel, String title, InteractionHook hook) {
|
||||||
|
channel.sendMessageEmbeds(new EmbedBuilder()
|
||||||
|
.setTitle(title)
|
||||||
|
.setColor(Color.RED)
|
||||||
|
.build()
|
||||||
|
).queue(message -> createdPoll(message, hook), throwable -> failedCreatingPoll(throwable, hook));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createdPoll(Message message, InteractionHook hook) {
|
||||||
|
hook.editOriginalEmbeds(Util.genericSuccessEmbed("Created Poll!",
|
||||||
|
Parser.parse("Created a poll with the message id: `<message_id>`. " +
|
||||||
|
"When you're ready don't forget to open the poll!",
|
||||||
|
Template.of("message_id", message.getId()))))
|
||||||
|
.queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void failedCreatingPoll(Throwable throwable, InteractionHook hook) {
|
||||||
|
Logger.warning(throwable.getMessage());
|
||||||
|
hook.editOriginalEmbeds(Util.genericErrorEmbed("Failed to create Poll",
|
||||||
|
"Unable to create poll, please contact an Admin."))
|
||||||
|
.queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user