diff --git a/src/main/java/cc/fascinated/bat/common/EmbedDescriptionBuilder.java b/src/main/java/cc/fascinated/bat/common/EmbedDescriptionBuilder.java new file mode 100644 index 0000000..b0f2e6b --- /dev/null +++ b/src/main/java/cc/fascinated/bat/common/EmbedDescriptionBuilder.java @@ -0,0 +1,40 @@ +package cc.fascinated.bat.common; + +import lombok.NonNull; + +/** + * @author Fascinated (fascinated7) + */ +public class EmbedDescriptionBuilder { + /** + * Where the description is stored + */ + private final StringBuilder builder = new StringBuilder(); + + public EmbedDescriptionBuilder(String title) { + builder.append("**").append(title).append("**").append("\n"); + } + + @NonNull + public EmbedDescriptionBuilder appendLine(@NonNull String line, boolean arrow) { + builder.append(arrow ? "➜ " : "").append(line).append("\n"); + return this; + } + + @NonNull + public EmbedDescriptionBuilder appendSubtitle(@NonNull String title) { + builder.append("**").append(title).append("**").append("\n"); + return this; + } + + @NonNull + public EmbedDescriptionBuilder emptyLine() { + builder.append("\n"); + return this; + } + + @NonNull + public String build() { + return builder.toString(); + } +} diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/general/BotStatsCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/general/BotStatsCommand.java index 5a4a804..9e8a515 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/general/BotStatsCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/general/BotStatsCommand.java @@ -2,6 +2,7 @@ package cc.fascinated.bat.features.base.commands.general; import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; +import cc.fascinated.bat.common.EmbedDescriptionBuilder; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.common.NumberFormatter; import cc.fascinated.bat.common.TimeUtils; @@ -42,15 +43,16 @@ public class BotStatsCommand extends BatCommand { JDA jda = DiscordService.JDA; event.replyEmbeds(EmbedUtils.genericEmbed().setDescription( - "**Bot Statistics**\n" + - "➜ Guilds: **%s**\n".formatted(NumberFormatter.format(jda.getGuilds().size())) + - "➜ Users: **%s**\n".formatted(NumberFormatter.format(jda.getUsers().size())) + - "➜ Gateway Ping: **%sms**\n".formatted(jda.getGatewayPing()) + - "\n" + - "**Bat Statistics**\n" + - "➜ Uptime: **%s**\n".formatted(TimeUtils.format(bean.getUptime())) + - "➜ Cached Guilds: **%s**\n".formatted(NumberFormatter.format(guildService.getGuilds().size())) + - "➜ Cached Users: **%s**".formatted(NumberFormatter.format(userService.getUsers().size())) + new EmbedDescriptionBuilder("Bat Statistics") + .appendLine("Guilds: **%s**".formatted(NumberFormatter.format(jda.getGuilds().size())), true) + .appendLine("Users: **%s**".formatted(NumberFormatter.format(jda.getUsers().size())), true) + .appendLine("Gateway Ping: **%sms**".formatted(jda.getGatewayPing()), true) + .emptyLine() + .appendSubtitle("Bot Statistics") + .appendLine("Uptime: **%s**".formatted(TimeUtils.format(bean.getUptime())), true) + .appendLine("Cached Guilds: **%s**".formatted(NumberFormatter.format(guildService.getGuilds().size())), true) + .appendLine("Cached Users: **%s**".formatted(NumberFormatter.format(userService.getUsers().size())), true) + .build() ).build()).queue(); } } diff --git a/src/main/java/cc/fascinated/bat/features/messagesnipe/command/DeletedSubCommand.java b/src/main/java/cc/fascinated/bat/features/messagesnipe/command/DeletedSubCommand.java index a419d53..2b4456d 100644 --- a/src/main/java/cc/fascinated/bat/features/messagesnipe/command/DeletedSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/messagesnipe/command/DeletedSubCommand.java @@ -2,6 +2,7 @@ package cc.fascinated.bat.features.messagesnipe.command; import cc.fascinated.bat.command.BatSubCommand; import cc.fascinated.bat.command.CommandInfo; +import cc.fascinated.bat.common.EmbedDescriptionBuilder; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.common.PasteUtils; import cc.fascinated.bat.features.messagesnipe.MessageSnipeFeature; @@ -32,23 +33,13 @@ public class DeletedSubCommand extends BatSubCommand { } User author = message.getMessage().getAuthor(); - String content = message.getMessage().getContentDisplay(); + String content = message.getMessage().getContentStripped(); + String formattedContent = content.length() > 512 ? PasteUtils.uploadPaste(content).getUrl() : "```\n%s\n```".formatted(content); event.replyEmbeds(EmbedUtils.genericEmbed() - .setDescription(""" - **Deleted Message Snipe** - ➜ Author: **%s** (%s) - ➜ Deleted: - ➜ Content: %s - """.formatted( - author.getAsMention(), - author.getId(), - message.getDeletedDate().getTime() / 1000, - content.length() > 512 ? PasteUtils.uploadPaste(content).getUrl() : - """ - ``` - %s - ``` - """.formatted(content) - )).build()).queue(); + .setDescription(new EmbedDescriptionBuilder("Deleted Message Snipe") + .appendLine("Author: **%s** (%s)".formatted(author.getAsMention(), author.getId()), true) + .appendLine("Deleted: ".formatted(message.getDeletedDate().getTime() / 1000), true) + .appendLine("Content: %s".formatted(formattedContent), true) + .build()).build()).queue(); } } diff --git a/src/main/java/cc/fascinated/bat/service/DiscordMessageService.java b/src/main/java/cc/fascinated/bat/service/DiscordMessageService.java index fc4643d..aa58f8b 100644 --- a/src/main/java/cc/fascinated/bat/service/DiscordMessageService.java +++ b/src/main/java/cc/fascinated/bat/service/DiscordMessageService.java @@ -58,7 +58,7 @@ public class DiscordMessageService extends ListenerAdapter { event.getChannel().getId(), event.getGuild().getId(), event.getAuthor().getId(), - event.getMessage().getContentRaw(), + event.getMessage().getContentStripped(), false )); } @@ -68,10 +68,10 @@ public class DiscordMessageService extends ListenerAdapter { Optional message = discordMessageRepository.findById(event.getMessageId()); if (message.isPresent()) { DiscordMessage discordMessage = message.get(); - if (discordMessage.getContent().equals(event.getMessage().getContentRaw())) { + if (discordMessage.getContent().equals(event.getMessage().getContentStripped())) { return; } - discordMessage.setContent(event.getMessage().getContentRaw()); + discordMessage.setContent(event.getMessage().getContentStripped()); discordMessageRepository.save(discordMessage); }