Search in sources :

Example 1 with MessageReactionRemoveEmoteEvent

use of net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEmoteEvent in project JDA by DV8FromTheWorld.

the class MessageReactionClearEmoteHandler method handleInternally.

@Override
protected Long handleInternally(DataObject content) {
    long guildId = content.getUnsignedLong("guild_id");
    if (getJDA().getGuildSetupController().isLocked(guildId))
        return guildId;
    Guild guild = getJDA().getGuildById(guildId);
    if (guild == null) {
        EventCache.LOG.debug("Caching MESSAGE_REACTION_REMOVE_EMOJI event for unknown guild {}", guildId);
        getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle);
        return null;
    }
    long channelId = content.getUnsignedLong("channel_id");
    // TODO-v5-unified-channel-cache
    GuildMessageChannel channel = guild.getTextChannelById(channelId);
    if (channel == null)
        channel = guild.getNewsChannelById(channelId);
    if (channel == null)
        channel = guild.getThreadChannelById(channelId);
    if (channel == null) {
        EventCache.LOG.debug("Caching MESSAGE_REACTION_REMOVE_EMOJI event for unknown channel {}", channelId);
        getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
        return null;
    }
    long messageId = content.getUnsignedLong("message_id");
    DataObject emoji = content.getObject("emoji");
    MessageReaction.ReactionEmote reactionEmote = null;
    if (emoji.isNull("id")) {
        reactionEmote = MessageReaction.ReactionEmote.fromUnicode(emoji.getString("name"), getJDA());
    } else {
        long emoteId = emoji.getUnsignedLong("id");
        Emote emote = getJDA().getEmoteById(emoteId);
        if (emote == null) {
            emote = new EmoteImpl(emoteId, getJDA()).setAnimated(emoji.getBoolean("animated")).setName(emoji.getString("name", ""));
        }
        reactionEmote = MessageReaction.ReactionEmote.fromCustom(emote);
    }
    MessageReaction reaction = new MessageReaction(channel, reactionEmote, messageId, false, 0);
    getJDA().handleEvent(new MessageReactionRemoveEmoteEvent(getJDA(), responseNumber, messageId, channel, reaction));
    return null;
}
Also used : MessageReaction(net.dv8tion.jda.api.entities.MessageReaction) EmoteImpl(net.dv8tion.jda.internal.entities.EmoteImpl) MessageReactionRemoveEmoteEvent(net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEmoteEvent) DataObject(net.dv8tion.jda.api.utils.data.DataObject) Emote(net.dv8tion.jda.api.entities.Emote) Guild(net.dv8tion.jda.api.entities.Guild) GuildMessageChannel(net.dv8tion.jda.api.entities.GuildMessageChannel)

Aggregations

Emote (net.dv8tion.jda.api.entities.Emote)1 Guild (net.dv8tion.jda.api.entities.Guild)1 GuildMessageChannel (net.dv8tion.jda.api.entities.GuildMessageChannel)1 MessageReaction (net.dv8tion.jda.api.entities.MessageReaction)1 MessageReactionRemoveEmoteEvent (net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEmoteEvent)1 DataObject (net.dv8tion.jda.api.utils.data.DataObject)1 EmoteImpl (net.dv8tion.jda.internal.entities.EmoteImpl)1