@Override public RoleManager getManager() { RoleManager mng = manager; if (mng == null) { mng = MiscUtil.locked(mngLock, () -> { if (manager == null) manager = new RoleManager(this); return manager; }); } return mng; }
@Override protected RequestBody finalizeData() { JSONObject object = new JSONObject().put("name", getRole().getName()); if (shouldUpdate(NAME)) object.put("name", name); if (shouldUpdate(PERMISSION)) object.put("permissions", permissions); if (shouldUpdate(HOIST)) object.put("hoist", hoist); if (shouldUpdate(MENTIONABLE)) object.put("mentionable", mentionable); if (shouldUpdate(COLOR)) object.put("color", color == Role.DEFAULT_COLOR_RAW ? 0 : color & 0xFFFFFF); reset(); return getRequestBody(object); }
/** * Revokes the specified {@link net.dv8tion.jda.core.Permission Permissions} from the selected {@link net.dv8tion.jda.core.entities.Role Role}. * * <p>Permissions may only include already present Permissions for the currently logged in account. * <br>You are unable to revoke permissions you don't have! * * @param perms * The permission to give to the selected {@link net.dv8tion.jda.core.entities.Role Role} * * @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException * If the currently logged in account does not have permission to revoke one of the specified permissions * * @return RoleManager for chaining convenience * * @see #setPermissions(Collection) * @see #setPermissions(Permission...) * @see net.dv8tion.jda.core.Permission#getRaw(net.dv8tion.jda.core.Permission...) Permission.getRaw(Permission...) */ @CheckReturnValue public RoleManager revokePermissions(Permission... perms) { Checks.notNull(perms, "Permissions"); return revokePermissions(Arrays.asList(perms)); }
private void setupPermissions() { if (!shouldUpdate(PERMISSION)) this.permissions = getRole().getPermissionsRaw(); } }
public RoleManager setPermissions(long perms) long selfPermissions = PermissionUtil.getEffectivePermission(getGuild().getSelfMember()); setupPermissions(); long missingPerms = perms; // include permissions we want to set to if (missingPerms != 0 && isPermissionChecksEnabled())
/** * 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(); }
@Override protected boolean checkPermissions() { Member selfMember = getGuild().getSelfMember(); if (!selfMember.hasPermission(Permission.MANAGE_ROLES)) throw new InsufficientPermissionException(Permission.MANAGE_ROLES); if (!selfMember.canInteract(getRole())) throw new HierarchyException("Cannot modify a role that is higher or equal in hierarchy"); return super.checkPermissions(); /* //we can't reliably check the permissions of the role here long missingRaw = permissions; missingRaw &= ~selfPermissions; // exclude own perms missingRaw &= ~role.getPermissionsRaw(); // exclude role perms if (missingRaw != 0) { List<Permission> missingPermissions = Permission.getPermissions(missingRaw); if (!missingPermissions.isEmpty()) throw new InsufficientPermissionException(missingPermissions.get(0)); } */ }
@Override public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message msg, String[] args, Member member) { if (guild.getGuildId().equals("226785954537406464") && PerGuildPermissions.isAdmin(sender)) { if (args.length == 0) { channel.sendMessage("You kinda need like.... a message to announce... like yeah...").queue(); return; } Role r = guild.getGuild().getRoleById(320304080926801922L); r.getManager().setMentionable(true).queue(aVoid -> { if (args[0].startsWith("pr:")) { channel.sendMessage(new MessageBuilder().setEmbed(GitHubUtils.getEmbedForPR(args[0].substring(3)) .build()).append(r.getAsMention()).build()).queue(bVoid -> channel.sendMessage("make sure to report any bugs over to be <#242206261767176192> channel " + "and if you need any support we're happy to help over in the <#226786463440699392> " + "channel!").queue() ); } else { String message = msg.getContentRaw(); message = message.substring(message.indexOf(" ") + 1); channel.sendMessage(new MessageBuilder().setContent(r.getAsMention()) .setEmbed(new EmbedBuilder().setTitle("Some announcement thing!").setDescription(message) .setFooter("Announcement by " + member.getEffectiveName(), sender.getEffectiveAvatarUrl()).build()).build()) .complete(); } }); r.getManager().setMentionable(false).queue(); } }
/** * 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(); }
/** * Adds the specified {@link net.dv8tion.jda.core.Permission Permissions} to the selected {@link net.dv8tion.jda.core.entities.Role Role}. * * <p>Permissions may only include already present Permissions for the currently logged in account. * <br>You are unable to give permissions you don't have! * * @param perms * The permission to give to the selected {@link net.dv8tion.jda.core.entities.Role Role} * * @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException * If the currently logged in account does not have permission to apply one of the specified permissions * * @return RoleManager for chaining convenience * * @see #setPermissions(Collection) * @see #setPermissions(Permission...) * @see net.dv8tion.jda.core.Permission#getRaw(net.dv8tion.jda.core.Permission...) Permission.getRaw(Permission...) */ @CheckReturnValue public RoleManager givePermissions(Permission... perms) { Checks.notNull(perms, "Permissions"); return givePermissions(Arrays.asList(perms)); }