use of org.javacord.api.event.message.ChannelPinsUpdateEvent in project Javacord by BtoBastian.
the class ChannelPinsUpdateHandler method handle.
@Override
public void handle(JsonNode packet) {
long channelId = packet.get("channel_id").asLong();
Optional<TextChannel> optionalChannel = api.getTextChannelById(channelId);
if (optionalChannel.isPresent()) {
TextChannel channel = optionalChannel.get();
Instant lastPinTimestamp = packet.hasNonNull("last_pin_timestamp") ? OffsetDateTime.parse(packet.get("last_pin_timestamp").asText()).toInstant() : null;
ChannelPinsUpdateEvent event = new ChannelPinsUpdateEventImpl(channel, lastPinTimestamp);
Optional<Server> optionalServer = channel.asServerChannel().map(ServerChannel::getServer);
api.getEventDispatcher().dispatchChannelPinsUpdateEvent(optionalServer.map(DispatchQueueSelector.class::cast).orElse(api), optionalServer.orElse(null), channel, event);
} else {
LoggerUtil.logMissingChannel(logger, channelId);
}
}
Aggregations