added check to check if a role is in the server

added more log output
This commit is contained in:
Sheldan
2020-04-21 19:25:12 +02:00
parent 5edb2e4cc8
commit 7b56b89157
29 changed files with 126 additions and 40 deletions

View File

@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.core.service;
import dev.sheldan.abstracto.core.exception.GuildException;
import dev.sheldan.abstracto.core.exception.RoleException;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
import lombok.extern.slf4j.Slf4j;
@@ -69,4 +70,14 @@ public class RoleServiceBean implements RoleService {
throw new RoleException(String.format("Cannot find role %s to mark as deleted.", id));
}
}
@Override
public boolean isRoleInServer(AServer server, ARole role) {
Optional<Guild> guildById = botService.getGuildById(server.getId());
if(guildById.isPresent()) {
return guildById.get().getRoleById(role.getId()) != null;
} else {
throw new GuildException(String.format("Failed to load guild %s.", server.getId()));
}
}
}

View File

@@ -69,7 +69,7 @@ public class StartupServiceBean implements Startup {
availableServers.forEach(aLong -> {
AServer newAServer = serverManagementService.loadOrCreate(aLong);
Guild newGuild = instance.getGuildById(aLong);
log.debug("Synchronizing server: {}", aLong);
log.trace("Synchronizing server: {}", aLong);
if(newGuild != null){
synchronizeRolesOf(newGuild, newAServer);
synchronizeChannelsOf(newGuild, newAServer);
@@ -89,7 +89,7 @@ public class StartupServiceBean implements Startup {
Set<Long> newRoles = SetUtils.disjunction(availableRoles, knownRolesId);
newRoles.forEach(aLong -> {
ARole newRole = roleManagementService.createRole(aLong, existingAServer);
log.debug("Adding new role: {}", aLong);
log.trace("Adding new role: {}", aLong);
existingAServer.getRoles().add(newRole);
});
}
@@ -102,7 +102,7 @@ public class StartupServiceBean implements Startup {
Set<Long> newChannels = SetUtils.difference(existingChannelsIds, knownChannelsIds);
newChannels.forEach(aLong -> {
GuildChannel channel1 = available.stream().filter(channel -> channel.getIdLong() == aLong).findFirst().get();
log.debug("Adding new channel: {}", aLong);
log.trace("Adding new channel: {}", aLong);
AChannelType type = AChannel.getAChannelType(channel1.getType());
AChannel newChannel = channelManagementService.createChannel(channel1.getIdLong(), type);
serverManagementService.addChannelToServer(existingServer, newChannel);