Skip to content

Commit

Permalink
[AB-xxx] adding ability to use different names for a user installable…
Browse files Browse the repository at this point in the history
… command
  • Loading branch information
Sheldan committed Jun 27, 2024
1 parent 6e01092 commit 79ea84d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public CommandConfiguration getConfiguration() {
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND_PUBLIC)
.userRootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND)
.commandName("get")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public CommandConfiguration getConfiguration() {
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND_PUBLIC)
.userRootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND)
.commandName("list")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -74,9 +75,9 @@ public void convertCommandConfigToCommandData(CommandConfiguration commandConfig
} else {
description = templateService.renderSimpleTemplate(internalCommandName + "_description", serverId);
}
String rootName = slashConfig.getSlashCompatibleRootName();
String groupName = slashConfig.getSlashCompatibleGroupName();
String commandName = slashConfig.getSlashCompatibleCommandName();
String rootName = userCommandsOnly ? StringUtils.defaultString(slashConfig.getUserSlashCompatibleRootName(), slashConfig.getSlashCompatibleRootName()) : slashConfig.getSlashCompatibleRootName();
String groupName = userCommandsOnly ? StringUtils.defaultString(slashConfig.getUserSlashCompatibleGroupName(), slashConfig.getSlashCompatibleGroupName()) : slashConfig.getSlashCompatibleGroupName();
String commandName = userCommandsOnly ? StringUtils.defaultString(slashConfig.getUserSlashCompatibleCommandName(), slashConfig.getSlashCompatibleCommandName()) : slashConfig.getSlashCompatibleCommandName();
Optional<SlashCommandData> existingRootCommand = existingCommands
.stream()
.filter(commandData -> commandData.getSecond().getName().equals(rootName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
public class SlashCommandConfig {
private boolean enabled;
private String rootCommandName;
private String userRootCommandName;
private String groupName;
private String userGroupName;
private String commandName;
private String userCommandName;

@Builder.Default
private boolean userInstallable = false;
Expand Down Expand Up @@ -46,4 +49,16 @@ public String getSlashCompatibleGroupName() {
public String getSlashCompatibleCommandName() {
return commandName != null ? commandName.toLowerCase(Locale.ROOT) : null;
}

public String getUserSlashCompatibleRootName() {
return userRootCommandName != null ? userRootCommandName.toLowerCase(Locale.ROOT) : null;
}

public String getUserSlashCompatibleGroupName() {
return userGroupName != null ? userGroupName.toLowerCase(Locale.ROOT) : null;
}

public String getUserSlashCompatibleCommandName() {
return userCommandName != null ? userCommandName.toLowerCase(Locale.ROOT) : null;
}
}

0 comments on commit 79ea84d

Please sign in to comment.