Skip to content

Commit

Permalink
fix webhook for native-image
Browse files Browse the repository at this point in the history
  • Loading branch information
danthe1st committed Nov 13, 2024
1 parent 07da629 commit cbb7ca8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.nio.channels.Channel;

import club.minnced.discord.webhook.send.WebhookEmbed;
import net.discordjug.javabot.data.config.BotConfig;
import net.discordjug.javabot.data.config.GuildConfig;
import net.discordjug.javabot.data.config.GuildConfigItem;
Expand Down Expand Up @@ -48,7 +49,9 @@
//ensure JDA can create necessary caches
User[].class, Guild[].class, Member[].class, Role[].class, Channel[].class, AudioManager[].class, ScheduledEvent[].class, ThreadMember[].class, ForumTag[].class, RichCustomEmoji[].class, GuildSticker[].class, MemberPresenceImpl[].class,
//needs to be serialized for channel managers etc
PermOverrideData.class
PermOverrideData.class,
//ensure that webhook embed authors can be serialized
WebhookEmbed.EmbedAuthor.class
})
public class RuntimeHintsConfiguration implements RuntimeHintsRegistrar {

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/net/discordjug/javabot/util/WebhookUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ public static void ensureWebhookExists(@NotNull IWebhookContainer channel, @NotN
* the message
*/
public static CompletableFuture<ReadonlyMessage> mirrorMessageToWebhook(@NotNull Webhook webhook, @NotNull Message originalMessage, String newMessageContent, long threadId, @Nullable List<LayoutComponent> components, @Nullable List<MessageEmbed> embeds) {
return originalMessage.getGuild().retrieveMember(originalMessage.getAuthor()).submit().thenCompose(member -> mirrorMessageToWebhook(webhook, originalMessage, newMessageContent, threadId, components, embeds, member));
return originalMessage
.getGuild()
.retrieveMember(originalMessage.getAuthor())
.submit()
.exceptionally(e -> null)//if the member cannot be found, use no member information
.thenCompose(member ->
mirrorMessageToWebhook(webhook, originalMessage, newMessageContent, threadId, components, embeds, member));
}

private static CompletableFuture<ReadonlyMessage> mirrorMessageToWebhook(@NotNull Webhook webhook, Message originalMessage, String newMessageContent, long threadId,
Expand Down

0 comments on commit cbb7ca8

Please sign in to comment.