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.DiscordApi;
|
||||||
import org.javacord.api.entity.channel.TextChannel;
|
import org.javacord.api.entity.channel.TextChannel;
|
||||||
import org.javacord.api.entity.message.Message;
|
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.MessageAuthor;
|
||||||
import org.javacord.api.entity.message.MessageBuilder;
|
|
||||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||||
import org.javacord.api.event.message.MessageCreateEvent;
|
import org.javacord.api.event.message.MessageCreateEvent;
|
||||||
import org.javacord.api.listener.message.MessageCreateListener;
|
import org.javacord.api.listener.message.MessageCreateListener;
|
||||||
@ -23,44 +23,62 @@ public class ReportListener implements MessageCreateListener {
|
|||||||
|
|
||||||
public void onMessageCreate(MessageCreateEvent event) {
|
public void onMessageCreate(MessageCreateEvent event) {
|
||||||
DiscordApi api = event.getApi();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Message message = event.getMessage();
|
Message message = event.getMessage();
|
||||||
|
String content = message.getContent();
|
||||||
MessageAuthor author = message.getAuthor();
|
MessageAuthor author = message.getAuthor();
|
||||||
|
|
||||||
if (author.isBotUser()) {
|
if (author.isBotUser()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String content = message.getContent();
|
// The report log, also known as the #moderators channel.
|
||||||
message.getAttachments().forEach(
|
Optional<TextChannel> modChannel = api.getTextChannelById(BotConfig.REPORT_LOG);
|
||||||
attachment -> attachment.downloadAsImage().thenAcceptAsync(
|
|
||||||
image -> new MessageBuilder()
|
|
||||||
.addAttachment(image, "evidence")
|
|
||||||
.setContent("Report Evidence:")
|
|
||||||
.send(channel)));
|
|
||||||
|
|
||||||
message.delete().join();
|
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()
|
EmbedBuilder embed = new EmbedBuilder()
|
||||||
.setTitle("User Report")
|
.setTitle("User Report")
|
||||||
.setDescription(content)
|
.setDescription(content)
|
||||||
.setColor(Color.GREEN)
|
.setColor(Color.GREEN)
|
||||||
.setFooter("From: " + author.getDiscriminatedName());
|
.setFooter("From: " + author.getDiscriminatedName());
|
||||||
|
|
||||||
Optional<TextChannel> logChannel = api.getTextChannelById(BotConfig.REPORT_LOG);
|
modChannel.ifPresentOrElse(
|
||||||
if (logChannel.isPresent()) {
|
chnl -> chnl.sendMessage(embed),
|
||||||
logChannel.get().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 {
|
|
||||||
channel.sendMessage("Could not find proper log channel, please contact a staff member.")
|
|
||||||
.thenAccept(MessageUtilities.deleteAfter(30, TimeUnit.SECONDS));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete the message from the channel.
|
||||||
|
message.delete().join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user