Search in sources :

Example 1 with ServerChannelChangeNsfwFlagEvent

use of org.javacord.api.event.channel.server.ServerChannelChangeNsfwFlagEvent in project Javacord by BtoBastian.

the class ChannelUpdateHandler method handleChannelCategory.

/**
 * Handles a channel category update.
 *
 * @param jsonChannel The channel data.
 */
private void handleChannelCategory(JsonNode jsonChannel) {
    long channelCategoryId = jsonChannel.get("id").asLong();
    api.getChannelCategoryById(channelCategoryId).map(ChannelCategoryImpl.class::cast).ifPresent(channel -> {
        boolean oldNsfwFlag = channel.isNsfw();
        boolean newNsfwFlag = jsonChannel.get("nsfw").asBoolean();
        if (oldNsfwFlag != newNsfwFlag) {
            channel.setNsfwFlag(newNsfwFlag);
            ServerChannelChangeNsfwFlagEvent event = new ServerChannelChangeNsfwFlagEventImpl(channel, newNsfwFlag, oldNsfwFlag);
            api.getEventDispatcher().dispatchServerChannelChangeNsfwFlagEvent((DispatchQueueSelector) channel.getServer(), channel, channel.getServer(), null, event);
        }
    });
}
Also used : ServerChannelChangeNsfwFlagEventImpl(org.javacord.core.event.channel.server.ServerChannelChangeNsfwFlagEventImpl) ServerChannelChangeNsfwFlagEvent(org.javacord.api.event.channel.server.ServerChannelChangeNsfwFlagEvent)

Example 2 with ServerChannelChangeNsfwFlagEvent

use of org.javacord.api.event.channel.server.ServerChannelChangeNsfwFlagEvent in project Javacord by BtoBastian.

the class ChannelUpdateHandler method handleServerTextChannel.

/**
 * Handles a server text channel update.
 *
 * @param jsonChannel The json channel data.
 */
private void handleServerTextChannel(JsonNode jsonChannel) {
    long channelId = jsonChannel.get("id").asLong();
    Optional<ServerTextChannel> optionalChannel = api.getServerTextChannelById(channelId);
    if (!optionalChannel.isPresent()) {
        LoggerUtil.logMissingChannel(logger, channelId);
        return;
    }
    ServerTextChannelImpl channel = (ServerTextChannelImpl) optionalChannel.get();
    String oldTopic = channel.getTopic();
    String newTopic = jsonChannel.has("topic") && !jsonChannel.get("topic").isNull() ? jsonChannel.get("topic").asText() : "";
    if (!oldTopic.equals(newTopic)) {
        channel.setTopic(newTopic);
        ServerTextChannelChangeTopicEvent event = new ServerTextChannelChangeTopicEventImpl(channel, newTopic, oldTopic);
        api.getEventDispatcher().dispatchServerTextChannelChangeTopicEvent((DispatchQueueSelector) channel.getServer(), channel.getServer(), channel, event);
    }
    boolean oldNsfwFlag = channel.isNsfw();
    boolean newNsfwFlag = jsonChannel.get("nsfw").asBoolean();
    if (oldNsfwFlag != newNsfwFlag) {
        channel.setNsfwFlag(newNsfwFlag);
        ServerChannelChangeNsfwFlagEvent event = new ServerChannelChangeNsfwFlagEventImpl(channel, newNsfwFlag, oldNsfwFlag);
        api.getEventDispatcher().dispatchServerChannelChangeNsfwFlagEvent((DispatchQueueSelector) channel.getServer(), null, channel.getServer(), channel, event);
    }
    int oldSlowmodeDelay = channel.getSlowmodeDelayInSeconds();
    // Check if "rate_limit_per_user" exists as a temporary fix until SERVER_NEWS_CHANNEL is handled separately.
    int newSlowmodeDelay = jsonChannel.has("rate_limit_per_user") ? jsonChannel.get("rate_limit_per_user").asInt(0) : 0;
    if (oldSlowmodeDelay != newSlowmodeDelay) {
        channel.setSlowmodeDelayInSeconds(newSlowmodeDelay);
        ServerTextChannelChangeSlowmodeEvent event = new ServerTextChannelChangeSlowmodeEventImpl(channel, oldSlowmodeDelay, newSlowmodeDelay);
        api.getEventDispatcher().dispatchServerTextChannelChangeSlowmodeEvent((DispatchQueueSelector) channel.getServer(), channel.getServer(), channel, event);
    }
    int oldDefaultAutoArchiveDuration = channel.getDefaultAutoArchiveDuration();
    int newDefaultAutoArchiveDuration = jsonChannel.has("default_auto_archive_duration") ? jsonChannel.get("default_auto_archive_duration").asInt() : 1440;
    if (oldDefaultAutoArchiveDuration != newDefaultAutoArchiveDuration) {
        channel.setDefaultAutoArchiveDuration(newDefaultAutoArchiveDuration);
        ServerTextChannelChangeDefaultAutoArchiveDurationEvent event = new ServerTextChannelChangeDefaultAutoArchiveDurationEventImpl(channel, oldDefaultAutoArchiveDuration, newDefaultAutoArchiveDuration);
        api.getEventDispatcher().dispatchServerTextChannelChangeDefaultAutoArchiveDurationEvent((DispatchQueueSelector) channel.getServer(), channel.getServer(), channel, event);
    }
}
Also used : ServerChannelChangeNsfwFlagEventImpl(org.javacord.core.event.channel.server.ServerChannelChangeNsfwFlagEventImpl) ServerTextChannelChangeTopicEvent(org.javacord.api.event.channel.server.text.ServerTextChannelChangeTopicEvent) ServerTextChannelChangeTopicEventImpl(org.javacord.core.event.channel.server.text.ServerTextChannelChangeTopicEventImpl) ServerTextChannelChangeDefaultAutoArchiveDurationEventImpl(org.javacord.core.event.channel.server.text.ServerTextChannelChangeDefaultAutoArchiveDurationEventImpl) ServerChannelChangeNsfwFlagEvent(org.javacord.api.event.channel.server.ServerChannelChangeNsfwFlagEvent) ServerTextChannel(org.javacord.api.entity.channel.ServerTextChannel) ServerTextChannelChangeSlowmodeEvent(org.javacord.api.event.channel.server.text.ServerTextChannelChangeSlowmodeEvent) ServerTextChannelChangeDefaultAutoArchiveDurationEvent(org.javacord.api.event.channel.server.text.ServerTextChannelChangeDefaultAutoArchiveDurationEvent) ServerTextChannelChangeSlowmodeEventImpl(org.javacord.core.event.channel.server.text.ServerTextChannelChangeSlowmodeEventImpl) ServerTextChannelImpl(org.javacord.core.entity.channel.ServerTextChannelImpl)

Aggregations

ServerChannelChangeNsfwFlagEvent (org.javacord.api.event.channel.server.ServerChannelChangeNsfwFlagEvent)2 ServerChannelChangeNsfwFlagEventImpl (org.javacord.core.event.channel.server.ServerChannelChangeNsfwFlagEventImpl)2 ServerTextChannel (org.javacord.api.entity.channel.ServerTextChannel)1 ServerTextChannelChangeDefaultAutoArchiveDurationEvent (org.javacord.api.event.channel.server.text.ServerTextChannelChangeDefaultAutoArchiveDurationEvent)1 ServerTextChannelChangeSlowmodeEvent (org.javacord.api.event.channel.server.text.ServerTextChannelChangeSlowmodeEvent)1 ServerTextChannelChangeTopicEvent (org.javacord.api.event.channel.server.text.ServerTextChannelChangeTopicEvent)1 ServerTextChannelImpl (org.javacord.core.entity.channel.ServerTextChannelImpl)1 ServerTextChannelChangeDefaultAutoArchiveDurationEventImpl (org.javacord.core.event.channel.server.text.ServerTextChannelChangeDefaultAutoArchiveDurationEventImpl)1 ServerTextChannelChangeSlowmodeEventImpl (org.javacord.core.event.channel.server.text.ServerTextChannelChangeSlowmodeEventImpl)1 ServerTextChannelChangeTopicEventImpl (org.javacord.core.event.channel.server.text.ServerTextChannelChangeTopicEventImpl)1