Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/main/java/de/presti/ree6/commands/CommandEvent.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package de.presti.ree6.commands;

import de.presti.ree6.main.Main;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -71,6 +75,65 @@ public CommandEvent(@Nonnull Member member, @Nonnull Guild guild, @Nullable Mess
this.slashCommandInteractionEvent = slashCommandInteractionEvent;
}

/**
* Reply to the Command execution.
* @param message the Message to reply with.
*/
public void reply (String message) {
MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder();
messageCreateBuilder.setContent(message);
reply(messageCreateBuilder.build());
}

/**
* Reply to the Command execution.
* @param message the Message to reply with.
* @param deleteSecond the Seconds to delete the Message after.
*/
public void reply (String message, int deleteSecond) {
MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder();
messageCreateBuilder.setContent(message);
reply(messageCreateBuilder.build(), deleteSecond);
}

/**
* Reply to the Command execution.
* @param message the Message to reply with.
*/
public void reply (MessageEmbed message) {
MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder();
messageCreateBuilder.setEmbeds(message);
reply(messageCreateBuilder.build());
}

/**
* Reply to the Command execution.
* @param message the Message to reply with.
* @param deleteSecond the Seconds to delete the Message after.
*/
public void reply (MessageEmbed message, int deleteSecond) {
MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder();
messageCreateBuilder.setEmbeds(message);
reply(messageCreateBuilder.build(), deleteSecond);
}

/**
* Reply to the Command execution.
* @param message the Message to reply with.
*/
public void reply(MessageCreateData message) {
Main.getInstance().getCommandManager().sendMessage(message, getChannel(), getInteractionHook());
}

/**
* Reply to the Command execution.
* @param message the Message to reply with.
* @param deleteSecond the Seconds to delete the Message after.
*/
public void reply(MessageCreateData message, int deleteSecond) {
Main.getInstance().getCommandManager().sendMessage(message, deleteSecond, getChannel(), getInteractionHook());
}

/**
* Get the {@link Member} Entity associated with the Event.
* @return the {@link Member} Entity.
Expand Down
105 changes: 105 additions & 0 deletions src/main/java/de/presti/ree6/commands/impl/mod/EmbedSender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package de.presti.ree6.commands.impl.mod;

import de.presti.ree6.commands.Category;
import de.presti.ree6.commands.CommandEvent;
import de.presti.ree6.commands.interfaces.Command;
import de.presti.ree6.commands.interfaces.ICommand;
import de.presti.ree6.main.Main;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.internal.interactions.CommandDataImpl;

import java.awt.*;
import java.time.Instant;

/**
* Command to send an Embed.
*/
@Command(name = "embed", description = "Send an Embed!", category = Category.MOD)
public class EmbedSender implements ICommand {

/**
* {@inheritDoc}
*/
@Override
public void onPerform(CommandEvent commandEvent) {
if (!commandEvent.isSlashCommand()) {
commandEvent.reply("This command is only available as slash command!");
return;
}

OptionMapping title = commandEvent.getSlashCommandInteractionEvent().getOption("title");
OptionMapping description = commandEvent.getSlashCommandInteractionEvent().getOption("description");
OptionMapping color = commandEvent.getSlashCommandInteractionEvent().getOption("color");
OptionMapping footer = commandEvent.getSlashCommandInteractionEvent().getOption("footer");
OptionMapping footer_Icon = commandEvent.getSlashCommandInteractionEvent().getOption("footer_icon");
OptionMapping image = commandEvent.getSlashCommandInteractionEvent().getOption("image");
OptionMapping thumbnail = commandEvent.getSlashCommandInteractionEvent().getOption("thumbnail");
OptionMapping author = commandEvent.getSlashCommandInteractionEvent().getOption("author");
OptionMapping author_Url = commandEvent.getSlashCommandInteractionEvent().getOption("author_url");
OptionMapping author_Icon = commandEvent.getSlashCommandInteractionEvent().getOption("author_icon");
OptionMapping url = commandEvent.getSlashCommandInteractionEvent().getOption("url");
OptionMapping timestamp = commandEvent.getSlashCommandInteractionEvent().getOption("timestamp");

EmbedBuilder embedBuilder = new EmbedBuilder();

embedBuilder.setTitle(title != null ? title.getAsString() : "Invalid Title", url != null ? url.getAsString() : null);
embedBuilder.setDescription(description != null ? description.getAsString() : "Invalid description");

if (color != null) {
embedBuilder.setColor(new Color(color.getAsInt()));
}

if (footer != null) {
embedBuilder.setFooter(footer.getAsString(), footer_Icon != null ? footer_Icon.getAsString() : null);
}

if (image != null) {
embedBuilder.setImage(image.getAsString());
}

if (thumbnail != null) {
embedBuilder.setThumbnail(thumbnail.getAsString());
}

if (author != null) {
embedBuilder.setAuthor(author.getAsString(), author_Url != null ? author_Url.getAsString() : null, author_Icon != null ? author_Icon.getAsString() : null);
}

if (timestamp != null) {
embedBuilder.setTimestamp(Instant.ofEpochMilli(timestamp.getAsLong()));
}

Main.getInstance().getCommandManager().sendMessage(embedBuilder, commandEvent.getChannel());
}

/**
* {@inheritDoc}
*/
@Override
public CommandData getCommandData() {
return new CommandDataImpl("embed", "Send an Embed!")
.addOption(OptionType.STRING, "title", "The title of the embed!", true)
.addOption(OptionType.STRING, "description", "The description of the embed!", true)
.addOption(OptionType.INTEGER, "color", "The color of the embed!", false)
.addOption(OptionType.STRING, "footer", "The footer of the embed!", false)
.addOption(OptionType.STRING, "footer_icon", "The footer icon of the embed!", false)
.addOption(OptionType.STRING, "image", "The image of the embed!", false)
.addOption(OptionType.STRING, "thumbnail", "The thumbnail of the embed!", false)
.addOption(OptionType.STRING, "author", "The author of the embed!", false)
.addOption(OptionType.STRING, "author_url", "The author url of the embed!", false)
.addOption(OptionType.STRING, "author_icon", "The author icon of the embed!", false)
.addOption(OptionType.STRING, "url", "The url of the embed!", false)
.addOption(OptionType.NUMBER, "timestamp", "The timestamp of the embed!", false);
}

/**
* {@inheritDoc}
*/
@Override
public String[] getAlias() {
return new String[0];
}
}