Search in sources :

Example 1 with ChannelPinsUpdateEventImpl

use of org.javacord.core.event.message.ChannelPinsUpdateEventImpl 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);
    }
}
Also used : TextChannel(org.javacord.api.entity.channel.TextChannel) Server(org.javacord.api.entity.server.Server) Instant(java.time.Instant) ChannelPinsUpdateEvent(org.javacord.api.event.message.ChannelPinsUpdateEvent) ChannelPinsUpdateEventImpl(org.javacord.core.event.message.ChannelPinsUpdateEventImpl) ServerChannel(org.javacord.api.entity.channel.ServerChannel) DispatchQueueSelector(org.javacord.core.util.event.DispatchQueueSelector)

Aggregations

Instant (java.time.Instant)1 ServerChannel (org.javacord.api.entity.channel.ServerChannel)1 TextChannel (org.javacord.api.entity.channel.TextChannel)1 Server (org.javacord.api.entity.server.Server)1 ChannelPinsUpdateEvent (org.javacord.api.event.message.ChannelPinsUpdateEvent)1 ChannelPinsUpdateEventImpl (org.javacord.core.event.message.ChannelPinsUpdateEventImpl)1 DispatchQueueSelector (org.javacord.core.util.event.DispatchQueueSelector)1