Skip to content

Commit

Permalink
Bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
DxsSucuk committed Oct 25, 2022
1 parent dd5d75b commit b9e77ee
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
12 changes: 5 additions & 7 deletions src/main/java/de/presti/ree6/commands/CommandEvent.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.presti.ree6.commands;

import de.presti.ree6.commands.interfaces.ICommand;
import de.presti.ree6.language.LanguageService;
import de.presti.ree6.main.Main;
import lombok.Getter;
Expand All @@ -25,11 +24,10 @@
public class CommandEvent {

/**
* The Command that has been executed.
* The Name of Command that has been executed.
*/
@Getter
@Nonnull
ICommand iCommand;
String command;

/**
* The Member associated with the Command execution.
Expand Down Expand Up @@ -70,16 +68,16 @@ public class CommandEvent {
/**
* Constructor used to save the Data.
*
* @param iCommand the {@link ICommand}
* @param command the Command Name.
* @param member the {@link Member} Entity.
* @param guild the {@link Guild} Entity.
* @param message the {@link Message} Entity.
* @param textChannel the {@link TextChannel} Entity.
* @param arguments the given Arguments.
* @param slashCommandInteractionEvent the {@link SlashCommandInteractionEvent} Entity.
*/
public CommandEvent(@Nonnull ICommand iCommand, @Nonnull Member member, @Nonnull Guild guild, @Nullable Message message, @Nonnull MessageChannelUnion textChannel, @Nullable String[] arguments, @Nullable SlashCommandInteractionEvent slashCommandInteractionEvent) {
this.iCommand = iCommand;
public CommandEvent(String command, @Nonnull Member member, @Nonnull Guild guild, @Nullable Message message, @Nonnull MessageChannelUnion textChannel, @Nullable String[] arguments, @Nullable SlashCommandInteractionEvent slashCommandInteractionEvent) {
this.command = command;
this.member = member;
this.guild = guild;
this.message = message;
Expand Down
52 changes: 35 additions & 17 deletions src/main/java/de/presti/ree6/commands/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,48 @@ public void addSlashCommand(JDA jda) {
commandData = new CommandDataImpl(command.getClass().getAnnotation(Command.class).name(), command.getClass().getAnnotation(Command.class).description());
}

for (DiscordLocale discordLocale : DiscordLocale.values()) {
if (!LanguageService.languageResources.containsKey(discordLocale)) continue;
if (commandData instanceof CommandDataImpl commandData1) {

String description = LanguageService.getByLocale(discordLocale, command.getClass().getAnnotation(Command.class).description() + "_slash");
for (DiscordLocale discordLocale : DiscordLocale.values()) {
if (!LanguageService.languageResources.containsKey(discordLocale)) continue;

String description = LanguageService.getByLocale(discordLocale, command.getClass().getAnnotation(Command.class).description() + "_slash");
if (description.equals("Missing language resource!")) {
description = LanguageService.getByLocale(discordLocale, command.getClass().getAnnotation(Command.class).description());
}

if (!description.equals("Missing language resource!")) {
commandData1.setDescriptionLocalization(discordLocale, description);
}
}

String description = LanguageService.getDefault(command.getClass().getAnnotation(Command.class).description() + "_slash");
if (description.equals("Missing language resource!")) {
description = LanguageService.getByLocale(discordLocale, command.getClass().getAnnotation(Command.class).description());
description = LanguageService.getDefault(command.getClass().getAnnotation(Command.class).description());
}

if (!description.equals("Missing language resource!")) {
if (commandData instanceof CommandDataImpl commandData1) {
commandData1.setDescriptionLocalization(discordLocale, description);
}
commandData1.setDescription(description);
}
}

if (commandAnnotation.category() == Category.MOD && commandData.getDefaultPermissions() == DefaultMemberPermissions.ENABLED) {
commandData.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.ADMINISTRATOR));
}
if (commandAnnotation.category() == Category.MOD && commandData.getDefaultPermissions() == DefaultMemberPermissions.ENABLED) {
commandData1.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.ADMINISTRATOR));
}

commandData.setGuildOnly(true);
commandData1.setGuildOnly(true);

//noinspection ResultOfMethodCallIgnored
listUpdateAction.addCommands(commandData);
//noinspection ResultOfMethodCallIgnored
listUpdateAction.addCommands(commandData1);
} else {
if (commandAnnotation.category() == Category.MOD && commandData.getDefaultPermissions() == DefaultMemberPermissions.ENABLED) {
commandData.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.ADMINISTRATOR));
}

commandData.setGuildOnly(true);

//noinspection ResultOfMethodCallIgnored
listUpdateAction.addCommands(commandData);
}
}

listUpdateAction.queue();
Expand Down Expand Up @@ -279,7 +298,7 @@ private boolean performMessageCommand(Member member, Guild guild, String message
String[] argumentsParsed = Arrays.copyOfRange(arguments, 1, arguments.length);

// Perform the Command.
command.onASyncPerform(new CommandEvent(command, member, guild, message, textChannel, argumentsParsed, null));
command.onASyncPerform(new CommandEvent(command.getClass().getAnnotation(Command.class).name(), member, guild, message, textChannel, argumentsParsed, null));

return true;
}
Expand All @@ -289,7 +308,6 @@ private boolean performMessageCommand(Member member, Guild guild, String message
*
* @param textChannel the TextChannel where the command has been performed.
* @param slashCommandInteractionEvent the Slash-Command Event.
*
* @return true, if a command has been performed.
*/
private boolean performSlashCommand(MessageChannelUnion textChannel, SlashCommandInteractionEvent slashCommandInteractionEvent) {
Expand All @@ -309,7 +327,7 @@ private boolean performSlashCommand(MessageChannelUnion textChannel, SlashComman
}

// Perform the Command.
command.onASyncPerform(new CommandEvent(command, slashCommandInteractionEvent.getMember(), slashCommandInteractionEvent.getGuild(), null, textChannel, null, slashCommandInteractionEvent));
command.onASyncPerform(new CommandEvent(command.getClass().getAnnotation(Command.class).name(), slashCommandInteractionEvent.getMember(), slashCommandInteractionEvent.getGuild(), null, textChannel, null, slashCommandInteractionEvent));

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ default void onASyncPerform(CommandEvent commandEvent) {
return null;
});
// Update Stats.
Main.getInstance().getSqlConnector().getSqlWorker().addStats(commandEvent.getGuild().getId(), commandEvent.getICommand().getClass().getAnnotation(Command.class).name());
Main.getInstance().getSqlConnector().getSqlWorker().addStats(commandEvent.getGuild().getId(), commandEvent.getCommand());
}

/**
Expand Down

0 comments on commit b9e77ee

Please sign in to comment.