@Override protected RequestBody finalizeData() { JSONObject data = new JSONObject(); if (shouldUpdate(NAME)) data.put("name", name); if (shouldUpdate(CHANNEL)) data.put("channel_id", channel); if (shouldUpdate(AVATAR)) data.put("avatar", avatar == null ? JSONObject.NULL : avatar.getEncoding()); return getRequestBody(data); }
/** * The {@link net.dv8tion.jda.core.entities.Guild Guild} this Manager's * {@link net.dv8tion.jda.core.entities.Webhook Webhook} is in. * <br>This is logically the same as calling {@code getWebhook().getGuild()} * * @return The parent {@link net.dv8tion.jda.core.entities.Guild Guild} */ public Guild getGuild() { return getWebhook().getGuild(); }
@Override protected boolean checkPermissions() { if (!getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_WEBHOOKS)) throw new InsufficientPermissionException(Permission.MANAGE_WEBHOOKS); return super.checkPermissions(); } }
/** * Creates a new WebhookManager instance * * @param webhook * The target {@link net.dv8tion.jda.core.entities.Webhook Webhook} to modify */ public WebhookManager(Webhook webhook) { super(webhook.getJDA(), Route.Webhooks.MODIFY_WEBHOOK.compile(webhook.getId())); this.webhook = new UpstreamReference<>(webhook); if (isPermissionChecksEnabled()) checkPermissions(); }
@Override public WebhookManager getManager() { if (isFake()) throw new IllegalStateException("Fake Webhooks (such as those retrieved from Audit Logs) " + "cannot provide a WebhookManager!"); WebhookManager mng = manager; if (mng == null) { mng = MiscUtil.locked(mngLock, () -> { if (manager == null) manager = new WebhookManager(this); return manager; }); } return mng; }
/** * Sets the {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} of the selected {@link net.dv8tion.jda.core.entities.Webhook Webhook}. * * <p>A webhook channel <b>must not</b> be {@code null} and <b>must</b> be in the same {@link net.dv8tion.jda.core.entities.Guild Guild}! * * @param channel * The new {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} * for the selected {@link net.dv8tion.jda.core.entities.Webhook Webhook} * * @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException * If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_WEBHOOKS MANAGE_WEBHOOKS} * in the specified TextChannel * @throws IllegalArgumentException * If the provided channel is {@code null} or from a different Guild * * @return WebhookManager for chaining convenience */ @CheckReturnValue public WebhookManager setChannel(TextChannel channel) { Checks.notNull(channel, "Channel"); Checks.check(channel.getGuild().equals(getGuild()), "Channel is not from the same guild"); this.channel = channel.getId(); set |= CHANNEL; return this; }
/** * The {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} this Manager's * {@link net.dv8tion.jda.core.entities.Webhook Webhook} is in. * <br>This is logically the same as calling {@code getWebhook().getChannel()} * * @return The parent {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} */ public TextChannel getChannel() { return getWebhook().getChannel(); }