@Override public ChannelManager getManager() { ChannelManager mng = manager; if (mng == null) { mng = MiscUtil.locked(mngLock, () -> { if (manager == null) manager = new ChannelManager(this); return manager; }); } return mng; }
@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); }
Checks.check(permHolder.getGuild().equals(getGuild()), "PermissionHolder is not from the same Guild!"); if (isPermissionChecksEnabled() && !getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(Permission.MANAGE_PERMISSIONS); final long id = getId(permHolder); withLock(lock, (lock) ->
/** * 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 boolean checkPermissions() { final Member selfMember = getGuild().getSelfMember(); if (!selfMember.hasPermission(getChannel(), Permission.MANAGE_CHANNEL)) throw new InsufficientPermissionException(Permission.MANAGE_CHANNEL); return super.checkPermissions(); }
@Override public void run() { while (true) { if (MagiBridge.getConfig().CORE.ENABLE_UPDATER && MagiBridge.jda.getStatus() == JDA.Status.CONNECTED) { String topic = FormatType.TOPIC_FORMAT.get() .replace("%players%", Integer.valueOf(Sponge.getServer().getOnlinePlayers().size()).toString()) .replace("%maxplayers%", Integer.valueOf(Sponge.getServer().getMaxPlayers()).toString()) .replace("%tps%", Long.valueOf(Math.round(Sponge.getServer().getTicksPerSecond())).toString()) .replace("%daysonline%", Long.valueOf(ManagementFactory.getRuntimeMXBean().getUptime() / (24 * 60 * 60 * 1000)).toString()) .replace("%hoursonline%", Long.valueOf((ManagementFactory.getRuntimeMXBean().getUptime() / (60 * 60 * 1000)) % 24).toString()) .replace("%minutesonline%", Long.valueOf((ManagementFactory.getRuntimeMXBean().getUptime() / (60 * 1000)) % 60).toString()); try { if (MagiBridge.jda.getTextChannelById(MagiBridge.getConfig().CHANNELS.MAIN_CHANNEL) == null) { MagiBridge.getLogger().error("The main-discord-channel is INVALID, replace it with a valid one and restart the server!"); continue; } MagiBridge.jda.getTextChannelById(MagiBridge.getConfig().CHANNELS.MAIN_CHANNEL).getManager().setTopic(topic).queue(); } catch (NullPointerException e) { e.printStackTrace(); } } int interval = MagiBridge.getConfig().CORE.UPDATER_INTERVAL * 1000; try { Thread.sleep(interval < 10000 ? 10000 : interval); } catch (InterruptedException e) { MagiBridge.getLogger().error("The topic updater was interrupted!"); e.printStackTrace(); } } }
private boolean updateChannelStatus(CommandMessage context, TextChannel textChannel, boolean status) { textChannel.getManager().setNSFW(status).queue(aVoid -> { context.makeSuccess(context.i18n("updated")) .set("textChannel", textChannel.getAsMention()) .set("status", context.i18n("status." + (status ? "enabled" : "disabled"))) .queue(); }, throwable -> { context.makeError("Something went wrong while trying to update the channel status: " + throwable.getLocalizedMessage()) .queue(); }); return true; }
channel.getManager().setSlowmode(0).queue(null, RestActionUtil.ignore); channel.getManager().setSlowmode(slowmode).queue(aVoid -> { context.makeSuccess(context.i18n("message")) .set("textChannel", channel.getAsMention())
if (musicChannel != null && PermissionUtil.checkPermission(musicChannel, guild.getSelfMember(), Permission.MANAGE_CHANNEL)) { if (!isUpdateChannelTitle()) { bot.queue.add(musicChannel.getManager().setTopic("\uD83C\uDFB6 " + record.youtubeTitle));
/** * Sets the <b><u>{@link net.dv8tion.jda.core.entities.Category Parent Category}</u></b> * of the selected {@link net.dv8tion.jda.core.entities.Channel Channel}. * * * @param category * The new parent for the selected {@link net.dv8tion.jda.core.entities.Channel Channel} * * @throws IllegalStateException * If the target is a category itself * @throws IllegalArgumentException * If the provided category is not from the same Guild * * @return ChannelManager for chaining convenience * * @since 3.4.0 */ @CheckReturnValue public ChannelManager setParent(Category category) { if (category != null) { if (getType() == ChannelType.CATEGORY) throw new IllegalStateException("Cannot set the parent of a category"); Checks.check(category.getGuild().equals(getGuild()), "Category is not from the same guild"); } this.parent = category == null ? null : category.getId(); set |= PARENT; return this; }
/** * 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(); }
/** * The {@link net.dv8tion.jda.core.entities.ChannelType ChannelType} * * @return The ChannelType */ public ChannelType getType() { return getChannel().getType(); }
public void stopStuff(Boolean fake) { if (!fake) { if (jda != null) { DiscordHandler.sendMessageToChannel(Config.CHANNELS.MAIN_CHANNEL, Config.MESSAGES.SERVER_STOPPING); DiscordHandler.close(); if (updater != null) updater.interrupt(); jda.getTextChannelById(Config.CHANNELS.MAIN_CHANNEL).getManager().setTopic(FormatType.OFFLINE_TOPIC_FORMAT.get()).queue(); jda.shutdown(); long time = System.currentTimeMillis(); while ((System.currentTimeMillis() - time < 10000) && (jda != null && jda.getStatus() != JDA.Status.SHUTDOWN)) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } return; } } logger.info("Disconnecting from Discord..."); if (jda != null && jda.getStatus() != JDA.Status.SHUTDOWN && jda.getStatus() != JDA.Status.SHUTTING_DOWN) { jda.shutdownNow(); } // Unregistering listeners Sponge.getEventManager().unregisterPluginListeners(this); Sponge.getEventManager().registerListeners(this, this); Config = null; }
public ChannelManager setBitrate(int bitrate) if (getType() != ChannelType.VOICE) throw new IllegalStateException("Can only set bitrate on voice channels"); final int maxBitrate = getGuild().getFeatures().contains("VIP_REGIONS") ? 128000 : 96000; Checks.check(bitrate >= 8000, "Bitrate must be greater or equal to 8000"); Checks.check(bitrate <= maxBitrate, "Bitrate must be less or equal to %s", maxBitrate);
/** * The {@link net.dv8tion.jda.core.entities.Guild Guild} this Manager's * {@link net.dv8tion.jda.core.entities.Channel Channel} is in. * <br>This is logically the same as calling {@code getChannel().getGuild()} * * @return The parent {@link net.dv8tion.jda.core.entities.Guild Guild} */ public Guild getGuild() { return getChannel().getGuild(); }
Checks.check(permHolder.getGuild().equals(getGuild()), "PermissionHolder is not from the same Guild!"); if (isPermissionChecksEnabled() && !getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(Permission.MANAGE_PERMISSIONS); final long id = getId(permHolder); final int type = permHolder instanceof Role ? PermOverrideData.ROLE_TYPE : PermOverrideData.MEMBER_TYPE; withLock(lock, (lock) ->
protected Collection<PermOverrideData> getOverrides() { //note: overridesAdd and overridesRem are mutually disjoint TLongObjectHashMap<PermOverrideData> data = new TLongObjectHashMap<>(this.overridesAdd); AbstractChannelImpl<?> impl = (AbstractChannelImpl<?>) getChannel(); impl.getOverrideMap().forEachEntry((id, override) -> { //removed by not adding them here, this data set overrides the existing one //we can use remove because it will be reset afterwards either way if (!overridesRem.remove(id) && !data.containsKey(id)) data.put(id, new PermOverrideData(override)); return true; }); return data.valueCollection(); }
Checks.check(getGuild().equals(syncSource.getGuild()), "Sync only works for channels of same guild"); if(syncSource.equals(getChannel())) return this; if (isPermissionChecksEnabled() && !getGuild().getSelfMember().hasPermission(getChannel(), Permission.MANAGE_PERMISSIONS)) throw new InsufficientPermissionException(Permission.MANAGE_PERMISSIONS); withLock(lock, (lock) -> getChannel().getPermissionOverrides().forEach(permO -> this.overridesRem.add(getId(permO.isRoleOverride() ? permO.getRole() : permO.getMember())) ); long id = getId(permO.isRoleOverride() ? permO.getRole() : permO.getMember());