[AB-xxx] adding default permissions for commands

adding owner limitation for certain internal commands
This commit is contained in:
Sheldan
2025-02-15 15:33:56 +01:00
parent 210140b242
commit f99c5351e6
99 changed files with 516 additions and 184 deletions

View File

@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.exception.EntityGuildMismatchException;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.ChannelGroupService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
@@ -90,6 +91,7 @@ public class AddToChannelGroup extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(CoreSlashCommandNames.CHANNELS)
.commandName(ADD_TO_CHANNEL_GROUP_COMMAND)
.build();

View File

@@ -11,6 +11,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.database.ChannelGroupType;
import dev.sheldan.abstracto.core.service.ChannelGroupService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
@@ -82,6 +83,7 @@ public class CreateChannelGroup extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(CoreSlashCommandNames.CHANNELS)
.commandName(CREATE_CHANNEL_GROUP_COMMAND)
.build();

View File

@@ -11,6 +11,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.ChannelGroupService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@@ -70,6 +71,7 @@ public class DeleteChannelGroup extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(CoreSlashCommandNames.CHANNELS)
.commandName(DELETE_CHANNEL_GROUP_COMMAND)
.build();

View File

@@ -1,25 +1,25 @@
package dev.sheldan.abstracto.core.commands.channels;
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.service.ChannelGroupService;
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import dev.sheldan.abstracto.core.service.ChannelGroupService;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class DisableChannelGroup extends AbstractConditionableCommand {
@@ -49,40 +49,41 @@ public class DisableChannelGroup extends AbstractConditionableCommand {
String channelGroupName = slashCommandParameterService.getCommandOption(CHANNEL_GROUP_NAME_PARAMETER, event, String.class);
channelGroupService.disableChannelGroup(channelGroupName, event.getGuild().getIdLong());
return interactionService.replyEmbed(DISABLE_CHANNEL_GROUP_RESPONSE, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@Override
public CommandConfiguration getConfiguration() {
Parameter channelGroupName = Parameter
.builder()
.name(CHANNEL_GROUP_NAME_PARAMETER)
.type(String.class)
.templated(true)
.build();
.builder()
.name(CHANNEL_GROUP_NAME_PARAMETER)
.type(String.class)
.templated(true)
.build();
List<Parameter> parameters = Arrays.asList(channelGroupName);
HelpInfo helpInfo = HelpInfo
.builder()
.templated(true)
.build();
.builder()
.templated(true)
.build();
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.CHANNELS)
.commandName(DISABLE_CHANNEL_GROUP_COMMAND)
.build();
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(CoreSlashCommandNames.CHANNELS)
.commandName(DISABLE_CHANNEL_GROUP_COMMAND)
.build();
return CommandConfiguration.builder()
.name(DISABLE_CHANNEL_GROUP_COMMAND)
.module(ChannelsModuleDefinition.CHANNELS)
.parameters(parameters)
.slashCommandConfig(slashCommandConfig)
.supportsEmbedException(true)
.help(helpInfo)
.templated(true)
.causesReaction(true)
.build();
.name(DISABLE_CHANNEL_GROUP_COMMAND)
.module(ChannelsModuleDefinition.CHANNELS)
.parameters(parameters)
.slashCommandConfig(slashCommandConfig)
.supportsEmbedException(true)
.help(helpInfo)
.templated(true)
.causesReaction(true)
.build();
}
@Override

View File

@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.exception.PostTargetNotValidException;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.PostTargetService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@@ -77,6 +78,7 @@ public class DisablePostTarget extends AbstractConditionableCommand {
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.POST_TARGET)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.commandName("disable")
.build();

View File

@@ -11,6 +11,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.ChannelGroupService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@@ -49,40 +50,41 @@ public class EnableChannelGroup extends AbstractConditionableCommand {
String channelGroupName = slashCommandParameterService.getCommandOption(CHANNEL_GROUP_NAME_PARAMETER, event, String.class);
channelGroupService.enableChannelGroup(channelGroupName, event.getGuild().getIdLong());
return interactionService.replyEmbed(ENABLE_CHANNEL_GROUP_RESPONSE, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@Override
public CommandConfiguration getConfiguration() {
Parameter channelGroupName = Parameter
.builder()
.name(CHANNEL_GROUP_NAME_PARAMETER)
.type(String.class)
.templated(true)
.build();
.builder()
.name(CHANNEL_GROUP_NAME_PARAMETER)
.type(String.class)
.templated(true)
.build();
List<Parameter> parameters = Arrays.asList(channelGroupName);
HelpInfo helpInfo = HelpInfo
.builder()
.templated(true)
.build();
.builder()
.templated(true)
.build();
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.CHANNELS)
.commandName(ENABLE_CHANNEL_GROUP_COMMAND)
.build();
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.CHANNELS)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.commandName(ENABLE_CHANNEL_GROUP_COMMAND)
.build();
return CommandConfiguration.builder()
.name(ENABLE_CHANNEL_GROUP_COMMAND)
.module(ChannelsModuleDefinition.CHANNELS)
.parameters(parameters)
.slashCommandConfig(slashCommandConfig)
.supportsEmbedException(true)
.help(helpInfo)
.templated(true)
.causesReaction(true)
.build();
.name(ENABLE_CHANNEL_GROUP_COMMAND)
.module(ChannelsModuleDefinition.CHANNELS)
.parameters(parameters)
.slashCommandConfig(slashCommandConfig)
.supportsEmbedException(true)
.help(helpInfo)
.templated(true)
.causesReaction(true)
.build();
}
@Override

View File

@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.exception.PostTargetNotValidException;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.PostTargetService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@@ -41,7 +42,7 @@ public class EnablePostTarget extends AbstractConditionableCommand {
@Override
public CommandResult execute(CommandContext commandContext) {
String targetName = (String) commandContext.getParameters().getParameters().get(0);
if(!postTargetService.validPostTarget(targetName)) {
if (!postTargetService.validPostTarget(targetName)) {
throw new PostTargetNotValidException(targetName, postTargetService.getAvailablePostTargets());
}
postTargetService.enablePostTarget(targetName, commandContext.getGuild().getIdLong());
@@ -51,45 +52,46 @@ public class EnablePostTarget extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
String postTargetName = slashCommandParameterService.getCommandOption(NAME_PARAMETER, event, String.class);
if(!postTargetService.validPostTarget(postTargetName)) {
if (!postTargetService.validPostTarget(postTargetName)) {
throw new PostTargetNotValidException(postTargetName, postTargetService.getAvailablePostTargets());
}
postTargetService.enablePostTarget(postTargetName, event.getGuild().getIdLong());
return interactionService.replyEmbed(ENABLE_POSTTARGET_RESPONSE, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@Override
public CommandConfiguration getConfiguration() {
Parameter postTargetName = Parameter
.builder()
.name(NAME_PARAMETER)
.type(String.class)
.templated(true)
.build();
.builder()
.name(NAME_PARAMETER)
.type(String.class)
.templated(true)
.build();
List<Parameter> parameters = Arrays.asList(postTargetName);
HelpInfo helpInfo = HelpInfo
.builder()
.templated(true)
.build();
.builder()
.templated(true)
.build();
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.POST_TARGET)
.commandName("enable")
.build();
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.POST_TARGET)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.commandName("enable")
.build();
return CommandConfiguration.builder()
.name(ENABLE_POSTTARGET_COMMAND)
.module(ChannelsModuleDefinition.CHANNELS)
.parameters(parameters)
.slashCommandConfig(slashCommandConfig)
.supportsEmbedException(true)
.help(helpInfo)
.templated(true)
.causesReaction(true)
.build();
.name(ENABLE_POSTTARGET_COMMAND)
.module(ChannelsModuleDefinition.CHANNELS)
.parameters(parameters)
.slashCommandConfig(slashCommandConfig)
.supportsEmbedException(true)
.help(helpInfo)
.templated(true)
.causesReaction(true)
.build();
}
@Override

View File

@@ -10,6 +10,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.template.commands.ListChannelGroupsModel;
@@ -61,9 +62,9 @@ public class ListChannelGroups extends AbstractConditionableCommand {
AServer server = serverManagementService.loadServer(guild);
List<AChannelGroup> channelGroups = channelGroupManagementService.findAllInServer(server);
ListChannelGroupsModel template = ListChannelGroupsModel
.builder()
.groups(channelGroupService.convertAChannelGroupToChannelGroupChannel(channelGroups))
.build();
.builder()
.groups(channelGroupService.convertAChannelGroupToChannelGroupChannel(channelGroups))
.build();
return templateService.renderEmbedTemplate("listChannelGroups_response", template, guild.getIdLong());
}
@@ -71,34 +72,35 @@ public class ListChannelGroups extends AbstractConditionableCommand {
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
MessageToSend response = getMessageToSend(event.getGuild());
return interactionService.replyMessageToSend(response, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@Override
public CommandConfiguration getConfiguration() {
List<String> aliases = Arrays.asList("lsChGrp");
HelpInfo helpInfo = HelpInfo
.builder()
.templated(true)
.build();
.builder()
.templated(true)
.build();
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.CHANNELS)
.commandName(LIST_CHANNEL_GROUPS_COMMAND)
.build();
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.CHANNELS)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.commandName(LIST_CHANNEL_GROUPS_COMMAND)
.build();
return CommandConfiguration.builder()
.name(LIST_CHANNEL_GROUPS_COMMAND)
.module(ChannelsModuleDefinition.CHANNELS)
.slashCommandConfig(slashCommandConfig)
.aliases(aliases)
.templated(true)
.help(helpInfo)
.supportsEmbedException(true)
.causesReaction(true)
.build();
.name(LIST_CHANNEL_GROUPS_COMMAND)
.module(ChannelsModuleDefinition.CHANNELS)
.slashCommandConfig(slashCommandConfig)
.aliases(aliases)
.templated(true)
.help(helpInfo)
.supportsEmbedException(true)
.causesReaction(true)
.build();
}
@Override

View File

@@ -1,11 +1,9 @@
package dev.sheldan.abstracto.core.commands.channels;
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
import dev.sheldan.abstracto.core.command.exception.SlashCommandParameterMissingException;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
@@ -14,20 +12,28 @@ import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.exception.EntityGuildMismatchException;
import dev.sheldan.abstracto.core.exception.PostTargetNotValidException;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.PostTarget;
import dev.sheldan.abstracto.core.models.template.commands.PostTargetDisplayModel;
import dev.sheldan.abstracto.core.models.template.commands.PostTargetModelEntry;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.PostTargetService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import dev.sheldan.abstracto.core.service.management.PostTargetManagement;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
@@ -35,12 +41,6 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
@Service
@Slf4j
public class PostTargetCommand extends AbstractConditionableCommand {
@@ -75,11 +75,11 @@ public class PostTargetCommand extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
Guild guild = commandContext.getGuild();
if(commandContext.getParameters().getParameters().isEmpty()) {
if (commandContext.getParameters().getParameters().isEmpty()) {
log.debug("Displaying existing post targets for guild {}.", guild.getId());
MessageToSend messageToSend = getMessageToSendForPosttargetDisplay(guild);
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
.thenApply(aVoid -> CommandResult.fromSuccess());
.thenApply(aVoid -> CommandResult.fromSuccess());
}
String targetName = (String) commandContext.getParameters().getParameters().get(0);
GuildChannel channel = (GuildChannel) commandContext.getParameters().getParameters().get(1);
@@ -88,10 +88,10 @@ public class PostTargetCommand extends AbstractConditionableCommand {
}
private void validateAndCreatePosttarget(Guild guild, String targetName, GuildChannel channel) {
if(!postTargetService.validPostTarget(targetName)) {
if (!postTargetService.validPostTarget(targetName)) {
throw new PostTargetNotValidException(targetName, postTargetService.getAvailablePostTargets());
}
if(!channel.getGuild().equals(guild)) {
if (!channel.getGuild().equals(guild)) {
throw new EntityGuildMismatchException();
}
postTargetManagement.createOrUpdate(targetName, guild.getIdLong(), channel.getIdLong());
@@ -135,15 +135,15 @@ public class PostTargetCommand extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
if(!slashCommandParameterService.hasCommandOption(CHANNEL_PARAMETER, event) && !slashCommandParameterService.hasCommandOption(NAME_PARAMETER, event)) {
if (!slashCommandParameterService.hasCommandOption(CHANNEL_PARAMETER, event) && !slashCommandParameterService.hasCommandOption(NAME_PARAMETER, event)) {
MessageToSend messageToSend = getMessageToSendForPosttargetDisplay(event.getGuild());
return interactionService.replyMessageToSend(messageToSend, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
} else {
if(!slashCommandParameterService.hasCommandOption(NAME_PARAMETER, event)) {
if (!slashCommandParameterService.hasCommandOption(NAME_PARAMETER, event)) {
throw new SlashCommandParameterMissingException(NAME_PARAMETER);
}
if(!slashCommandParameterService.hasCommandOption(CHANNEL_PARAMETER, event)) {
if (!slashCommandParameterService.hasCommandOption(CHANNEL_PARAMETER, event)) {
throw new SlashCommandParameterMissingException(CHANNEL_PARAMETER);
}
String postTargetName = slashCommandParameterService.getCommandOption(NAME_PARAMETER, event, String.class);
@@ -157,44 +157,45 @@ public class PostTargetCommand extends AbstractConditionableCommand {
@Override
public CommandConfiguration getConfiguration() {
Parameter postTargetName = Parameter
.builder()
.name(NAME_PARAMETER)
.type(String.class)
.optional(true)
.templated(true)
.build();
.builder()
.name(NAME_PARAMETER)
.type(String.class)
.optional(true)
.templated(true)
.build();
Parameter channel = Parameter
.builder()
.name(CHANNEL_PARAMETER)
.type(TextChannel.class)
.optional(true)
.templated(true)
.build();
.builder()
.name(CHANNEL_PARAMETER)
.type(TextChannel.class)
.optional(true)
.templated(true)
.build();
List<Parameter> parameters = Arrays.asList(postTargetName, channel);
HelpInfo helpInfo = HelpInfo
.builder()
.templated(true)
.hasExample(true)
.build();
.builder()
.templated(true)
.hasExample(true)
.build();
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.POST_TARGET)
.commandName(POSTTARGET_COMMAND)
.build();
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.POST_TARGET)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.commandName(POSTTARGET_COMMAND)
.build();
return CommandConfiguration.builder()
.name(POSTTARGET_COMMAND)
.module(ChannelsModuleDefinition.CHANNELS)
.parameters(parameters)
.async(true)
.slashCommandConfig(slashCommandConfig)
.supportsEmbedException(true)
.help(helpInfo)
.templated(true)
.causesReaction(true)
.build();
.name(POSTTARGET_COMMAND)
.module(ChannelsModuleDefinition.CHANNELS)
.parameters(parameters)
.async(true)
.slashCommandConfig(slashCommandConfig)
.supportsEmbedException(true)
.help(helpInfo)
.templated(true)
.causesReaction(true)
.build();
}
@Override

View File

@@ -13,6 +13,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.exception.EntityGuildMismatchException;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.service.ChannelGroupService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
@@ -51,7 +52,7 @@ public class RemoveFromChannelGroup extends AbstractConditionableCommand {
String name = (String) commandContext.getParameters().getParameters().get(0);
AChannel fakeChannel = (AChannel) commandContext.getParameters().getParameters().get(1);
AChannel actualChannel = channelManagementService.loadChannel(fakeChannel.getId());
if(!actualChannel.getServer().getId().equals(commandContext.getGuild().getIdLong())) {
if (!actualChannel.getServer().getId().equals(commandContext.getGuild().getIdLong())) {
throw new EntityGuildMismatchException();
}
channelGroupService.removeChannelFromChannelGroup(name, actualChannel);
@@ -62,10 +63,11 @@ public class RemoveFromChannelGroup extends AbstractConditionableCommand {
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
String channelGroupName = slashCommandParameterService.getCommandOption(NAME_PARAMETER, event, String.class);
AChannel actualChannel;
if(slashCommandParameterService.hasCommandOptionWithFullType(CHANNEL_PARAMETER, event, OptionType.CHANNEL)) {
GuildMessageChannel guildChannel = slashCommandParameterService.getCommandOption(CHANNEL_PARAMETER, event, AChannel.class, GuildMessageChannel.class);
if (slashCommandParameterService.hasCommandOptionWithFullType(CHANNEL_PARAMETER, event, OptionType.CHANNEL)) {
GuildMessageChannel guildChannel =
slashCommandParameterService.getCommandOption(CHANNEL_PARAMETER, event, AChannel.class, GuildMessageChannel.class);
actualChannel = channelManagementService.loadChannel(guildChannel.getIdLong());
} else if(slashCommandParameterService.hasCommandOptionWithFullType(CHANNEL_PARAMETER, event, OptionType.STRING)) {
} else if (slashCommandParameterService.hasCommandOptionWithFullType(CHANNEL_PARAMETER, event, OptionType.STRING)) {
String channelId = slashCommandParameterService.getCommandOption(CHANNEL_PARAMETER, event, AChannel.class, String.class);
actualChannel = channelManagementService.loadChannel(Long.parseLong(channelId));
} else {
@@ -73,47 +75,48 @@ public class RemoveFromChannelGroup extends AbstractConditionableCommand {
}
channelGroupService.removeChannelFromChannelGroup(channelGroupName, actualChannel);
return interactionService.replyEmbed(REMOVE_FROM_CHANNEL_GROUP_RESPONSE, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@Override
public CommandConfiguration getConfiguration() {
Parameter channelGroupName = Parameter
.builder()
.name(NAME_PARAMETER)
.type(String.class)
.build();
.builder()
.name(NAME_PARAMETER)
.type(String.class)
.build();
Parameter channelToAdd = Parameter
.builder()
.name(CHANNEL_PARAMETER)
.type(AChannel.class)
.build();
.builder()
.name(CHANNEL_PARAMETER)
.type(AChannel.class)
.build();
List<Parameter> parameters = Arrays.asList(channelGroupName, channelToAdd);
List<String> aliases = Arrays.asList("rmChChgrp", "chGrpCh-");
HelpInfo helpInfo = HelpInfo
.builder()
.templated(true)
.hasExample(true)
.build();
.builder()
.templated(true)
.hasExample(true)
.build();
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.CHANNELS)
.commandName(REMOVE_FROM_CHANNEL_GROUP_COMMAND)
.build();
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.CHANNELS)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.commandName(REMOVE_FROM_CHANNEL_GROUP_COMMAND)
.build();
return CommandConfiguration.builder()
.name(REMOVE_FROM_CHANNEL_GROUP_COMMAND)
.module(ChannelsModuleDefinition.CHANNELS)
.aliases(aliases)
.parameters(parameters)
.slashCommandConfig(slashCommandConfig)
.templated(true)
.help(helpInfo)
.supportsEmbedException(true)
.causesReaction(true)
.build();
.name(REMOVE_FROM_CHANNEL_GROUP_COMMAND)
.module(ChannelsModuleDefinition.CHANNELS)
.aliases(aliases)
.parameters(parameters)
.slashCommandConfig(slashCommandConfig)
.templated(true)
.help(helpInfo)
.supportsEmbedException(true)
.causesReaction(true)
.build();
}
@Override

View File

@@ -1,5 +1,7 @@
package dev.sheldan.abstracto.core.commands.config;
import dev.sheldan.abstracto.core.command.condition.CommandCondition;
import dev.sheldan.abstracto.core.command.condition.BotOwnerOnlyCondition;
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
@@ -11,6 +13,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.CacheServiceBean;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,6 +35,9 @@ public class ClearCache extends AbstractConditionableCommand {
@Autowired
private InteractionService interactionService;
@Autowired
private BotOwnerOnlyCondition botOwnerOnlyCondition;
@Override
public CommandResult execute(CommandContext commandContext) {
@@ -53,6 +59,7 @@ public class ClearCache extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(CoreSlashCommandNames.INTERNAL)
.commandName(CLEAR_CACHE_COMMAND)
.build();
@@ -77,4 +84,11 @@ public class ClearCache extends AbstractConditionableCommand {
public FeatureDefinition getFeature() {
return CoreFeatureDefinition.CORE_FEATURE;
}
@Override
public List<CommandCondition> getConditions() {
List<CommandCondition> conditions = super.getConditions();
conditions.add(botOwnerOnlyCondition);
return conditions;
}
}

View File

@@ -13,6 +13,7 @@ import dev.sheldan.abstracto.core.command.service.management.FeatureManagementSe
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.exception.ConfigurationKeyNotFoundException;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.ConfigService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import dev.sheldan.abstracto.core.service.management.DefaultConfigManagementService;
@@ -97,6 +98,7 @@ public class ResetConfig extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.CONFIG)
.commandName("reset")
.build();

View File

@@ -11,6 +11,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.ConfigService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@@ -80,6 +81,7 @@ public class SetConfig extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.CONFIG)
.commandName("set")
.build();

View File

@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
@@ -62,6 +63,7 @@ public class RemoveCommandMemberCooldown extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.COOLDOWN)
.groupName("commandMember")
.commandName("remove")

View File

@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import dev.sheldan.abstracto.core.utils.ParseUtils;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@@ -73,6 +74,7 @@ public class SetCommandMemberCooldown extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.COOLDOWN)
.groupName("commandMember")
.commandName("set")

View File

@@ -14,6 +14,7 @@ import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureConfig;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.template.commands.FeatureSwitchModel;
import dev.sheldan.abstracto.core.service.ChannelService;
@@ -148,6 +149,7 @@ public class DisableFeature extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.FEATURE)
.commandName("disable")
.build();

View File

@@ -13,6 +13,7 @@ import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.config.FeatureMode;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.FeatureConfigService;
import dev.sheldan.abstracto.core.service.FeatureModeService;
@@ -97,6 +98,7 @@ public class DisableMode extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.FEATURE)
.commandName(DISABLE_MODE_COMMAND)
.build();

View File

@@ -14,6 +14,7 @@ import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureConfig;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.FeatureValidationResult;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.template.commands.FeatureSwitchModel;
@@ -172,6 +173,7 @@ public class EnableFeature extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.FEATURE)
.commandName("enable")
.build();

View File

@@ -13,6 +13,7 @@ import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.config.FeatureMode;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.FeatureConfigService;
import dev.sheldan.abstracto.core.service.FeatureModeService;
@@ -95,6 +96,7 @@ public class EnableMode extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.FEATURE)
.commandName(ENABLE_MODE_COMMAND)
.build();

View File

@@ -13,6 +13,7 @@ import dev.sheldan.abstracto.core.command.service.management.FeatureManagementSe
import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.database.AFeature;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.template.commands.FeatureModeDisplay;
@@ -116,6 +117,7 @@ public class FeatureModes extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.FEATURE)
.commandName(FEATURE_MODES_COMMAND)
.build();

View File

@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.converter.FeatureFlagConverter;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.database.AFeatureFlag;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.property.FeatureFlagProperty;
@@ -104,6 +105,7 @@ public class Features extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.FEATURE)
.commandName("list")
.build();

View File

@@ -13,6 +13,7 @@ import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.exception.EntityGuildMismatchException;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.service.RoleImmunityService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
@@ -96,6 +97,7 @@ public class MakeAffected extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.CONFIG)
.commandName(MAKE_AFFECTED_COMMAND_NAME)
.build();

View File

@@ -13,6 +13,7 @@ import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.exception.EntityGuildMismatchException;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.RoleImmunityService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.entities.Role;
@@ -89,6 +90,7 @@ public class MakeImmune extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.CONFIG)
.commandName(MAKE_IMMUNE_COMMAND)
.build();

View File

@@ -16,7 +16,6 @@ import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.models.database.AFeature;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -37,9 +36,6 @@ public class Restrict extends AbstractConditionableCommand {
@Autowired
private CommandService commandService;
@Autowired
private RoleManagementService roleManagementService;
@Autowired
private TemplateService templateService;

View File

@@ -11,6 +11,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.database.EffectType;
import dev.sheldan.abstracto.core.models.template.commands.ShowEffectsModel;
import dev.sheldan.abstracto.core.service.ChannelService;
@@ -73,6 +74,7 @@ public class ShowEffects extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.rootCommandName(CoreSlashCommandNames.CONFIG)
.commandName(SHOW_EFFECTS_COMMAND)
.build();

View File

@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.ProfanityService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@@ -109,6 +110,7 @@ public class AddProfanityRegex extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(CoreSlashCommandNames.PROFANITY)
.commandName(ADD_PROFANITY_REGEX_COMMAND)
.build();

View File

@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.ProfanityService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@@ -70,6 +71,7 @@ public class CreateProfanityGroup extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(CoreSlashCommandNames.PROFANITY)
.commandName(CREATE_PROFANITY_GROUP_COMMAND)
.build();

View File

@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.ProfanityService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@@ -70,6 +71,7 @@ public class DeleteProfanityGroup extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(CoreSlashCommandNames.PROFANITY)
.commandName(DELETE_PROFANITY_GROUP_COMMAND)
.build();

View File

@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.service.ProfanityService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@@ -79,6 +80,7 @@ public class RemoveProfanityRegex extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(CoreSlashCommandNames.PROFANITY)
.commandName(REMOVE_PROFANITY_REGEX_COMMAND)
.build();

View File

@@ -11,6 +11,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.database.ProfanityGroup;
import dev.sheldan.abstracto.core.models.template.commands.ProfanityConfigModel;
import dev.sheldan.abstracto.core.service.ChannelService;
@@ -77,6 +78,7 @@ public class ShowProfanityConfig extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(CoreSlashCommandNames.PROFANITY)
.commandName(SHOW_PROFANITY_CONFIG_COMMAND)
.build();

View File

@@ -1,5 +1,7 @@
package dev.sheldan.abstracto.core.commands.config.template;
import dev.sheldan.abstracto.core.command.condition.CommandCondition;
import dev.sheldan.abstracto.core.command.condition.BotOwnerOnlyCondition;
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
@@ -13,6 +15,7 @@ import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.exception.CustomTemplateNotFoundException;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.template.commands.GetCustomTemplateModel;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
@@ -59,6 +62,9 @@ public class GetCustomTemplate extends AbstractConditionableCommand {
@Autowired
private TemplateService templateService;
@Autowired
private BotOwnerOnlyCondition botOwnerOnlyCondition;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
String templateKey = (String) commandContext.getParameters().getParameters().get(0);
@@ -110,6 +116,7 @@ public class GetCustomTemplate extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(CoreSlashCommandNames.INTERNAL)
.commandName(GET_CUSTOM_TEMPLATE_COMMAND)
.build();
@@ -131,4 +138,11 @@ public class GetCustomTemplate extends AbstractConditionableCommand {
public FeatureDefinition getFeature() {
return CoreFeatureDefinition.CORE_FEATURE;
}
@Override
public List<CommandCondition> getConditions() {
List<CommandCondition> conditions = super.getConditions();
conditions.add(botOwnerOnlyCondition);
return conditions;
}
}

View File

@@ -1,5 +1,7 @@
package dev.sheldan.abstracto.core.commands.config.template;
import dev.sheldan.abstracto.core.command.condition.CommandCondition;
import dev.sheldan.abstracto.core.command.condition.BotOwnerOnlyCondition;
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
@@ -13,6 +15,7 @@ import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.exception.TemplateNotFoundException;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.template.commands.GetTemplateModel;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
@@ -56,6 +59,9 @@ public class GetTemplate extends AbstractConditionableCommand {
@Autowired
private FileService fileService;
@Autowired
private BotOwnerOnlyCondition botOwnerOnlyCondition;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
String templateKey = (String) commandContext.getParameters().getParameters().get(0);
@@ -105,6 +111,7 @@ public class GetTemplate extends AbstractConditionableCommand {
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.INTERNAL)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.commandName(GET_TEMPLATE_COMMAND)
.build();
@@ -125,4 +132,11 @@ public class GetTemplate extends AbstractConditionableCommand {
public FeatureDefinition getFeature() {
return CoreFeatureDefinition.CORE_FEATURE;
}
@Override
public List<CommandCondition> getConditions() {
List<CommandCondition> conditions = super.getConditions();
conditions.add(botOwnerOnlyCondition);
return conditions;
}
}

View File

@@ -1,5 +1,7 @@
package dev.sheldan.abstracto.core.commands.config.template;
import dev.sheldan.abstracto.core.command.condition.CommandCondition;
import dev.sheldan.abstracto.core.command.condition.BotOwnerOnlyCondition;
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
@@ -13,6 +15,7 @@ import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.exception.CustomTemplateNotFoundException;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import dev.sheldan.abstracto.core.templating.model.database.CustomTemplate;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
@@ -45,6 +48,9 @@ public class ResetTemplate extends AbstractConditionableCommand {
@Autowired
private InteractionService interactionService;
@Autowired
private BotOwnerOnlyCondition botOwnerOnlyCondition;
@Override
public CommandResult execute(CommandContext commandContext) {
String templateKey = (String) commandContext.getParameters().getParameters().get(0);
@@ -89,6 +95,7 @@ public class ResetTemplate extends AbstractConditionableCommand {
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.INTERNAL)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.commandName(RESET_TEMPLATE_COMMAND)
.build();
@@ -108,4 +115,11 @@ public class ResetTemplate extends AbstractConditionableCommand {
public FeatureDefinition getFeature() {
return CoreFeatureDefinition.CORE_FEATURE;
}
@Override
public List<CommandCondition> getConditions() {
List<CommandCondition> conditions = super.getConditions();
conditions.add(botOwnerOnlyCondition);
return conditions;
}
}

View File

@@ -1,5 +1,7 @@
package dev.sheldan.abstracto.core.commands.config.template;
import dev.sheldan.abstracto.core.command.condition.CommandCondition;
import dev.sheldan.abstracto.core.command.condition.BotOwnerOnlyCondition;
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
@@ -13,6 +15,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.templating.service.management.CustomTemplateManagementService;
@@ -55,6 +58,9 @@ public class SetTemplate extends AbstractConditionableCommand {
@Autowired
private InteractionService interactionService;
@Autowired
private BotOwnerOnlyCondition botOwnerOnlyCondition;
@Override
public CommandResult execute(CommandContext commandContext) {
List<Object> parameter = commandContext.getParameters().getParameters();
@@ -136,6 +142,7 @@ public class SetTemplate extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(CoreSlashCommandNames.INTERNAL)
.commandName(SET_TEMPLATE_COMMAND)
.build();
@@ -151,4 +158,11 @@ public class SetTemplate extends AbstractConditionableCommand {
.causesReaction(true)
.build();
}
@Override
public List<CommandCondition> getConditions() {
List<CommandCondition> conditions = super.getConditions();
conditions.add(botOwnerOnlyCondition);
return conditions;
}
}

View File

@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import dev.sheldan.abstracto.core.models.template.commands.EchoModel;
import dev.sheldan.abstracto.core.models.template.commands.EchoRedirectResponseModel;
@@ -122,6 +123,7 @@ public class Echo extends AbstractConditionableCommand {
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.defaultPrivilege(SlashCommandPrivilegeLevels.ADMIN)
.rootCommandName(ECHO_COMMAND)
.build();
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();

View File

@@ -11,6 +11,7 @@ import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
import dev.sheldan.abstracto.core.models.database.AEmote;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import dev.sheldan.abstracto.core.service.management.EmoteManagementService;
@@ -82,6 +83,7 @@ public class SetEmote extends AbstractConditionableCommand {
.builder()
.enabled(true)
.rootCommandName(CoreSlashCommandNames.CONFIG)
.defaultPrivilege(SlashCommandPrivilegeLevels.INVITER)
.commandName("setEmote")
.build();
return CommandConfiguration.builder()

View File

@@ -15,11 +15,13 @@ import dev.sheldan.abstracto.core.service.FeatureConfigService;
import dev.sheldan.abstracto.core.service.FeatureFlagService;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.CompletableFutureList;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.interactions.IntegrationType;
import net.dv8tion.jda.api.interactions.InteractionContextType;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.*;
import org.apache.commons.lang3.StringUtils;
@@ -92,7 +94,17 @@ public class SlashCommandServiceBean implements SlashCommandService {
.filter(commandData -> commandData.getSecond().getName().equals(rootName))
.map(Pair::getSecond)
.findAny();
SlashCommandData rootCommand = existingRootCommand.orElseGet(() -> Commands.slash(rootName, description));
DefaultMemberPermissions defaultPermissions;
if(slashConfig.getDefaultPrivilege() != null) {
defaultPermissions = switch (slashConfig.getDefaultPrivilege()) {
case ADMIN -> DefaultMemberPermissions.enabledFor(Permission.ADMINISTRATOR);
case INVITER -> DefaultMemberPermissions.enabledFor(Permission.MANAGE_SERVER);
case NONE -> DefaultMemberPermissions.ENABLED;
};
} else {
defaultPermissions = DefaultMemberPermissions.ENABLED;
}
SlashCommandData rootCommand = existingRootCommand.orElseGet(() -> Commands.slash(rootName, description).setDefaultPermissions(defaultPermissions));
if(commandConfiguration.isUserInstallable() && userCommandsOnly) {
rootCommand.setIntegrationTypes(IntegrationType.USER_INSTALL);
if(commandConfiguration.getSlashCommandConfig().getUserCommandConfig() != null) {