@Override public GuildManager getManager() { GuildManager mng = manager; if (mng == null) { mng = MiscUtil.locked(mngLock, () -> { if (manager == null) manager = new GuildManager(this); return manager; }); } return mng; }
public GuildManager(Guild guild) { super(guild.getJDA(), Route.Guilds.MODIFY_GUILD.compile(guild.getId())); this.guild = new UpstreamReference<>(guild); if (isPermissionChecksEnabled()) checkPermissions(); }
@Override protected RequestBody finalizeData() { JSONObject body = new JSONObject().put("name", getGuild().getName()); if (shouldUpdate(NAME)) body.put("name", name); if (shouldUpdate(REGION)) body.put("region", region); if (shouldUpdate(AFK_TIMEOUT)) body.put("afk_timeout", afkTimeout); if (shouldUpdate(ICON)) body.put("icon", icon == null ? JSONObject.NULL : icon.getEncoding()); if (shouldUpdate(SPLASH)) body.put("splash", splash == null ? JSONObject.NULL : splash.getEncoding()); if (shouldUpdate(AFK_CHANNEL)) body.put("afk_channel_id", opt(afkChannel)); if (shouldUpdate(SYSTEM_CHANNEL)) body.put("system_channel_id", opt(systemChannel)); if (shouldUpdate(VERIFICATION_LEVEL)) body.put("verification_level", verificationLevel); if (shouldUpdate(NOTIFICATION_LEVEL)) body.put("default_message_notifications", notificationLevel); if (shouldUpdate(MFA_LEVEL)) body.put("mfa_level", mfaLevel); if (shouldUpdate(EXPLICIT_CONTENT_LEVEL)) body.put("explicit_content_filter", explicitContentLevel); reset(); //now that we've built our JSON object, reset the manager back to the non-modified state return getRequestBody(body); }
/** * Sets the Splash {@link net.dv8tion.jda.core.entities.Icon Icon} of this {@link net.dv8tion.jda.core.entities.Guild Guild}. * * @param splash * The new splash for this {@link net.dv8tion.jda.core.entities.Guild Guild} * or {@code null} to reset * * @throws IllegalArgumentException * If the guild's {@link net.dv8tion.jda.core.entities.Guild#getFeatures() features} does not include {@code INVITE_SPLASH} * * @return GuildManager for chaining convenience */ @CheckReturnValue public GuildManager setSplash(Icon splash) { Checks.check(splash == null || getGuild().getFeatures().contains("INVITE_SPLASH"), "Cannot set a splash on this guild"); this.splash = splash; set |= SPLASH; return this; }
private void stageChangeToOriginalRegion(CommandMessage context, Message message, Region region, Region swapRegion) { message.editMessage(buildTodoEmbed(context, swapRegion, region, true, false)) .queue(editMessage -> context.getGuild().getManager().setRegion(region).queueAfter(2500, TimeUnit.MILLISECONDS, bVoid -> { stageChangeHasFinished(context, editMessage, region, swapRegion); }, error -> logError(context, error) ), error -> logError(context, error)); }
@Override public boolean onCommand(CommandMessage context, String[] args) { Region region = context.getGuild().getRegion(); Region swapRegion = getRandomRegion(region); // Start the swapping process by sending the first status message and changing the server region to the swap region. context.getMessageChannel() .sendMessage(buildTodoEmbed(context, swapRegion, region, false, false)) .queue(message -> context.getGuild().getManager().setRegion(swapRegion).queue(aVoid -> { stageChangeToOriginalRegion(context, message, region, swapRegion); }, error -> logError(context, error) ), error -> logError(context, error)); return true; }
/** * Sets the system {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} of this {@link net.dv8tion.jda.core.entities.Guild Guild}. * * @param systemChannel * The new system channel for this {@link net.dv8tion.jda.core.entities.Guild Guild} * or {@code null} to reset * * @throws IllegalArgumentException * If the provided channel is not from this guild * * @return GuildManager for chaining convenience */ @CheckReturnValue public GuildManager setSystemChannel(TextChannel systemChannel) { Checks.check(systemChannel == null || systemChannel.getGuild().equals(getGuild()), "Channel must be from the same guild"); this.systemChannel = systemChannel == null ? null : systemChannel.getId(); set |= SYSTEM_CHANNEL; return this; }
/** * Sets the AFK {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannel} of this {@link net.dv8tion.jda.core.entities.Guild Guild}. * * @param afkChannel * The new afk channel for this {@link net.dv8tion.jda.core.entities.Guild Guild} * or {@code null} to reset * * @throws IllegalArgumentException * If the provided channel is not from this guild * * @return GuildManager for chaining convenience */ @CheckReturnValue public GuildManager setAfkChannel(VoiceChannel afkChannel) { Checks.check(afkChannel == null || afkChannel.getGuild().equals(getGuild()), "Channel must be from the same guild"); this.afkChannel = afkChannel == null ? null : afkChannel.getId(); set |= AFK_CHANNEL; return this; }
@Override protected boolean checkPermissions() { if (!getGuild().getSelfMember().hasPermission(Permission.MANAGE_SERVER)) throw new InsufficientPermissionException(Permission.MANAGE_SERVER); return super.checkPermissions(); } }
/** * Sets the {@link net.dv8tion.jda.core.Region Region} of this {@link net.dv8tion.jda.core.entities.Guild Guild}. * * @param region * The new region for this {@link net.dv8tion.jda.core.entities.Guild Guild} * * @throws IllegalArgumentException * If the provided region is a {@link net.dv8tion.jda.core.Region#isVip() VIP Region} but the guild does not support VIP regions. * Use {@link net.dv8tion.jda.core.entities.Guild#getFeatures() Guild#getFeatures()} to check if VIP regions are supported. * * @return GuildManager for chaining convenience * * @see net.dv8tion.jda.core.Region#isVip() * @see net.dv8tion.jda.core.entities.Guild#getFeatures() */ @CheckReturnValue public GuildManager setRegion(Region region) { Checks.notNull(region, "Region"); Checks.check(region != Region.UNKNOWN, "Region must not be UNKNOWN"); Checks.check(!region.isVip() || getGuild().getFeatures().contains("VIP_REGIONS"), "Cannot set a VIP voice region on this guild"); this.region = region.getKey(); set |= REGION; return this; }