Search in sources :

Example 1 with ReactionRemoveAllEvent

use of org.javacord.api.event.message.reaction.ReactionRemoveAllEvent in project Javacord by BtoBastian.

the class MessageReactionRemoveAllHandler method handle.

@Override
public void handle(JsonNode packet) {
    long messageId = packet.get("message_id").asLong();
    Optional<Message> message = api.getCachedMessageById(messageId);
    message.ifPresent(msg -> ((MessageImpl) msg).removeAllReactionsFromCache());
    long channelId = packet.get("channel_id").asLong();
    TextChannel channel = api.getTextChannelById(channelId).orElse(null);
    if (channel == null) {
        if (packet.hasNonNull("guild_id")) {
            // we don't know anything about the channel as it is part of a server and not cached
            LoggerUtil.logMissingChannel(logger, channelId);
            return;
        }
        // channel is a private channel:
        channel = PrivateChannelImpl.dispatchPrivateChannelCreateEvent(api, new PrivateChannelImpl(api, channelId, null, null));
    }
    ReactionRemoveAllEvent event = new ReactionRemoveAllEventImpl(api, messageId, channel);
    Optional<Server> optionalServer = channel.asServerChannel().map(ServerChannel::getServer);
    api.getEventDispatcher().dispatchReactionRemoveAllEvent(optionalServer.map(DispatchQueueSelector.class::cast).orElse(api), messageId, optionalServer.orElse(null), channel, event);
}
Also used : TextChannel(org.javacord.api.entity.channel.TextChannel) Message(org.javacord.api.entity.message.Message) Server(org.javacord.api.entity.server.Server) ReactionRemoveAllEventImpl(org.javacord.core.event.message.reaction.ReactionRemoveAllEventImpl) ReactionRemoveAllEvent(org.javacord.api.event.message.reaction.ReactionRemoveAllEvent) PrivateChannelImpl(org.javacord.core.entity.channel.PrivateChannelImpl) ServerChannel(org.javacord.api.entity.channel.ServerChannel) DispatchQueueSelector(org.javacord.core.util.event.DispatchQueueSelector)

Aggregations

ServerChannel (org.javacord.api.entity.channel.ServerChannel)1 TextChannel (org.javacord.api.entity.channel.TextChannel)1 Message (org.javacord.api.entity.message.Message)1 Server (org.javacord.api.entity.server.Server)1 ReactionRemoveAllEvent (org.javacord.api.event.message.reaction.ReactionRemoveAllEvent)1 PrivateChannelImpl (org.javacord.core.entity.channel.PrivateChannelImpl)1 ReactionRemoveAllEventImpl (org.javacord.core.event.message.reaction.ReactionRemoveAllEventImpl)1 DispatchQueueSelector (org.javacord.core.util.event.DispatchQueueSelector)1