added check to unmute user, in case the user left the guild

added checks if users being awarded a role are still in the guild
This commit is contained in:
Sheldan
2020-04-24 20:49:06 +02:00
parent 0f8a39a336
commit d4eeb2dadb
5 changed files with 49 additions and 11 deletions

View File

@@ -180,7 +180,9 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
boolean currentlyHasNoExperienceRole = userExperience.getCurrentExperienceRole() == null;
if(role == null) {
if(!currentlyHasNoExperienceRole){
roleService.removeRoleFromUser(user, userExperience.getCurrentExperienceRole().getRole());
if(botService.isUserInGuild(userExperience.getUser())) {
roleService.removeRoleFromUser(user, userExperience.getCurrentExperienceRole().getRole());
}
}
userExperience.setCurrentExperienceRole(null);
return;
@@ -190,7 +192,9 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
if(currentlyHasNoExperienceRole || !role.getRole().getId().equals(userExperience.getCurrentExperienceRole().getRole().getId())) {
log.info("User {} in server {} gets a new role {}", user.getUserReference().getId(), user.getServerReference().getId(), role.getRole().getId());
if(!currentlyHasNoExperienceRole) {
roleService.removeRoleFromUser(user, userExperience.getCurrentExperienceRole().getRole());
if(botService.isUserInGuild(userExperience.getUser())) {
roleService.removeRoleFromUser(user, userExperience.getCurrentExperienceRole().getRole());
}
}
roleService.addRoleToUser(user, role.getRole());
}

View File

@@ -20,6 +20,7 @@ import dev.sheldan.abstracto.scheduling.service.SchedulerService;
import dev.sheldan.abstracto.templating.model.MessageToSend;
import dev.sheldan.abstracto.templating.service.TemplateService;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
@@ -200,13 +201,18 @@ public class MuteServiceBean implements MuteService {
log.info("Unmuting {} in server {}", mutingServer.getId(), mute.getMutedUser().getUserReference().getId());
MuteRole muteRole = muteRoleManagementService.retrieveMuteRoleForServer(mutingServer);
log.trace("Using the mute role {} mapping to role {}", muteRole.getId(), muteRole.getRole().getId());
roleService.removeRoleFromUser(mute.getMutedUser(), muteRole.getRole());
Guild guild = botService.getGuildById(mute.getMutingServer().getId()).orElseGet(null);
if(botService.isUserInGuild(guild, mute.getMutedUser())) {
roleService.removeRoleFromUser(mute.getMutedUser(), muteRole.getRole());
} else {
log.info("User to unmute left the guild.");
}
UnMuteLog unMuteLog = UnMuteLog
.builder()
.mute(mute)
.mutingUser(botService.getMemberInServer(mute.getMutingUser()))
.unMutedUser(botService.getMemberInServer(mute.getMutedUser()))
.guild(botService.getGuildById(mute.getMutingServer().getId()).orElseGet(null))
.guild(guild)
.server(mute.getMutingServer())
.build();
sendUnmuteLog(unMuteLog);

View File

@@ -1,8 +1,10 @@
{
"author": {
"name": "${unMutedUser.effectiveName}",
"avatar": "${unMutedUser.user.effectiveAvatarUrl}"
},
<#if unMutedUser?has_content>
"author": {
"name": "${unMutedUser.effectiveName}",
"avatar": "${unMutedUser.user.effectiveAvatarUrl}"
},
</#if>
"title": {
"title": "User has been unmuted"
},
@@ -14,11 +16,20 @@
"fields": [
{
"name": "Unmuted User",
"value": "${unMutedUser.effectiveName} ${unMutedUser.asMention} (${unMutedUser.idLong?c})"
<#if unMutedUser?has_content>
"value": "${unMutedUser.effectiveName} ${unMutedUser.asMention} (${unMutedUser.idLong?c})"
<#else>
"value": "User has left the server (${mute.mutedUser.userReference.id?c})"
</#if>
},
{
"name": "Muted by",
"value": "${mutingUser.effectiveName} ${mutingUser.asMention} (${mutingUser.idLong?c})"
<#if mutingUser?has_content>
"value": "${mutingUser.effectiveName} ${mutingUser.asMention} (${mutingUser.idLong?c})"
<#else>
"value": "User has left the server (${mute.mutingUser.userReference.id?c})"
</#if>
},
{
"name": "Location of the mute",