@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); }
/** * 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)); }
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); }
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. } }
.setTitle("#" + channel.getName()) .addField(context.i18n("fields.id"), channel.getId(), true) .addField(context.i18n("fields.position"), "" + channel.getPosition(), true)