mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-26 13:46:19 +00:00
added conventions for templated commands, to reduce the amount of necessary configuration
added an exception, in case the command was missing the correct types of parameters (channel is required, no channel was found) added fix text to exception handler, in case the message of an exception is null fixed off-by-one error when searching the missing parameter changed supported chanel from guildChannel to textChannel for posttarget added slowmode command
This commit is contained in:
@@ -10,9 +10,9 @@ import dev.sheldan.abstracto.core.management.PostTargetManagement;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.GuildChannel;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -39,7 +39,7 @@ public class SetPostTargetCommand implements Command {
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter channel = Parameter.builder().name("channel").type(GuildChannel.class).description("The channel to post towards").build();
|
||||
Parameter channel = Parameter.builder().name("channel").type(TextChannel.class).description("The channel to post towards").build();
|
||||
Parameter postTargetName = Parameter.builder().name("name").type(String.class).description("The name of the post target to redirect").build();
|
||||
List<Parameter> parameters = Arrays.asList(postTargetName, channel);
|
||||
return CommandConfiguration.builder()
|
||||
|
||||
@@ -61,20 +61,35 @@ public class Help implements Command {
|
||||
CommandConfiguration commandConfiguration = command.getConfiguration();
|
||||
sb.append(String.format("Command: **%s**", commandConfiguration.getName()));
|
||||
sb.append("\n");
|
||||
sb.append(String.format("Description: %s", getTemplateOrDefault(commandConfiguration.getDescriptionTemplate(), commandConfiguration.getDescription())));
|
||||
String descriptionTemplate = getDescriptionTemplate(commandConfiguration.getName());
|
||||
sb.append(String.format("Description: %s", getTemplateOrDefault(commandConfiguration, descriptionTemplate, commandConfiguration.getDescription())));
|
||||
sb.append("\n");
|
||||
HelpInfo helpObj = commandConfiguration.getHelp();
|
||||
if(helpObj != null){
|
||||
sb.append(String.format("Usage: %s", getTemplateOrDefault(helpObj.getUsageTemplate(), helpObj.getUsage())));
|
||||
String usageTemplate = getUsageTemplate(commandConfiguration.getName());
|
||||
sb.append(String.format("Usage: %s", getTemplateOrDefault(commandConfiguration, usageTemplate, helpObj.getUsage())));
|
||||
sb.append("\n");
|
||||
sb.append(String.format("Detailed help: %s", getTemplateOrDefault(helpObj.getLongHelpTemplate(), helpObj.getLongHelp())));
|
||||
String longHelpTemplate = getLongHelpTemplate(commandConfiguration.getName());
|
||||
sb.append(String.format("Detailed help: %s", getTemplateOrDefault(commandConfiguration, longHelpTemplate, helpObj.getLongHelp())));
|
||||
sb.append("\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String getTemplateOrDefault(String templateKey, String defaultText) {
|
||||
if(templateKey == null) {
|
||||
private String getDescriptionTemplate(String commandName) {
|
||||
return commandName + "_description";
|
||||
}
|
||||
|
||||
private String getUsageTemplate(String commandName) {
|
||||
return commandName + "_usage";
|
||||
}
|
||||
|
||||
private String getLongHelpTemplate(String commandName) {
|
||||
return commandName + "_long_help";
|
||||
}
|
||||
|
||||
private String getTemplateOrDefault(CommandConfiguration commandConfiguration, String templateKey, String defaultText) {
|
||||
if(templateKey == null || !commandConfiguration.isTemplated()) {
|
||||
return defaultText;
|
||||
} else {
|
||||
return templateService.renderTemplate(templateKey, null);
|
||||
|
||||
@@ -37,11 +37,11 @@ public class Echo implements Command {
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
parameters.add(Parameter.builder().name("input").type(String.class).remainder(true).build());
|
||||
HelpInfo helpInfo = HelpInfo.builder().usageTemplate("echo_usage").longHelpTemplate("echo_long_help").build();
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("echo")
|
||||
.module("utility")
|
||||
.descriptionTemplate("echo_description")
|
||||
.templated(true)
|
||||
.causesReaction(false)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Ping implements Command {
|
||||
return CommandConfiguration.builder()
|
||||
.name("ping")
|
||||
.module("utility")
|
||||
.descriptionTemplate("ping_description")
|
||||
.templated(true)
|
||||
.causesReaction(false)
|
||||
.build();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user