/** * The {@link net.dv8tion.jda.core.entities.Guild Guild} this Manager's * {@link net.dv8tion.jda.core.entities.Channel Channel} is in. * <br>This is logically the same as calling {@code getChannel().getGuild()} * * @return The parent {@link net.dv8tion.jda.core.entities.Guild Guild} */ public Guild getGuild() { return getChannel().getGuild(); }
/** * The {@link net.dv8tion.jda.core.entities.ChannelType ChannelType} * * @return The ChannelType */ public ChannelType getType() { return getChannel().getType(); }
/** * Syncs all {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverrides} of this Channel with * its parent ({@link net.dv8tion.jda.core.entities.Category Category}). * * <p>After this operation, all {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverrides} * will be exactly the same as the ones from the parent. * <br><b>That means that all current PermissionOverrides are lost!</b> * * <p>This behaves as if calling {@link #sync(Channel)} with this Channel's {@link net.dv8tion.jda.core.entities.Channel#getParent() Parent}. * * @throws java.lang.IllegalStateException * If this Channel has no parent * @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException * If the currently logged in account does not have {@link net.dv8tion.jda.core.Permission#MANAGE_PERMISSIONS Permission.MANAGE_PERMISSIONS} * in this channel * * @return ChannelManager for chaining convenience * * @see <a href="https://discordapp.com/developers/docs/topics/permissions#permission-syncing" target="_blank">Discord Documentation - Permission Syncing</a> */ @CheckReturnValue public ChannelManager sync() { if(getChannel().getParent() == null) throw new IllegalStateException("sync() requires a parent category"); return sync(getChannel().getParent()); }
@Override protected RequestBody finalizeData() { JSONObject frame = new JSONObject().put("name", getChannel().getName()); if (shouldUpdate(NAME)) frame.put("name", name); if (shouldUpdate(POSITION)) frame.put("position", position); if (shouldUpdate(TOPIC)) frame.put("topic", opt(topic)); if (shouldUpdate(NSFW)) frame.put("nsfw", nsfw); if (shouldUpdate(SLOWMODE)) frame.put("rate_limit_per_user", slowmode); if (shouldUpdate(USERLIMIT)) frame.put("user_limit", userlimit); if (shouldUpdate(BITRATE)) frame.put("bitrate", bitrate); if (shouldUpdate(PARENT)) frame.put("parent_id", opt(parent)); withLock(lock, (lock) -> { if (shouldUpdate(PERMISSION)) frame.put("permission_overwrites", getOverrides()); }); reset(); return getRequestBody(frame); }
@Override protected boolean checkPermissions() { final Member selfMember = getGuild().getSelfMember(); if (!selfMember.hasPermission(getChannel(), Permission.MANAGE_CHANNEL)) throw new InsufficientPermissionException(Permission.MANAGE_CHANNEL); return super.checkPermissions(); }
protected Collection<PermOverrideData> getOverrides() { //note: overridesAdd and overridesRem are mutually disjoint TLongObjectHashMap<PermOverrideData> data = new TLongObjectHashMap<>(this.overridesAdd); AbstractChannelImpl<?> impl = (AbstractChannelImpl<?>) getChannel(); impl.getOverrideMap().forEachEntry((id, override) -> { //removed by not adding them here, this data set overrides the existing one //we can use remove because it will be reset afterwards either way if (!overridesRem.remove(id) && !data.containsKey(id)) data.put(id, new PermOverrideData(override)); return true; }); return data.valueCollection(); }
Checks.check(getGuild().equals(syncSource.getGuild()), "Sync only works for channels of same guild"); if(syncSource.equals(getChannel())) return this; if (isPermissionChecksEnabled() && !getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(Permission.MANAGE_PERMISSIONS); getChannel().getPermissionOverrides().forEach(permO -> this.overridesRem.add(getId(permO.isRoleOverride() ? permO.getRole() : permO.getMember())) );
if (isPermissionChecksEnabled() && !getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(Permission.MANAGE_PERMISSIONS); final long id = getId(permHolder);
if (isPermissionChecksEnabled() && !getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(Permission.MANAGE_PERMISSIONS); final long id = getId(permHolder);