@Override public List<Permission> getDenied() { return Collections.unmodifiableList(Permission.getPermissions(deny)); }
@Override public String getInviteUrl(Collection<Permission> permissions) { StringBuilder builder = buildBaseInviteUrl(); if (permissions != null && !permissions.isEmpty()) builder.append("&permissions=").append(Permission.getRaw(permissions)); return builder.toString(); }
@Override public boolean hasPermission(Channel channel, Permission... permissions) { long effectivePerms = PermissionUtil.getEffectivePermission(channel, this); for (Permission perm : permissions) { final long rawValue = perm.getRawValue(); if ((effectivePerms & rawValue) != rawValue) return false; } return true; }
/** * Checks if the given permission value includes the raw embed permission value. * * @param permissions The permission value that should be checked. * @return <code>True</code> if the given raw permission value includes * the embed permissions, <code>False</code> otherwise. */ private static boolean checkForRawEmbedPermission(long permissions) { for (Permission permission : Permission.getPermissions(permissions)) { if (permission.getRawValue() == 0x00004000) { return true; } } return false; }
AuditLogChange change = changes.get("permissions"); Map<Boolean, List<Permission>> permChanges = GeneralUtils.getChanged( Permission.getPermissions(((Integer) change.getOldValue()).longValue()), Permission.getPermissions(((Integer) change.getNewValue()).longValue())); if (permChanges.get(true).size() > 0) { StringBuilder added = new StringBuilder(); for (Permission addedPerm : permChanges.get(true)) { added.append(addedPerm.getName()).append("\n"); StringBuilder removed = new StringBuilder(); for (Permission removedPerm : permChanges.get(false)) { removed.append(removedPerm.getName()).append("\n");
@Override public String getDescription() { return "Disables the slowmode or enables it with the given limit, users with the **" + Permissions.MESSAGE_MANAGE.getPermission().getName() + "** or **" + Permissions.MANAGE_CHANNEL.getPermission().getName() + "** permissions are exempt from slowmode limits."; }
/** * Checks to see if the {@link net.dv8tion.jda.core.entities.Member Member} has the specified {@link net.dv8tion.jda.core.Permission Permissions} * in the specified {@link net.dv8tion.jda.core.entities.Guild Guild}. This method properly deals with Owner status. * * <p><b>Note:</b> this is based on effective permissions, not literal permissions. If a member has permissions that would * enable them to do something without the literal permission to do it, this will still return true. * <br>Example: If a member has the {@link net.dv8tion.jda.core.Permission#ADMINISTRATOR} permission, they will be able to * {@link net.dv8tion.jda.core.Permission#MANAGE_SERVER} as well, even without the literal permissions. * * @param member * The {@link net.dv8tion.jda.core.entities.Member Member} whose permissions are being checked. * @param permissions * The {@link net.dv8tion.jda.core.Permission Permissions} being checked for. * * @throws IllegalArgumentException * if any of the provided parameters is null * * @return True - * if the {@link net.dv8tion.jda.core.entities.Member Member} effectively has the specified {@link net.dv8tion.jda.core.Permission Permissions}. */ public static boolean checkPermission(Member member, Permission... permissions) { Checks.notNull(member, "Member"); Checks.notNull(permissions, "Permissions"); long effectivePerms = getEffectivePermission(member); return isApplied(effectivePerms, Permission.ADMINISTRATOR.getRawValue()) || isApplied(effectivePerms, Permission.getRaw(permissions)); }
/** * Creates a new PermissionException instance * * @param permission * The required {@link net.dv8tion.jda.core.Permission Permission} */ protected PermissionException(Permission permission) { this(permission, "Cannot perform action due to a lack of Permission. Missing permission: " + permission.toString()); }
/** * Gets the first {@link net.dv8tion.jda.core.Permission Permission} relating to the provided offset. * <br>If there is no {@link net.dv8tion.jda.core.Permission Permssions} that matches the provided * offset, {@link net.dv8tion.jda.core.Permission#UNKNOWN Permission.UNKNOWN} is returned. * * @param offset * The offset to match a {@link net.dv8tion.jda.core.Permission Permission} to. * * @return {@link net.dv8tion.jda.core.Permission Permission} relating to the provided offset. */ public static Permission getFromOffset(int offset) { for (Permission perm : values()) { if (perm.offset == offset) return perm; } return UNKNOWN; }
return Templates.permission_missing.formatGuild(channel, getRequiredPermission().name());
@Override public boolean hasPermission(JDACommandManager manager, JDACommandEvent event, String permission) { // Explicitly return true if the issuer is the bot's owner. They are always allowed. if (manager.getBotOwnerId() == event.getIssuer().getAuthor().getIdLong()) { return true; } // Return false on webhook messages, as they cannot have permissions defined. if (event.getIssuer().isWebhookMessage()) { return false; } Integer permissionOffset = discordPermissionOffsets.get(permission); if (permissionOffset == null) { return false; } return event.getIssuer().getMember().hasPermission( Permission.getFromOffset(permissionOffset) ); } }
/** * Formats the permission middleware description message * if only one argument was given to the middleware. * * @param arguments The first argument given to the middleware. * @return Possibly-null, the formatted string if the given argument is a valid permission node. */ @Nullable public static String formatWithOneArgument(PermissionType type, String arguments) { Permissions node = Permissions.fromNode(arguments); if (node != null) { return String.format(getPermissionTypeMessage(type), node.getPermission().getName() ); } return null; }
return isApplied(effectivePerms, Permission.ADMINISTRATOR.getRawValue()) || isApplied(effectivePerms, Permission.getRaw(permissions));
public InsufficientPermissionException(Permission permission) { super(permission, "Cannot perform action due to a lack of Permission. Missing permission: " + permission.toString()); }
/** * Constructs an {@link java.util.EnumSet EnumSet} from the provided permissions bitmask. * <br>If provided with {@code 0} this will fast-fail with an empty set. * * @param permissions * The permission bitmask * * @return Possibly-empty {@link java.util.EnumSet EnumSet} containing the constants for this permission bitmask */ public static EnumSet<Permission> toEnumSet(long permissions) { EnumSet<Permission> set = EnumSet.noneOf(Permission.class); if (permissions == 0) return set; for (Permission perm : values()) { if (perm != UNKNOWN && (permissions & perm.raw) == perm.raw) set.add(perm); } return set; }
@Override public String getInviteUrl(Permission... permissions) { StringBuilder builder = buildBaseInviteUrl(); if (permissions != null && permissions.length > 0) builder.append("&permissions=").append(Permission.getRaw(permissions)); return builder.toString(); }
/** * Immutable list of {@link net.dv8tion.jda.core.Permission Permissions} * that would be <b>granted</b> by the PermissionOverride that is created by this action. * * @return immutable list of granted {@link net.dv8tion.jda.core.Permission Permissions} */ public List<Permission> getAllowedPermissions() { return Collections.unmodifiableList(Permission.getPermissions(allow)); }
throw new PermissionException(Permission.VOICE_CONNECT.getName());
Guild guild = ((TextChannel) channel).getGuild(); if (!PermissionUtil.checkPermission(guild.getSelfMember(), Permission.MANAGE_ROLES)) { return Templates.permission_missing.formatGuild(channel, Permission.MANAGE_ROLES.toString());