/** * 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() { final Member self = guild.getSelfMember(); if (!self.hasPermission(Permission.MANAGE_CHANNEL)) throw new InsufficientPermissionException(Permission.MANAGE_CHANNEL); JSONArray array = new JSONArray(); for (int i = 0; i < orderList.size(); i++) { Channel chan = orderList.get(i); array.put(new JSONObject() .put("id", chan.getId()) .put("position", i)); } return getRequestBody(array); }
default ChannelAction createCopy() return createCopy(getGuild());
/** * Creates a new ChannelManager instance * * @param channel * {@link net.dv8tion.jda.core.entities.Channel Channel} that should be modified * <br>Either {@link net.dv8tion.jda.core.entities.VoiceChannel Voice}- or {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} */ public ChannelManager(Channel channel) { super(channel.getJDA(), Route.Channels.MODIFY_CHANNEL.compile(channel.getId())); this.channel = new UpstreamReference<>(channel); if (isPermissionChecksEnabled()) checkPermissions(); this.overridesAdd = new TLongObjectHashMap<>(); this.overridesRem = new TLongHashSet(); }
private void handleChannelCreate(GuildWrapper wrapper, Channel channel) { if (cannotHandle(wrapper, ModlogEvent.CHANNEL_CREATE)) return; AuditLogEntry entry = wrapper.getGuild().getAuditLogs().complete().get(0); EmbedBuilder builder = new EmbedBuilder() .addField("Type", channel.getType().name().toLowerCase(), true) .addField("Name", channel.getName(), true); if (channel.getParent() != null) { builder.addField("Category", channel.getParent().getName(), true); } ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.CHANNEL_CREATE, entry.getUser(), builder); }
Carbon time = Carbon.createFromOffsetDateTime(channel.getCreationTime()); .setTitle("#" + channel.getName()) .addField(context.i18n("fields.id"), channel.getId(), true) .addField(context.i18n("fields.position"), "" + channel.getPosition(), true) .addField(context.i18n("fields.users"), "" + channel.getMembers().size(), true) .addField(context.i18n("fields.category"), getCategoryFor(channel), true);
/** * Parses the given message for all the channel * placeholders using the given channel object. * * @param channel The channel object that should be used to parse the placeholders. * @param string The original string that should be parsed. * @return The parsed string after all the channel placeholders was parsed. */ public static String parseChannel(@Nonnull Channel channel, @Nonnull String string) { string = string.replaceAll("%channel%", "<#" + channel.getId() + ">"); string = string.replaceAll("%channelname%", Matcher.quoteReplacement(channel.getName())); string = string.replaceAll("%channelid%", channel.getId()); return string; }
@Override public boolean onCommand(CommandMessage context, String[] args) { if (args.length == 0) { return sendErrorMessage(context, context.i18n("missingArgument")); } Channel channel = MentionableUtil.getChannel(context.getMessage(), args); if (channel == null) { return handleSlowmode(context, context.getChannel(), args); } if (!channel.getType().equals(ChannelType.TEXT)) { return sendErrorMessage(context, "invalidTextChannel", channel.getName()); } return handleSlowmode(context, (TextChannel) channel, Arrays.copyOfRange(args, 1, args.length)); }
/** * The {@link net.dv8tion.jda.core.entities.ChannelType ChannelType} * * @return The ChannelType */ public ChannelType getType() { return getChannel().getType(); }
Member member = chan.getGuild().getMemberById(id); if (member == null) throw new NoSuchElementException("Attempted to create a PermissionOverride for a non-existent user. Guild: " + chan.getGuild() + ", Channel: " + chan + ", JSON: " + override); permOverride = (PermissionOverrideImpl) chan.getPermissionOverride(member); if (permOverride == null) Role role = ((GuildImpl) chan.getGuild()).getRolesMap().get(id); if (role == null) throw new NoSuchElementException("Attempted to create a PermissionOverride for a non-existent role! JSON: " + override); permOverride = (PermissionOverrideImpl) chan.getPermissionOverride(role); if (permOverride == null)
@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 public Guild getGuild() { return getChannel().getGuild(); }
Checks.check(getGuild().equals(syncSource.getGuild()), "Sync only works for channels of same guild"); getChannel().getPermissionOverrides().forEach(permO -> this.overridesRem.add(getId(permO.isRoleOverride() ? permO.getRole() : permO.getMember())) ); syncSource.getPermissionOverrides().forEach(permO ->
@Override public boolean equals(Object obj) { if (!(obj instanceof Channel)) return false; if (obj == this) return true; Channel channel = (Channel) obj; return channel.getIdLong() == getIdLong(); }
return channel.createCopy(getGuild());
private boolean kickUser(CommandMessage context, Member user, String[] args) { String reason = generateMessage(args); String originalVoiceChannelName = user.getVoiceState().getChannel().getName(); String originalVoiceChannelId = user.getVoiceState().getChannel().getId(); context.getGuild().getController().createVoiceChannel("kick-" + user.getUser().getId()).queue(channel -> context.getGuild().getController().moveVoiceMember(user, (VoiceChannel) channel) .queue(empty -> channel.delete().queue((Consumer<Void>) aVoid -> { Modlog.log(avaire, context, new ModlogAction( ModlogType.VOICE_KICK, context.getAuthor(), user.getUser(), originalVoiceChannelName + " (ID: " + originalVoiceChannelId + ")\n" + reason ) ); context.makeSuccess(context.i18n("message")) .set("target", user.getUser().getName() + "#" + user.getUser().getDiscriminator()) .set("voiceChannel", originalVoiceChannelName) .set("reason", reason) .queue(ignoreMessage -> context.delete().queue(null, RestActionUtil.ignore)); }, RestActionUtil.ignore) ) ); return true; }
private void handleChannelDelete(GuildWrapper wrapper, Channel channel) { if (wrapper == null) return; if (cannotHandle(wrapper, ModlogEvent.CHANNEL_DELETE)) return; AuditLogEntry entry = wrapper.getGuild().getAuditLogs().complete().get(0); EmbedBuilder builder = new EmbedBuilder() .addField("Type", channel.getType().name().toLowerCase(), true) .addField("Name", channel.getName(), true); if (channel.getParent() != null) { builder.addField("Category", channel.getParent().getName(), true); } ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.CHANNEL_DELETE, entry.getUser(), builder); }
private void updateDatabase(CommandMessage context, Type type, Channel value) { try { avaire.getDatabase().newQueryBuilder(Constants.GUILD_TABLE_NAME) .useAsync(true) .where("id", context.getGuild().getId()) .update(statement -> statement.set(type.getField(), value == null ? null : value.getId())); String status = null; if (value != null) { status = (value instanceof TextChannel) ? ((TextChannel) value).getAsMention() : value.getName(); } context.makeSuccess(context.i18n("updated")) .set("type", type.name().toLowerCase()) .set("status", value == null ? context.i18n("status.disabled") : context.i18n("status.enabled", status) ) .queue(); } catch (SQLException ignored) { // Since we're running the query as async we won't really need to // check for errors since that is handled by the database thread. } }
Checks.notNull(role, "Role"); Guild guild = channel.getGuild(); if (!guild.equals(role.getGuild())) throw new IllegalArgumentException("Provided channel and role are not of the same guild!"); PermissionOverride publicOverride = channel.getPermissionOverride(guild.getPublicRole()); PermissionOverride roleOverride = channel.getPermissionOverride(role);