use of org.javacord.core.event.channel.server.text.ServerTextChannelChangeDefaultAutoArchiveDurationEventImpl 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);
}
}
Aggregations