@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); }
@Override public String toString() { return "PermOver:(" + (isMemberOverride() ? "M" : "R") + ")(" + getChannel().getId() + " | " + id + ")"; }
/** * 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(); }
route = Route.Invites.GET_CHANNEL_INVITES.compile(channel.getId());
/** * Creates a new PermOverrideManager instance * * @param override * The {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverride} to manage */ public PermOverrideManager(PermissionOverride override) { super(override.getJDA(), Route.Channels.MODIFY_PERM_OVERRIDE.compile( override.getChannel().getId(), override.isMemberOverride() ? override.getMember().getUser().getId() : override.getRole().getId())); this.override = new UpstreamReference<>(override); this.allowed = override.getAllowedRaw(); this.denied = override.getDeniedRaw(); if (isPermissionChecksEnabled()) checkPermissions(); }
@Override public AuditableRestAction<Void> delete() { if (!getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(Permission.MANAGE_PERMISSIONS); String targetId = isRoleOverride() ? getRole().getId() : getMember().getUser().getId(); Route.CompiledRoute route = Route.Channels.DELETE_PERM_OVERRIDE.compile(getChannel().getId(), targetId); return new AuditableRestAction<Void>(getJDA(), route) { @Override protected void handleResponse(Response response, Request<Void> request) { if (response.isOk()) request.onSuccess(null); else request.onFailure(response); } }; }
/** * 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; }
private boolean handleVoice(CommandMessage context, String[] args) { if (args.length == 0) { context.getGuildTransformer().setMusicChannelVoice(null); updateDatabase(context, Type.VOICE, null); return true; } args = new String[]{String.join(" ", args)}; Channel channel = MentionableUtil.getChannel(context.getMessage(), args); if (channel == null || !(channel instanceof VoiceChannel)) { return sendErrorMessage(context, context.i18n("errors.notValidType", args[0], Type.VOICE.name().toLowerCase())); } context.getGuildTransformer().setMusicChannelVoice(channel.getId()); updateDatabase(context, Type.VOICE, channel); return true; }
private boolean handleText(CommandMessage context, String[] args) { if (args.length == 0) { context.getGuildTransformer().setMusicChannelText(null); updateDatabase(context, Type.TEXT, null); return true; } args = new String[]{String.join(" ", args)}; Channel channel = MentionableUtil.getChannel(context.getMessage(), args); if (channel == null || !(channel instanceof TextChannel)) { return sendErrorMessage(context, context.i18n("errors.notValidType", args[0], Type.TEXT.name().toLowerCase())); } context.getGuildTransformer().setMusicChannelText(channel.getId()); updateDatabase(context, Type.TEXT, channel); return true; }
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. } }
@Override public boolean onCommand(CommandMessage context, String[] args) { GuildTransformer transformer = context.getGuildTransformer(); if (transformer == null) { return sendErrorMessage(context, "errors.errorOccurredWhileLoading", "server settings"); } if (args.length == 0) { sendModlogChannel(context, transformer).queue(); return true; } if (ComparatorUtil.isFuzzyFalse(args[0])) { return disableModlog(context, transformer); } Channel channel = MentionableUtil.getChannel(context.getMessage(), args); if (channel == null || !(channel instanceof TextChannel)) { return sendErrorMessage(context, context.i18n("mustMentionTextChannel")); } if (!((TextChannel) channel).canTalk() || !context.getGuild().getSelfMember().hasPermission(channel, Permission.MESSAGE_EMBED_LINKS)) { return sendErrorMessage(context, context.i18n("cantSendEmbedMessages", ((TextChannel) channel).getAsMention())); } try { updateModlog(transformer, context, channel.getId()); context.makeSuccess(context.i18n("enable")) .set("modlog", ((TextChannel) channel).getAsMention()) .queue(); } catch (SQLException ex) { AvaIre.getLogger().error(ex.getMessage(), ex); } return true; }
.setColor(MessageType.INFO.getColor()) .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)