From 48251cc634bcc06e8e9b4f8aeaa17082d8329b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Spie=C3=9F?= Date: Wed, 21 Aug 2024 16:31:59 +0200 Subject: [PATCH] Remove MessageEmbedEvent (#2720) --- .../api/events/message/MessageEmbedEvent.java | 60 ------------------- .../jda/api/hooks/ListenerAdapter.java | 1 - .../internal/handle/MessageUpdateHandler.java | 51 ---------------- 3 files changed, 112 deletions(-) delete mode 100644 src/main/java/net/dv8tion/jda/api/events/message/MessageEmbedEvent.java diff --git a/src/main/java/net/dv8tion/jda/api/events/message/MessageEmbedEvent.java b/src/main/java/net/dv8tion/jda/api/events/message/MessageEmbedEvent.java deleted file mode 100644 index 367e3a8066..0000000000 --- a/src/main/java/net/dv8tion/jda/api/events/message/MessageEmbedEvent.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.dv8tion.jda.api.events.message; - -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.MessageEmbed; -import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; - -import javax.annotation.Nonnull; -import java.util.Collections; -import java.util.List; - -/** - * Indicates that a Message contains an {@link net.dv8tion.jda.api.entities.MessageEmbed Embed} in a {@link net.dv8tion.jda.api.entities.channel.middleman.MessageChannel MessageChannel}. - *
Discord may need to do additional calculations and resizing tasks on messages that embed websites, thus they send the message only with content and link and use this update to add the missing embed later when the server finishes those calculations. - * - *

Can be used to retrieve MessageEmbeds from any message. No matter if private or guild. - * - *

Requirements
- * - *

This event requires at least one of the following intents (Will not fire at all if neither is enabled): - *

- */ -public class MessageEmbedEvent extends GenericMessageEvent -{ - private final List embeds; - - public MessageEmbedEvent(@Nonnull JDA api, long responseNumber, long messageId, @Nonnull MessageChannel channel, @Nonnull List embeds) - { - super(api, responseNumber, messageId, channel); - this.embeds = Collections.unmodifiableList(embeds); - } - - /** - * The list of {@link net.dv8tion.jda.api.entities.MessageEmbed MessageEmbeds} - * - * @return The list of MessageEmbeds - */ - @Nonnull - public List getMessageEmbeds() - { - return embeds; - } -} diff --git a/src/main/java/net/dv8tion/jda/api/hooks/ListenerAdapter.java b/src/main/java/net/dv8tion/jda/api/hooks/ListenerAdapter.java index 0c18a59fbb..0183f0cf92 100644 --- a/src/main/java/net/dv8tion/jda/api/hooks/ListenerAdapter.java +++ b/src/main/java/net/dv8tion/jda/api/hooks/ListenerAdapter.java @@ -181,7 +181,6 @@ public void onMessageReceived(@Nonnull MessageReceivedEvent event) {} public void onMessageUpdate(@Nonnull MessageUpdateEvent event) {} public void onMessageDelete(@Nonnull MessageDeleteEvent event) {} public void onMessageBulkDelete(@Nonnull MessageBulkDeleteEvent event) {} - public void onMessageEmbed(@Nonnull MessageEmbedEvent event) {} public void onMessageReactionAdd(@Nonnull MessageReactionAddEvent event) {} public void onMessageReactionRemove(@Nonnull MessageReactionRemoveEvent event) {} public void onMessageReactionRemoveAll(@Nonnull MessageReactionRemoveAllEvent event) {} diff --git a/src/main/java/net/dv8tion/jda/internal/handle/MessageUpdateHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/MessageUpdateHandler.java index cc528b27f6..4b12eafe41 100644 --- a/src/main/java/net/dv8tion/jda/internal/handle/MessageUpdateHandler.java +++ b/src/main/java/net/dv8tion/jda/internal/handle/MessageUpdateHandler.java @@ -17,21 +17,15 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.MessageType; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; -import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; -import net.dv8tion.jda.api.events.message.MessageEmbedEvent; import net.dv8tion.jda.api.events.message.MessageUpdateEvent; -import net.dv8tion.jda.api.utils.data.DataArray; import net.dv8tion.jda.api.utils.data.DataObject; import net.dv8tion.jda.internal.JDAImpl; import net.dv8tion.jda.internal.entities.EntityBuilder; import net.dv8tion.jda.internal.requests.WebSocketClient; -import java.util.LinkedList; - public class MessageUpdateHandler extends SocketHandler { @@ -72,15 +66,7 @@ protected Long handleInternally(DataObject content) WebSocketClient.LOG.debug("JDA received a message update for an unexpected message type. Type: {} JSON: {}", type, content); return null; } - else if (!content.isNull("embeds")) - { - //Received update with no "type" field which means its an update for a rich embed message - handleMessageEmbed(content); - return null; - } } - else if (!content.isNull("embeds")) - return handleMessageEmbed(content); return null; } @@ -137,41 +123,4 @@ private Long handleMessage(DataObject content, Guild guild) message)); return null; } - - private Long handleMessageEmbed(DataObject content) - { - EntityBuilder builder = getJDA().getEntityBuilder(); - final long messageId = content.getLong("id"); - final long channelId = content.getLong("channel_id"); - LinkedList embeds = new LinkedList<>(); - - MessageChannel channel = getJDA().getChannelById(MessageChannel.class, channelId); - if (channel == null) - { - Guild guild = getJDA().getGuildById(content.getUnsignedLong("guild_id", 0L)); - if (guild != null) - { - GuildChannel guildChannel = guild.getGuildChannelById(channelId); - if (guildChannel != null) - { - WebSocketClient.LOG.debug("Discarding MESSAGE_UPDATE event for unexpected channel type. Channel: {}", guildChannel); - return 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; - } }