Java 类net.dv8tion.jda.core.entities.PermissionOverride 实例源码

项目:happybot    文件:LockCommand.java   
@Override
protected void execute(CommandEvent e) {
    if (C.hasRole(e.getMember(), Roles.ADMIN)) {

        try {
            PermissionOverride permissionOverride = e.getTextChannel().getPermissionOverride(Roles.EVERYONE.getRole());
            PermOverrideManager manager = permissionOverride.getManager();
            manager.deny(Permission.MESSAGE_WRITE).queue();
            e.replySuccess(":lock: Channel has been locked!");
        } catch (NullPointerException npe) {
            e.replyError("An error occurred while locking the channel! Please make sure this channel is setup correctly.");
        }


    } else {
        e.replyError(C.permMsg(Roles.ADMIN));
    }
}
项目:happybot    文件:UnlockCommand.java   
@Override
protected void execute(CommandEvent e) {
    if (C.hasRole(e.getMember(), Roles.ADMIN)) {
        try {
            PermissionOverride permissionOverride = e.getTextChannel().getPermissionOverride(Roles.EVERYONE.getRole());
            PermOverrideManager manager = permissionOverride.getManager();
            manager.grant(Permission.MESSAGE_WRITE).queue();
            e.replySuccess(":unlock: Channel has been unlocked!");
        } catch (NullPointerException npe) {
            e.replyError("An error occurred while un-locking the channel! Please make sure this channel is setup correctly.");
        }
    } else {
        e.replyError(C.permMsg(Roles.ADMIN));
    }
}
项目:wolfia    文件:RoleAndPermissionUtils.java   
public static RestAction<Void> deleteIfCleared(final PermissionOverride permissionOverride) {
    //remove the whole override if it doesnt actually override any permission anymore
    if (permissionOverride != null && permissionOverride.getAllowed().isEmpty() && permissionOverride.getDenied().isEmpty()) {
        return permissionOverride.delete();
    } else {
        return new RestAction.EmptyRestAction<>(Wolfia.getFirstJda(), null);
    }
}
项目:wolfia    文件:RoleAndPermissionUtils.java   
@Nonnull
private static RestAction<?> setPermissionsInChannelForRoleOrMember(@Nonnull final Channel channel,
                                                                    @Nonnull final IPermissionHolder memberOrRole,
                                                                    @Nonnull final PermissionAction action,
                                                                    @Nonnull final Permission... permissions) {
    final PermissionOverride po;
    if (memberOrRole instanceof Role) {
        po = channel.getPermissionOverride((Role) memberOrRole);
    } else if (memberOrRole instanceof Member) {
        po = channel.getPermissionOverride((Member) memberOrRole);
    } else {
        log.warn("Unsupported class of IPermissionHolder detected: {}, returning an empty action", memberOrRole);
        return new RestAction.EmptyRestAction<>(channel.getJDA(), null);
    }

    final RestAction ra;
    if (po != null) {
        switch (action) {
            case GRANT:
                //do nothing if the permission override already grants the permission
                if (po.getAllowed().containsAll(Arrays.asList(permissions))) {
                    ra = new RestAction.EmptyRestAction<>(channel.getJDA(), null);
                } else {
                    ra = po.getManager().grant(permissions);
                }
                break;
            case DENY:
                //do nothing if the permission override already denies the permission
                if (po.getDenied().containsAll(Arrays.asList(permissions))) {
                    ra = new RestAction.EmptyRestAction<>(channel.getJDA(), null);
                } else {
                    ra = po.getManager().deny(permissions);
                }
                break;
            case CLEAR:
                //if the permission override becomes empty as a result of clearing these permissions, delete it
                final List<Permission> currentPerms = new ArrayList<>();
                currentPerms.addAll(po.getDenied());
                currentPerms.addAll(po.getAllowed());
                currentPerms.removeAll(Arrays.asList(permissions));

                if (currentPerms.isEmpty()) {
                    ra = po.delete();
                } else {
                    ra = po.getManager().clear(permissions);
                }
                break;
            default:
                throw new IllegalArgumentException("Unknown PermissionAction passed: " + action.name());
        }
    } else {
        final PermissionOverrideAction poa;
        if (memberOrRole instanceof Role) {
            poa = channel.createPermissionOverride((Role) memberOrRole);
        } else {
            poa = channel.createPermissionOverride((Member) memberOrRole);
        }
        switch (action) {
            case GRANT:
                ra = poa.setAllow(permissions);
                break;
            case DENY:
                ra = poa.setDeny(permissions);
                break;
            case CLEAR:
                //do nothing if we are trying to clear a nonexisting permission override
                ra = new RestAction.EmptyRestAction<>(channel.getJDA(), null);
                break;
            default:
                throw new IllegalArgumentException("Unknown PermissionAction passed: " + action.name());
        }
    }
    return ra;
}
项目:JDA    文件:PermOverrideManagerUpdatable.java   
/**
 * Creates a new PermOverrideManagerUpdatable instance
 *
 * @param override
 *        The {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverride} to manage
 */
public PermOverrideManagerUpdatable(PermissionOverride override)
{
    this.override = override;
}
项目:JDA    文件:PermOverrideManagerUpdatable.java   
/**
 * The target {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverride}
 * that will be modified by this Manager
 *
 * @return The target {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverride}
 */
public PermissionOverride getPermissionOverride()
{
    return override;
}
项目:JDA    文件:PermOverrideManager.java   
/**
 * Creates a new PermOverrideManager instance
 *
 * @param override
 *        The {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverride} to manage
 */
public PermOverrideManager(PermissionOverride override)
{
    updatable = new PermOverrideManagerUpdatable(override);
}
项目:JDA    文件:PermOverrideManager.java   
/**
 * The target {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverride}
 * that will be modified by this Manager
 *
 * @return The target {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverride}
 */
public PermissionOverride getPermissionOverride()
{
    return updatable.getPermissionOverride();
}