mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-27 14:23:56 +00:00
added check to check if a role is in the server
added more log output
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user