Archiviert
1
0

Fix DiscordRanks

Dieser Commit ist enthalten in:
yoyosource 2021-07-28 21:13:44 +02:00
Ursprung aeaed0db99
Commit 95ab4d3344

Datei anzeigen

@ -28,7 +28,9 @@ import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@UtilityClass
@ -43,18 +45,22 @@ public class DiscordRanks {
if (member == null) {
return;
}
Set<UserGroup> toRemove = new HashSet<>(SteamwarDiscordBotConfig.RANKS.keySet());
toRemove.remove(steamwarUser.getUserGroup());
for (UserGroup userGroup : toRemove) {
System.out.println(steamwarUser + " REMOVING");
String roleId = SteamwarDiscordBotConfig.RANKS.get(userGroup);
guild.removeRoleFromMember(member, guild.getRoleById(roleId)).complete();
List<Role> roleList = member.getRoles();
Set<String> strings = new HashSet<>(SteamwarDiscordBotConfig.RANKS.values());
String needed = SteamwarDiscordBotConfig.RANKS.get(steamwarUser.getUserGroup());
for (Role role : roleList) {
if (!strings.contains(role.getId())) {
continue;
}
if (steamwarUser.getUserGroup() != UserGroup.Member) {
System.out.println(steamwarUser + " ADDING");
guild.addRoleToMember(member, guild.getRoleById(SteamwarDiscordBotConfig.RANKS.get(steamwarUser.getUserGroup()))).complete();
if (role.getId().equals(needed)) {
needed = "";
continue;
}
guild.removeRoleFromMember(member, role).complete();
}
if (!needed.isEmpty()) {
guild.addRoleToMember(member, guild.getRoleById(needed)).complete();
}
}
}