Skip to content

Commit d05e1ea

Browse files
Merge pull request #375 from danthe1st/copy-report-message
2 parents f836ea4 + 52ce710 commit d05e1ea

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/main/java/net/javadiscord/javabot/systems/moderation/report/ReportManager.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@
2929
import net.javadiscord.javabot.data.config.guild.ModerationConfig;
3030
import net.javadiscord.javabot.util.InteractionUtils;
3131
import net.javadiscord.javabot.util.Responses;
32+
import net.javadiscord.javabot.util.WebhookUtil;
33+
3234
import org.jetbrains.annotations.NotNull;
3335

3436
import java.time.Instant;
3537
import java.util.List;
38+
import java.util.function.Consumer;
3639

3740
/**
3841
* Manages all interactions regarding the report-system.
@@ -154,7 +157,11 @@ private void handleMessageReport(ModalInteractionEvent event, String messageId)
154157
embed.setTitle(String.format("%s reported a Message from %s", event.getUser().getName(), target.getAuthor().getName()));
155158
embed.addField("Message", String.format("[Jump to Message](%s)", target.getJumpUrl()), false);
156159
MessageChannel reportChannel = config.getModerationConfig().getReportChannel();
157-
reportChannel.sendMessageEmbeds(embed.build()).queue(m -> createReportThread(m, target.getAuthor().getIdLong(), config.getModerationConfig()));
160+
reportChannel.sendMessageEmbeds(embed.build()).queue(m -> createReportThread(m, target.getAuthor().getIdLong(), config.getModerationConfig(), thread->{
161+
WebhookUtil.ensureWebhookExists(thread.getParentChannel().asStandardGuildMessageChannel(), wh->{
162+
WebhookUtil.mirrorMessageToWebhook(wh, target, target.getContentRaw(), thread.getIdLong());
163+
});
164+
}));
158165
embed.setDescription("Successfully reported " + "`" + target.getAuthor().getAsTag() + "`!\nYour report has been send to our Moderators");
159166
event.getHook().sendMessageEmbeds(embed.build()).queue();
160167
}, failure -> {
@@ -173,13 +180,24 @@ private ActionRow setComponents(long targetId, long threadId) {
173180
}
174181

175182
private void createReportThread(Message message, long targetId, ModerationConfig config) {
183+
createReportThread(message, targetId, config, thread->{});
184+
}
185+
186+
private void createReportThread(Message message, long targetId, ModerationConfig config, Consumer<ThreadChannel> onSuccess) {
176187
message.createThreadChannel(message.getEmbeds().get(0).getTitle()).queue(
177-
thread -> thread.sendMessage(config.getStaffRole().getAsMention())
188+
thread -> {
189+
thread.sendMessage(config.getStaffRole().getAsMention())
178190
.setComponents(setComponents(targetId, thread.getIdLong()))
179-
.queue()
191+
.queue();
192+
onSuccess.accept(thread);
193+
}
180194
);
181195
}
182196

197+
198+
199+
200+
183201
private EmbedBuilder buildReportEmbed(User reported, User reportedBy, String reason, Channel channel) {
184202
return new EmbedBuilder()
185203
.setAuthor(reported.getAsTag(), null, reported.getEffectiveAvatarUrl())

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import net.dv8tion.jda.api.entities.Message;
1010
import net.dv8tion.jda.api.entities.Message.Attachment;
1111
import net.dv8tion.jda.api.entities.Webhook;
12-
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel;
12+
import net.dv8tion.jda.api.entities.channel.attribute.IWebhookContainer;
1313
import org.jetbrains.annotations.NotNull;
1414

1515
import java.util.List;
@@ -32,9 +32,8 @@ private WebhookUtil() {
3232
* @param callback an action that is executed once a webhook is
3333
* found/created
3434
*/
35-
public static void ensureWebhookExists(StandardGuildMessageChannel channel, Consumer<? super Webhook> callback) {
36-
ensureWebhookExists(channel, callback, err -> {
37-
});
35+
public static void ensureWebhookExists(@NotNull IWebhookContainer channel, @NotNull Consumer<? super Webhook> callback) {
36+
ensureWebhookExists(channel, callback, ExceptionLogger::capture);
3837
}
3938

4039
/**
@@ -47,7 +46,7 @@ public static void ensureWebhookExists(StandardGuildMessageChannel channel, Cons
4746
* @param failureCallback an action that is executed if the webhook
4847
* lookup/creation failed
4948
*/
50-
public static void ensureWebhookExists(@NotNull StandardGuildMessageChannel channel, Consumer<? super Webhook> callback, Consumer<? super Throwable> failureCallback) {
49+
public static void ensureWebhookExists(@NotNull IWebhookContainer channel, @NotNull Consumer<? super Webhook> callback, @NotNull Consumer<? super Throwable> failureCallback) {
5150

5251
channel.retrieveWebhooks().queue(webhooks -> {
5352
Optional<Webhook> hook = webhooks.stream()

0 commit comments

Comments
 (0)