Merge pull request #60 from Fashionscape/dev

Dev
This commit is contained in:
Alex Gryczewski 2022-11-13 17:22:48 -05:00 committed by GitHub
commit 176e8f4ecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 32 deletions

View File

@ -25,7 +25,7 @@ dependencies {
implementation 'org.xerial:sqlite-jdbc:3.36.0.2'
implementation 'org.postgresql:postgresql:42.2.24'
implementation 'com.github.Kaaz:ConfigurationBuilder:0.4'
implementation 'org.javacord:javacord:3.3.2'
implementation 'org.javacord:javacord:3.7.0'
implementation 'com.vdurmont:emoji-java:5.1.1'
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'ch.qos.logback:logback-classic:1.2.5'

View File

@ -12,6 +12,7 @@ import dev.salmonllama.fsbot.listeners.*;
import org.javacord.api.DiscordApiBuilder;
import dev.salmonllama.fsbot.utilities.Constants;
import org.javacord.api.entity.intent.Intent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
@ -38,7 +39,7 @@ public class Main {
token = SecretManager.DISCORD_TOKEN.getPlainText();
}
new DiscordApiBuilder().setToken(token).login().thenAccept(api -> {
new DiscordApiBuilder().addIntents(Intent.MESSAGE_CONTENT).setToken(token).login().thenAccept(api -> {
@SuppressWarnings("unused")
Guthix guthix = new Guthix(api);

View File

@ -19,8 +19,8 @@ public class AddColorCommand extends Command {
@Override
public void onCommand(CommandContext ctx) {
ctx.getApi().getOwner().thenAcceptAsync(owner -> {
ctx.reply("This command is no longer active. An alternative is currently being developed. For more information, please contact " + owner.getDiscriminatedName());
});
// ctx.getApi().getOwner().thenAcceptAsync(owner -> {
// ctx.reply("This command is no longer active. An alternative is currently being developed. For more information, please contact " + owner.getDiscriminatedName());
// });
}
}

View File

@ -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));
}
}
}