Skip to content

Commit

Permalink
Merge pull request #104 from Ree6-Applications/rework/menu
Browse files Browse the repository at this point in the history
Menu Improvment.
  • Loading branch information
DxsSucuk authored Sep 15, 2022
2 parents 13ff4d5 + 509fe05 commit ed13ba5
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 83 deletions.
42 changes: 34 additions & 8 deletions src/main/java/de/presti/ree6/commands/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,60 @@ public enum Category {
/**
* Category used for informativ Commands.
*/
INFO,
INFO("re_icon_info",1019221661070917632L, false, "Used to gather information or provide information."),
/**
* Category used for moderativ Commands.
*/
MOD,
MOD("re_icon_mod",1019221710932803624L, false, "Moderation Tools that can help you manager Users or prevent rule breaking on the Server."),
/**
* Category used for music Commands.
*/
MUSIC,
MUSIC("re_icon_music",1019221781762023575L, false, "Music utilities that allow you to have fun with your friends through the power of music!"),
/**
* Category used for fun Commands.
*/
FUN,
FUN("re_icon_fun",1019221814670532628L, false, "Fun utilities that give you the power to do dumb stuff because you can!"),
/**
* Category used for level Commands.
*/
LEVEL,
LEVEL("re_icon_level",1019221845972635809L, false, "Leveling Tools that allow you to keep track of progress on the Server."),
/**
* Category used for community Commands.
*/
COMMUNITY,
COMMUNITY("re_icon_community",1019221884686057552L, false, "Community Tools that allow you to interact with your community."),
/**
* Category used for NSFW Commands.
*/
NSFW,
NSFW("re_icon_nsfw",1019221923466584166L, false, "NSFW stuff that you can only use in NSFW Channels."),
/**
* Category used for admin Commands.
*/
HIDDEN
HIDDEN("re_icon_hidden",1019221957817933865L, false, "Hidden Commands that are only visible to the Owner of the Bot.");

private final String icon;
private final long iconId;
private final boolean iconAnimated;
private final String description;
Category(String icon, long iconId, boolean iconAnimated, String description) {
this.icon = icon;
this.iconId = iconId;
this.iconAnimated = iconAnimated;
this.description = description;
}

public String getIcon() {
return icon;
}

public long getIconId() {
return iconId;
}

public boolean isIconAnimated() {
return iconAnimated;
}

public String getDescription() {
return description;
}
}
145 changes: 100 additions & 45 deletions src/main/java/de/presti/ree6/commands/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import org.reflections.Reflections;

Expand All @@ -41,10 +43,10 @@ public class CommandManager {
* Constructor for the Command-Manager used to register every Command.
*
* @throws CommandInitializerException if an error occurs while initializing the Commands.
* @throws IllegalStateException if an Invalid Command was used to initialize.
* @throws IllegalAccessException when an Instance of a Command is not accessible.
* @throws InstantiationException when an Instance of a Command is not instantiable.
* @throws NoSuchMethodException when a Constructor Instance of a Command is not found.
* @throws IllegalStateException if an Invalid Command was used to initialize.
* @throws IllegalAccessException when an Instance of a Command is not accessible.
* @throws InstantiationException when an Instance of a Command is not instantiable.
* @throws NoSuchMethodException when a Constructor Instance of a Command is not found.
*/
public CommandManager() throws CommandInitializerException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
Main.getInstance().getLogger().info("Initializing Commands!");
Expand Down Expand Up @@ -206,11 +208,12 @@ public boolean perform(Member member, Guild guild, String messageContent, Messag

/**
* Perform a Message based Command.
* @param member the Member that performed the command.
* @param guild the Guild the Member is from.
*
* @param member the Member that performed the command.
* @param guild the Guild the Member is from.
* @param messageContent the Message content (including the prefix + command name).
* @param message the Message Entity.
* @param textChannel the TextChannel where the command has been performed.
* @param message the Message Entity.
* @param textChannel the TextChannel where the command has been performed.
* @return true, if a command has been performed.
*/
private boolean performMessageCommand(Member member, Guild guild, String messageContent, Message message, MessageChannelUnion textChannel) {
Expand Down Expand Up @@ -258,7 +261,7 @@ private boolean performMessageCommand(Member member, Guild guild, String message
/**
* Call when a slash command has been performed.
*
* @param textChannel the TextChannel where the command has been performed.
* @param textChannel the TextChannel where the command has been performed.
* @param slashCommandInteractionEvent the Slash-Command Event.
*/
private boolean performSlashCommand(MessageChannelUnion textChannel, SlashCommandInteractionEvent slashCommandInteractionEvent) {
Expand All @@ -285,21 +288,101 @@ private boolean performSlashCommand(MessageChannelUnion textChannel, SlashComman

/**
* Check if an User is time-outed.
*
* @param user the User.
* @return true, if yes | false, if not.
*/
public boolean isTimeout(User user) {
return ArrayUtil.commandCooldown.contains(user.getId()) && BotWorker.getVersion() != BotVersion.DEVELOPMENT_BUILD;
}

/**
* Send a message to a special Message-Channel.
*
* @param messageCreateData the Message content.
* @param commandEvent the Command-Event.
*/
public void sendMessage(MessageCreateData messageCreateData, CommandEvent commandEvent) {
sendMessage(messageCreateData, commandEvent.getChannel(), commandEvent.getInteractionHook());
}

/**
* Send a message to a special Message-Channel.
*
* @param messageCreateData the Message content.
* @param deleteSecond the delete delay
* @param commandEvent the Command-Event.
*/
public void sendMessage(MessageCreateData messageCreateData, int deleteSecond, CommandEvent commandEvent) {
sendMessage(messageCreateData, deleteSecond, commandEvent.getChannel(), commandEvent.getInteractionHook());
}

/**
* Send a message to a special Message-Channel.
*
* @param messageCreateData the Message content.
* @param messageChannel the Message-Channel.
*/
public void sendMessage(MessageCreateData messageCreateData, MessageChannel messageChannel) {
sendMessage(messageCreateData, messageChannel, null);
}

/**
* Send a message to a special Message-Channel, with a deletion delay.
*
* @param messageCreateData the Message content.
* @param deleteSecond the delete delay
* @param messageChannel the Message-Channel.
*/
public void sendMessage(MessageCreateData messageCreateData, int deleteSecond, MessageChannel messageChannel) {
sendMessage(messageCreateData, deleteSecond, messageChannel, null);
}

/**
* Send a message to a special Message-Channel.
*
* @param messageCreateData the Message content.
* @param messageChannel the Message-Channel.
* @param interactionHook the Interaction-hook if it is a slash command.
*/
public void sendMessage(MessageCreateData messageCreateData, MessageChannel messageChannel, InteractionHook interactionHook) {
if (interactionHook == null) {
if (messageChannel.canTalk()) messageChannel.sendMessage(messageCreateData).queue();
} else interactionHook.sendMessage(messageCreateData).queue();
}

/**
* Send a message to a special Message-Channel, with a deletion delay.
*
* @param messageCreateData the Message content.
* @param messageChannel the Message-Channel.
* @param interactionHook the Interaction-hook if it is a slash command.
* @param deleteSecond the delete delay
*/
public void sendMessage(MessageCreateData messageCreateData, int deleteSecond, MessageChannel messageChannel, InteractionHook interactionHook) {
if (interactionHook == null) {
if (messageChannel == null) return;
if (messageChannel.canTalk())
messageChannel.sendMessage(messageCreateData).delay(deleteSecond, TimeUnit.SECONDS).flatMap(message -> {
if (message != null && message.getChannel().retrieveMessageById(message.getId()).complete() != null) {
return message.delete();
}

return null;
}).queue();
} else {
interactionHook.sendMessage(messageCreateData).queue();
}
}

/**
* Send a message to a special Message-Channel.
*
* @param message the Message content.
* @param messageChannel the Message-Channel.
*/
public void sendMessage(String message, MessageChannel messageChannel) {
if (messageChannel.canTalk()) sendMessage(message, messageChannel, null);
sendMessage(message, messageChannel, null);
}

/**
Expand All @@ -310,7 +393,7 @@ public void sendMessage(String message, MessageChannel messageChannel) {
* @param messageChannel the Message-Channel.
*/
public void sendMessage(String message, int deleteSecond, MessageChannel messageChannel) {
if (messageChannel.canTalk()) sendMessage(message, deleteSecond, messageChannel, null);
sendMessage(message, deleteSecond, messageChannel, null);
}

/**
Expand All @@ -321,9 +404,7 @@ public void sendMessage(String message, int deleteSecond, MessageChannel message
* @param interactionHook the Interaction-hook if it is a slash command.
*/
public void sendMessage(String message, MessageChannel messageChannel, InteractionHook interactionHook) {
if (interactionHook == null) {
if (messageChannel.canTalk()) messageChannel.sendMessage(message).queue();
} else interactionHook.sendMessage(message).queue();
sendMessage(new MessageCreateBuilder().setContent(message).build(), messageChannel, interactionHook);
}

/**
Expand All @@ -335,19 +416,7 @@ public void sendMessage(String message, MessageChannel messageChannel, Interacti
* @param deleteSecond the delete delay
*/
public void sendMessage(String messageContent, int deleteSecond, MessageChannel messageChannel, InteractionHook interactionHook) {
if (interactionHook == null) {
if (messageChannel == null) return;
if (messageChannel.canTalk())
messageChannel.sendMessage(messageContent).delay(deleteSecond, TimeUnit.SECONDS).flatMap(message -> {
if (message != null && message.getChannel().retrieveMessageById(message.getId()).complete() != null) {
return message.delete();
}

return null;
}).queue();
} else {
interactionHook.sendMessage(messageContent).queue();
}
sendMessage(new MessageCreateBuilder().setContent(messageContent).build(), deleteSecond, messageChannel, interactionHook);
}

/**
Expand All @@ -357,7 +426,7 @@ public void sendMessage(String messageContent, int deleteSecond, MessageChannel
* @param messageChannel the Message-Channel.
*/
public void sendMessage(EmbedBuilder embedBuilder, MessageChannel messageChannel) {
if (messageChannel.canTalk()) sendMessage(embedBuilder, messageChannel, null);
sendMessage(embedBuilder, messageChannel, null);
}

/**
Expand All @@ -368,7 +437,7 @@ public void sendMessage(EmbedBuilder embedBuilder, MessageChannel messageChannel
* @param messageChannel the Message-Channel.
*/
public void sendMessage(EmbedBuilder embedBuilder, int deleteSecond, MessageChannel messageChannel) {
if (messageChannel.canTalk()) sendMessage(embedBuilder, deleteSecond, messageChannel, null);
sendMessage(embedBuilder, deleteSecond, messageChannel, null);
}

/**
Expand All @@ -379,9 +448,7 @@ public void sendMessage(EmbedBuilder embedBuilder, int deleteSecond, MessageChan
* @param interactionHook the Interaction-hook if it is a slash command.
*/
public void sendMessage(EmbedBuilder embedBuilder, MessageChannel messageChannel, InteractionHook interactionHook) {
if (interactionHook == null) {
if (messageChannel.canTalk()) messageChannel.sendMessageEmbeds(embedBuilder.build()).queue();
} else interactionHook.sendMessageEmbeds(embedBuilder.build()).queue();
sendMessage(new MessageCreateBuilder().setEmbeds(embedBuilder.build()).build(), messageChannel, interactionHook);
}

/**
Expand All @@ -393,19 +460,7 @@ public void sendMessage(EmbedBuilder embedBuilder, MessageChannel messageChannel
* @param interactionHook the Interaction-hook if it is a slash command.
*/
public void sendMessage(EmbedBuilder embedBuilder, int deleteSecond, MessageChannel messageChannel, InteractionHook interactionHook) {
if (interactionHook == null) {
if (messageChannel == null) return;
if (messageChannel.canTalk())
messageChannel.sendMessageEmbeds(embedBuilder.build()).delay(deleteSecond, TimeUnit.SECONDS).flatMap(message -> {
if (message != null && message.getChannel().retrieveMessageById(message.getId()).complete() != null) {
return message.delete();
}

return null;
}).queue();
} else {
interactionHook.sendMessageEmbeds(embedBuilder.build()).queue();
}
sendMessage(new MessageCreateBuilder().setEmbeds(embedBuilder.build()).build(), deleteSecond, messageChannel, interactionHook);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void onPerform(CommandEvent commandEvent) {
if (commandEvent.getArguments()[0].equalsIgnoreCase("remove")) {
Main.getInstance().getSqlConnector().getSqlWorker().removeBirthday(commandEvent.getGuild().getId(), commandEvent.getMember().getId());
Main.getInstance().getCommandManager().sendMessage("Your Birthday has been removed!", 5, commandEvent.getChannel(), commandEvent.getInteractionHook());

} else {
Main.getInstance().getCommandManager().sendMessage("Please use " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "birthday add/remove [Birthday(day.month.year)] [@User]", 5, commandEvent.getChannel(), commandEvent.getInteractionHook());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Addon implements ICommand {
public void onPerform(CommandEvent commandEvent) {
if(commandEvent.getMember().getUser().getId().equalsIgnoreCase("321580743488831490")) {
if (commandEvent.getArguments().length == 0) {

StringBuilder stringBuilder = new StringBuilder("```");
for (de.presti.ree6.addons.Addon addon : Main.getInstance().getAddonManager().addons) {
stringBuilder.append(addon.getName()).append("v").append(addon.getVersion())
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/de/presti/ree6/commands/impl/info/Credits.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import de.presti.ree6.commands.interfaces.Command;
import de.presti.ree6.commands.interfaces.ICommand;
import de.presti.ree6.main.Main;
import de.presti.ree6.utils.others.RandomUtils;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;

/**
* A command to give credits.
Expand All @@ -18,8 +21,10 @@ public class Credits implements ICommand {
*/
@Override
public void onPerform(CommandEvent commandEvent) {
Main.getInstance().getCommandManager().sendMessage("Lead Developer : Presti | 平和#0240\nSupport Developer : xazed | xazed#5014\ndavid. | david.#3120",
commandEvent.getChannel(), commandEvent.getInteractionHook());
MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder();
messageCreateBuilder.addActionRow(Button.link("https://www.ree6.de/#team",
"Meet " + (RandomUtils.secureRandom.nextInt(10000) == 1562 ? "the Spy" : "our Team") + "!"));
Main.getInstance().getCommandManager().sendMessage(messageCreateBuilder.build(), commandEvent);
}

/**
Expand Down
Loading

0 comments on commit ed13ba5

Please sign in to comment.