added allowed roles, immune roles and restriction status to help command

This commit is contained in:
Sheldan
2020-04-28 21:32:20 +02:00
parent 65b693be7b
commit 6ed3a133e2
3 changed files with 34 additions and 0 deletions

View File

@@ -3,14 +3,19 @@ package dev.sheldan.abstracto.core.commands.help;
import dev.sheldan.abstracto.core.command.*;
import dev.sheldan.abstracto.core.command.config.*;
import dev.sheldan.abstracto.core.command.execution.*;
import dev.sheldan.abstracto.core.command.models.database.ACommand;
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
import dev.sheldan.abstracto.core.command.service.CommandRegistry;
import dev.sheldan.abstracto.core.command.service.ModuleRegistry;
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.config.features.CoreFeatures;
import dev.sheldan.abstracto.core.models.template.commands.help.HelpCommandDetailsModel;
import dev.sheldan.abstracto.core.models.template.commands.help.HelpModuleDetailsModel;
import dev.sheldan.abstracto.core.models.template.commands.help.HelpModuleOverviewModel;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.RoleService;
import dev.sheldan.abstracto.templating.model.MessageToSend;
import dev.sheldan.abstracto.templating.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,6 +41,15 @@ public class Help implements Command {
@Autowired
private CommandRegistry commandRegistry;
@Autowired
private CommandInServerManagementService commandInServerManagementService;
@Autowired
private CommandManagementService commandManagementService;
@Autowired
private RoleService roleService;
@Override
public CommandResult execute(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
@@ -59,7 +73,14 @@ public class Help implements Command {
channelService.sendMessageToEndInTextChannel(messageToSend, commandContext.getChannel());
} else if(commandRegistry.commandExists(parameter)) {
Command command = commandRegistry.getCommandByName(parameter);
ACommand aCommand = commandManagementService.findCommandByName(parameter);
ACommandInAServer aCommandInAServer = commandInServerManagementService.getCommandForServer(aCommand, commandContext.getUserInitiatedContext().getServer());
HelpCommandDetailsModel model = (HelpCommandDetailsModel) ContextConverter.fromCommandContext(commandContext, HelpCommandDetailsModel.class);
if(aCommandInAServer.getRestricted()) {
model.setImmuneRoles(roleService.getRolesFromGuild(aCommandInAServer.getImmuneRoles()));
model.setAllowedRoles(roleService.getRolesFromGuild(aCommandInAServer.getAllowedRoles()));
model.setRestricted(true);
}
model.setCommand(command.getConfiguration());
MessageToSend messageToSend = templateService.renderEmbedTemplate("help_command_details_response", model);
channelService.sendMessageToEndInTextChannel(messageToSend, commandContext.getChannel());

View File

@@ -25,6 +25,13 @@ Detailed help: ${command.help.longHelp}
<#if command.aliases?? && command.aliases?size gt 0>
Aliases: `${command.aliases?join("`, `")}`
</#if>
Restrictions:
<#if restricted?? && restricted>
Executable by:<#if allowedRoles??> <#list allowedRoles as allowedRole> ${allowedRole.asMention}<#sep>or<#else>Nobody</#list> </#if>
<#if immuneRoles?? > Immune roles: <#list immuneRoles as immuneRole> ${immuneRole.asMention}<#sep>or<#else>None</#list> </#if>
<#else>
Not restricted
</#if>
</#if>
Parameters:
<#if command.parameters??>

View File

@@ -5,10 +5,16 @@ import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import net.dv8tion.jda.api.entities.Role;
import java.util.List;
@Getter
@Setter
@SuperBuilder
public class HelpCommandDetailsModel extends UserInitiatedServerContext {
private CommandConfiguration command;
private List<Role> allowedRoles;
private List<Role> immuneRoles;
private Boolean restricted;
}