mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-14 19:56:29 +00:00
[AB-xxx] adding default permissions for commands
adding owner limitation for certain internal commands
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package dev.sheldan.abstracto.core.command.condition;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.condition.detail.NotBotOwnerConditionDetail;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.dv8tion.jda.api.entities.ApplicationTeam;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BotOwnerOnlyCondition implements CommandCondition {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ConditionResult> shouldExecuteAsync(CommandContext commandContext, Command command) {
|
||||
return commandContext.getJda().retrieveApplicationInfo().submit()
|
||||
.thenApply(applicationInfo -> {
|
||||
ApplicationTeam team = applicationInfo.getTeam();
|
||||
boolean hasTeam = team != null;
|
||||
if(hasTeam && team.isMember(commandContext.getAuthor().getUser())) {
|
||||
return ConditionResult.fromSuccess();
|
||||
} else if(!hasTeam && applicationInfo.getOwner().getId().equals(commandContext.getAuthor().getUser().getId())) {
|
||||
return ConditionResult.fromSuccess();
|
||||
} else {
|
||||
return ConditionResult.fromFailure(new NotBotOwnerConditionDetail());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ConditionResult> shouldExecuteAsync(SlashCommandInteractionEvent slashCommandInteractionEvent, Command command) {
|
||||
return slashCommandInteractionEvent.getJDA().retrieveApplicationInfo().submit()
|
||||
.thenApply(applicationInfo -> {
|
||||
ApplicationTeam team = applicationInfo.getTeam();
|
||||
boolean hasTeam = team != null;
|
||||
if(hasTeam && team.isMember(slashCommandInteractionEvent.getUser())) {
|
||||
return ConditionResult.fromSuccess();
|
||||
} else if(!hasTeam && applicationInfo.getOwner().getId().equals(slashCommandInteractionEvent.getInteraction().getUser().getId())) {
|
||||
return ConditionResult.fromSuccess();
|
||||
} else {
|
||||
return ConditionResult.fromFailure(new NotBotOwnerConditionDetail());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAsync() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package dev.sheldan.abstracto.core.command.condition.detail;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.condition.ConditionDetail;
|
||||
|
||||
public class NotBotOwnerConditionDetail implements ConditionDetail {
|
||||
|
||||
|
||||
public NotBotOwnerConditionDetail() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "is_bot_owner_condition";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ public class SlashCommandConfig {
|
||||
private String userGroupName;
|
||||
private String commandName;
|
||||
private String userCommandName;
|
||||
@Builder.Default
|
||||
private SlashCommandPrivilegeLevels defaultPrivilege = SlashCommandPrivilegeLevels.NONE;
|
||||
|
||||
@Builder.Default
|
||||
private boolean userInstallable = false;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.interaction.slash;
|
||||
|
||||
public enum SlashCommandPrivilegeLevels {
|
||||
ADMIN,
|
||||
INVITER,
|
||||
NONE
|
||||
}
|
||||
Reference in New Issue
Block a user