mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-24 05:39:44 +00:00
[AB-124] adding admin mode
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package dev.sheldan.abstracto.core.commands.config;
|
||||
|
||||
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.command.config.features.CoreFeatures;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.service.ServerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class SetAdminMode extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private ServerService serverService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
Boolean newState = (Boolean) commandContext.getParameters().getParameters().get(0);
|
||||
serverService.setAdminModeTo(commandContext.getGuild().getIdLong(), newState);
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter valueToSet = Parameter.builder().name("value").type(Boolean.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(valueToSet);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).hasExample(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("setAdminMode")
|
||||
.module(ConfigModuleInterface.CONFIG)
|
||||
.parameters(parameters)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureEnum getFeature() {
|
||||
return CoreFeatures.CORE_FEATURE;
|
||||
}
|
||||
}
|
||||
@@ -390,7 +390,7 @@ public class ChannelServiceBean implements ChannelService {
|
||||
public AChannel getFakeChannelFromTextChannel(TextChannel textChannel) {
|
||||
AServer server = AServer
|
||||
.builder()
|
||||
.id(textChannel.getIdLong())
|
||||
.id(textChannel.getGuild().getIdLong())
|
||||
.fake(true)
|
||||
.build();
|
||||
return AChannel
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ServerServiceBean implements ServerService {
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public boolean adminModeActive(Long id) {
|
||||
return serverManagementService.loadServer(id).getAdminMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean adminModeActive(Guild guild) {
|
||||
return adminModeActive(guild.getIdLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdminModeTo(Long id, Boolean newState) {
|
||||
AServer server = serverManagementService.loadServer(id);
|
||||
server.setAdminMode(newState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdminModeTo(Guild guild, Boolean newState) {
|
||||
setAdminModeTo(guild.getIdLong(), newState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdminModeTo(AServer server, Boolean newState) {
|
||||
server.setAdminMode(newState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAdminMode(Long id) {
|
||||
setAdminModeTo(id, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateAdminMode(Long id) {
|
||||
setAdminModeTo(id, false);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class ServerManagementServiceBean implements ServerManagementService {
|
||||
|
||||
@Override
|
||||
public AServer createServer(Long id) {
|
||||
AServer newServer = AServer.builder().id(id).build();
|
||||
AServer newServer = AServer.builder().id(id).adminMode(false).build();
|
||||
log.info("Creating server with id {}.", id);
|
||||
return repository.save(newServer);
|
||||
}
|
||||
|
||||
@@ -97,6 +97,12 @@
|
||||
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="setAdminMode"/>
|
||||
<column name="module_id" valueComputed="${configModule}"/>
|
||||
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="resetConfig"/>
|
||||
<column name="module_id" valueComputed="${configModule}"/>
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="admin_only" type="BOOLEAN">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
</createTable>
|
||||
<sql>
|
||||
|
||||
Reference in New Issue
Block a user