Rework the module to include images in reports.
This commit is contained in:
parent
b0aa137a69
commit
81ee89978c
@ -7,8 +7,8 @@ package dev.salmonllama.fsbot.listeners;
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.entity.channel.TextChannel;
|
||||
import org.javacord.api.entity.message.Message;
|
||||
import org.javacord.api.entity.message.MessageAttachment;
|
||||
import org.javacord.api.entity.message.MessageAuthor;
|
||||
import org.javacord.api.entity.message.MessageBuilder;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
import org.javacord.api.event.message.MessageCreateEvent;
|
||||
import org.javacord.api.listener.message.MessageCreateListener;
|
||||
@ -23,44 +23,62 @@ public class ReportListener implements MessageCreateListener {
|
||||
|
||||
public void onMessageCreate(MessageCreateEvent event) {
|
||||
DiscordApi api = event.getApi();
|
||||
TextChannel channel = event.getChannel();
|
||||
TextChannel reportChannel = event.getChannel();
|
||||
|
||||
if (!channel.getIdAsString().equals(BotConfig.REPORT_CHANNEL)) {
|
||||
if (!reportChannel.getIdAsString().equals(BotConfig.REPORT_CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Message message = event.getMessage();
|
||||
String content = message.getContent();
|
||||
MessageAuthor author = message.getAuthor();
|
||||
|
||||
if (author.isBotUser()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String content = message.getContent();
|
||||
message.getAttachments().forEach(
|
||||
attachment -> attachment.downloadAsImage().thenAcceptAsync(
|
||||
image -> new MessageBuilder()
|
||||
.addAttachment(image, "evidence")
|
||||
.setContent("Report Evidence:")
|
||||
.send(channel)));
|
||||
// The report log, also known as the #moderators channel.
|
||||
Optional<TextChannel> modChannel = api.getTextChannelById(BotConfig.REPORT_LOG);
|
||||
|
||||
if (message.getAttachments().stream().anyMatch(MessageAttachment::isImage)) {
|
||||
// Send the images with the content
|
||||
message.getAttachments().stream().filter(MessageAttachment::isImage).forEach(
|
||||
messageAttachment -> {
|
||||
// The messageAttachment is an image, proceed accordingly.
|
||||
// Upload the image to an embed and send it to the mods channel
|
||||
// Include any content that was sent with it
|
||||
messageAttachment.asImage().thenAcceptAsync(bufferedImage -> {
|
||||
EmbedBuilder embed = new EmbedBuilder()
|
||||
.setTitle("User Report with Image")
|
||||
.setColor(Color.GREEN)
|
||||
.setImage(bufferedImage)
|
||||
.setFooter("Sent by: " + author.getDiscriminatedName());
|
||||
|
||||
if (!message.getContent().equals("")) {
|
||||
embed.setDescription(message.getContent());
|
||||
}
|
||||
|
||||
modChannel.ifPresentOrElse(
|
||||
chnl -> chnl.sendMessage(embed),
|
||||
() -> reportChannel.sendMessage("An error has occurred. Could not find the proper log channel. Please contact a staff member")
|
||||
.thenAccept(MessageUtilities.deleteAfter(30, TimeUnit.SECONDS)));
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Just send the content
|
||||
EmbedBuilder embed = new EmbedBuilder()
|
||||
.setTitle("User Report")
|
||||
.setDescription(content)
|
||||
.setColor(Color.GREEN)
|
||||
.setFooter("From: " + author.getDiscriminatedName());
|
||||
|
||||
modChannel.ifPresentOrElse(
|
||||
chnl -> chnl.sendMessage(embed),
|
||||
() -> reportChannel.sendMessage("An error has occurred. Could not find the proper log channel. Please contact a staff member")
|
||||
.thenAccept(MessageUtilities.deleteAfter(30, TimeUnit.SECONDS)));
|
||||
}
|
||||
|
||||
// Delete the message from the channel.
|
||||
message.delete().join();
|
||||
|
||||
EmbedBuilder embed = new EmbedBuilder()
|
||||
.setTitle("User Report")
|
||||
.setDescription(content)
|
||||
.setColor(Color.GREEN)
|
||||
.setFooter("From: " + author.getDiscriminatedName());
|
||||
|
||||
Optional<TextChannel> logChannel = api.getTextChannelById(BotConfig.REPORT_LOG);
|
||||
if (logChannel.isPresent()) {
|
||||
logChannel.get().sendMessage(embed);
|
||||
}
|
||||
else {
|
||||
channel.sendMessage("Could not find proper log channel, please contact a staff member.")
|
||||
.thenAccept(MessageUtilities.deleteAfter(30, TimeUnit.SECONDS));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user