/** * The guild of the role * * @return The guild of the role */ public Guild getGuild() { return role.getGuild(); } }
/** * The {@link net.dv8tion.jda.core.entities.Guild Guild} this Manager's * {@link net.dv8tion.jda.core.entities.Role Role} is in. * <br>This is logically the same as calling {@code getRole().getGuild()} * * @return The parent {@link net.dv8tion.jda.core.entities.Guild Guild} */ public Guild getGuild() { return getRole().getGuild(); }
@Override protected void validateInput(Role entity) { Checks.check(entity.getGuild().equals(guild), "Provided selected role is not from this Guild!"); Checks.check(orderList.contains(entity), "Provided role is not in the list of orderable roles!"); } }
private void checkAndAdd(Set<Role> newRoles, Role role) { Checks.notNull(role, "Role"); Checks.check(role.getGuild().equals(getGuild()), "Roles must all be from the same guild"); newRoles.add(role); } }
default RoleAction createCopy() return createCopy(getGuild());
/** * Checks if one given Role can interact with a 2nd given Role - in a permission sense (kick/ban/modify perms). * This only checks the Role-Position and does not check the actual permission (kick/ban/manage_role/...) * * @param issuer * The role that tries to interact with 2nd role * @param target * The role that is the target of the interaction * * @throws IllegalArgumentException * if any of the provided parameters is {@code null} * or the provided entities are not from the same guild * * @return True, if issuer can interact with target */ public static boolean canInteract(Role issuer, Role target) { Checks.notNull(issuer, "Issuer Role"); Checks.notNull(target, "Target Role"); if(!issuer.getGuild().equals(target.getGuild())) throw new IllegalArgumentException("The 2 Roles are not from same Guild!"); return target.getPosition() < issuer.getPosition(); }
/** * Checks if a given Member can interact with a given Role - in a permission sense (kick/ban/modify perms). * This only checks the Role-Position and does not check the actual permission (kick/ban/manage_role/...) * * @param issuer * The member that tries to interact with the role * @param target * The role that is the target of the interaction * * @throws IllegalArgumentException * if any of the provided parameters is {@code null} * or the provided entities are not from the same guild * * @return True, if issuer can interact with target */ public static boolean canInteract(Member issuer, Role target) { Checks.notNull(issuer, "Issuer Member"); Checks.notNull(target, "Target Role"); Guild guild = issuer.getGuild(); if (!guild.equals(target.getGuild())) throw new IllegalArgumentException("Provided Member issuer and Role target must be from the same Guild!"); if(guild.getOwner().equals(issuer)) return true; List<Role> issuerRoles = issuer.getRoles(); return !issuerRoles.isEmpty() && canInteract(issuerRoles.get(0), target); }
Checks.check(role.getGuild().equals(getGuild()), "Roles must all be from the same guild"); }); withLock(this.roles, (list) ->
@Override public int compareTo(Role r) { if (this == r) return 0; if (!this.getGuild().equals(r.getGuild())) throw new IllegalArgumentException("Cannot compare roles that aren't from the same guild!"); if (this.getPositionRaw() != r.getPositionRaw()) return this.getPositionRaw() - r.getPositionRaw(); OffsetDateTime thisTime = this.getCreationTime(); OffsetDateTime rTime = r.getCreationTime(); //We compare the provided role's time to this's time instead of the reverse as one would expect due to how // discord deals with hierarchy. The more recent a role was created, the lower its hierarchy ranking when // it shares the same position as another role. return rTime.compareTo(thisTime); }
checkGuild(role.getGuild(), "Role: " + role.toString()); checkPosition(role); });
@Override public PermissionOverrideAction putPermissionOverride(Role role) { checkPermission(Permission.MANAGE_PERMISSIONS); Checks.notNull(role, "role"); if (!getGuild().equals(role.getGuild())) throw new IllegalArgumentException("Provided role is not from the same guild as this channel!"); Route.CompiledRoute route = Route.Channels.CREATE_PERM_OVERRIDE.compile(getId(), role.getId()); return new PermissionOverrideAction(getJDA(), route, this, role); }
/** * Creates a new RoleManager instance * * @param role * {@link net.dv8tion.jda.core.entities.Role Role} that should be modified */ public RoleManager(Role role) { super(role.getJDA(), Route.Roles.MODIFY_ROLE.compile(role.getGuild().getId(), role.getId())); this.role = new UpstreamReference<>(role); if (isPermissionChecksEnabled()) checkPermissions(); }
checkGuild(role.getGuild(), "Role: " + role.toString()); checkPosition(role); Checks.check(!role.isManaged(), "Cannot add a Managed role to a Member. Role: %s", role.toString()); checkGuild(role.getGuild(), "Role: " + role.toString()); checkPosition(role); Checks.check(!role.isManaged(), "Cannot remove a Managed role from a Member. Role: %s", role.toString());
if (!guild.equals(role.getGuild())) throw new IllegalArgumentException("Provided channel and role are not of the same guild!");
Checks.notNull(role, "Role"); checkGuild(member.getGuild(), "Member"); checkGuild(role.getGuild(), "Role"); checkPermission(Permission.MANAGE_ROLES); checkPosition(role);
Checks.notNull(role, "Role"); checkGuild(member.getGuild(), "Member"); checkGuild(role.getGuild(), "Role"); checkPermission(Permission.MANAGE_ROLES); checkPosition(role);
Checks.notNull(role, "Role"); final Guild guild = role.getGuild(); checkGuild(channel.getGuild(), guild, "Role");
private void _mutateRole(Role role, Member member, boolean adding) { if (PermissionUtil.canInteract(role.getGuild().getSelfMember(), role)) { if (adding) { for (Role memberRole : member.getRoles()) { if (memberRole.getId().equals(role.getId())) { return; } } role.getGuild().getController().addRolesToMember(member, role).complete(); } else { boolean hasRole = false; for (Role memberRole : member.getRoles()) { if (memberRole.getId().equals(role.getId())) { hasRole = true; break; } } if (!hasRole) { return; } role.getGuild().getController().removeRolesFromMember(member, role).complete(); } } else { this.success = false; } } }
/** * Checks the given user ID to see if a user with the ID exists on the * AvaIre Central server, and if the user has the Bot Admin role. * * @param userId The user ID that should be checked if they're a role admin. * @return <code>True</code> if the user has the bot admin role on the AvaIre Central * support server, <code>False</code> otherwise. */ public AdminType isRoleAdmin(long userId) { Role role = avaire.getShardManager().getRoleById(DiscordConstants.BOT_ADMIN_EXCEPTION_ROLE); if (role == null) { return AdminType.USER; } Member member = role.getGuild().getMemberById(userId); if (member == null) { return AdminType.USER; } if (!RoleUtil.hasRole(member, role)) { return AdminType.USER; } return AdminType.ROLE_ADMIN; } }
public void run() { try { while (!Launcher.isBeingKilled) { final RoleModifyTask roleToModify = itemsToDelete.take(); if (roleToModify != null) { Guild guild = roleToModify.getRole().getGuild(); Member member = guild.getMember(roleToModify.getUser()); Role role = roleToModify.getRole(); if (member == null) { continue; } if (PermissionUtil.canInteract(guild.getSelfMember(), role)) { if (roleToModify.isAdd()) { guild.getController().addRolesToMember(member, role).complete(); } else { guild.getController().removeRolesFromMember(member, role).complete(); } } } } } catch (InterruptedException ignored) { } finally { processTerminated = true; } }