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);
}
Aggregations