Search in sources :

Example 1 with MessageEmbedEvent

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

the class MessageUpdateHandler method handleMessageEmbed.

private Long handleMessageEmbed(DataObject content) {
    EntityBuilder builder = getJDA().getEntityBuilder();
    final long messageId = content.getLong("id");
    final long channelId = content.getLong("channel_id");
    LinkedList<MessageEmbed> embeds = new LinkedList<>();
    // TODO-v5-unified-channel-cache
    // TODO-v5: handle for threads.
    MessageChannel channel = getJDA().getTextChannelsView().get(channelId);
    if (channel == null)
        channel = getJDA().getNewsChannelById(channelId);
    if (channel == null)
        channel = getJDA().getPrivateChannelsView().get(channelId);
    if (channel == null) {
        getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
        EventCache.LOG.debug("Received message update for embeds for a channel/group that JDA does not have cached yet.");
        return null;
    }
    DataArray embedsJson = content.getArray("embeds");
    for (int i = 0; i < embedsJson.length(); i++) embeds.add(builder.createMessageEmbed(embedsJson.getObject(i)));
    getJDA().handleEvent(new MessageEmbedEvent(getJDA(), responseNumber, messageId, channel, embeds));
    return null;
}
Also used : MessageEmbedEvent(net.dv8tion.jda.api.events.message.MessageEmbedEvent) EntityBuilder(net.dv8tion.jda.internal.entities.EntityBuilder) LinkedList(java.util.LinkedList) DataArray(net.dv8tion.jda.api.utils.data.DataArray)

Aggregations

LinkedList (java.util.LinkedList)1 MessageEmbedEvent (net.dv8tion.jda.api.events.message.MessageEmbedEvent)1 DataArray (net.dv8tion.jda.api.utils.data.DataArray)1 EntityBuilder (net.dv8tion.jda.internal.entities.EntityBuilder)1