Skip to content

Commit bae3b09

Browse files
committed
allow deleting message link content messages
1 parent 0a4adfe commit bae3b09

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/main/java/net/javadiscord/javabot/listener/MessageLinkListener.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import net.dv8tion.jda.api.hooks.ListenerAdapter;
1616
import net.dv8tion.jda.api.requests.RestAction;
1717
import net.javadiscord.javabot.util.ExceptionLogger;
18+
import net.javadiscord.javabot.util.InteractionUtils;
1819
import net.javadiscord.javabot.util.WebhookUtil;
1920
import org.jetbrains.annotations.NotNull;
2021

@@ -42,7 +43,12 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
4243
Optional<RestAction<Message>> optional = parseMessageUrl(matcher.group(), event.getJDA());
4344
optional.ifPresent(action -> action.queue(m -> {
4445
WebhookUtil.ensureWebhookExists(webhookChannel,
45-
wh -> WebhookUtil.mirrorMessageToWebhook(wh, m, m.getContentRaw(), messageChannel.getType().isThread() ? messageChannel.getIdLong() : 0, List.of(ActionRow.of(Button.link(m.getJumpUrl(), "Jump to Message"))), null));
46+
wh -> WebhookUtil.mirrorMessageToWebhook(wh, m, m.getContentRaw(),
47+
messageChannel.getType().isThread() ? messageChannel.getIdLong() : 0,
48+
List.of(ActionRow.of(
49+
Button.link(m.getJumpUrl(), "Jump to Message"),
50+
Button.secondary(InteractionUtils.createDeleteInteractionId(m.getAuthor().getIdLong()), "\uD83D\uDDD1️"))),
51+
null));
4652
}, e -> ExceptionLogger.capture(e, getClass().getSimpleName())));
4753
}
4854
}

src/main/java/net/javadiscord/javabot/util/InteractionUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ private InteractionCallbackAction<?> delete(@NotNull ButtonInteraction interacti
113113
}
114114

115115
public static Button createDeleteButton(long senderId) {
116-
return Button.secondary(DELETE_ORIGINAL_TEMPLATE.formatted(senderId), "\uD83D\uDDD1️");
116+
return Button.secondary(createDeleteInteractionId(senderId), "\uD83D\uDDD1️");
117+
}
118+
119+
public static String createDeleteInteractionId(long senderId) {
120+
return DELETE_ORIGINAL_TEMPLATE.formatted(senderId);
117121
}
118122

119123
private void kick(ModalInteraction interaction, @NotNull Guild guild, String memberId, String reason) {

src/main/java/net/javadiscord/javabot/util/WebhookUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public static void ensureWebhookExists(@NotNull IWebhookContainer channel, @NotN
6565
channel.retrieveWebhooks().queue(webhooks -> {
6666
Optional<Webhook> hook = webhooks.stream()
6767
.filter(webhook -> webhook.getChannel().getIdLong() == channel.getIdLong())
68+
.filter(wh -> wh.getOwner() != null)
69+
.filter(wh -> wh.getOwner().getIdLong() == channel.getJDA().getSelfUser().getIdLong())
6870
.filter(wh -> wh.getToken() != null)
6971
.findAny();
7072
if (hook.isPresent()) {

0 commit comments

Comments
 (0)