use of org.javacord.api.event.message.reaction.ReactionRemoveEvent in project Javacord by BtoBastian.
the class MessageReactionRemoveHandler method handle.
@Override
public void handle(JsonNode packet) {
long messageId = packet.get("message_id").asLong();
long userId = packet.get("user_id").asLong();
Optional<Message> message = api.getCachedMessageById(messageId);
long channelId = packet.get("channel_id").asLong();
TextChannel channel;
if (packet.hasNonNull("guild_id")) {
channel = api.getTextChannelById(channelId).orElse(null);
} else {
// if private channel:
channel = PrivateChannelImpl.getOrCreatePrivateChannel(api, channelId, userId, null);
}
if (channel == null) {
LoggerUtil.logMissingChannel(logger, channelId);
return;
}
Emoji emoji;
JsonNode emojiJson = packet.get("emoji");
if (!emojiJson.has("id") || emojiJson.get("id").isNull()) {
emoji = UnicodeEmojiImpl.fromString(emojiJson.get("name").asText());
} else {
emoji = api.getKnownCustomEmojiOrCreateCustomEmoji(emojiJson);
}
message.ifPresent(msg -> ((MessageImpl) msg).removeReaction(emoji, userId == api.getYourself().getId()));
ReactionRemoveEvent event = new ReactionRemoveEventImpl(api, messageId, channel, emoji, userId);
Optional<Server> optionalServer = channel.asServerChannel().map(ServerChannel::getServer);
api.getEventDispatcher().dispatchReactionRemoveEvent(optionalServer.map(DispatchQueueSelector.class::cast).orElse(api), messageId, optionalServer.orElse(null), channel, userId, event);
}
Aggregations