From 39c29df5518e65f5cd3422d93eb56a2accc515ac Mon Sep 17 00:00:00 2001 From: Dynxsty Date: Sun, 24 Jul 2022 10:26:17 +0200 Subject: [PATCH 1/2] Added boolean option to enable/disable the Recent Transactions Section in `/help account` --- .../subcommands/HelpAccountSubcommand.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/javadiscord/javabot/systems/help/commands/subcommands/HelpAccountSubcommand.java b/src/main/java/net/javadiscord/javabot/systems/help/commands/subcommands/HelpAccountSubcommand.java index 90212798a..ee22e55bd 100644 --- a/src/main/java/net/javadiscord/javabot/systems/help/commands/subcommands/HelpAccountSubcommand.java +++ b/src/main/java/net/javadiscord/javabot/systems/help/commands/subcommands/HelpAccountSubcommand.java @@ -34,13 +34,15 @@ public class HelpAccountSubcommand extends SlashCommand.Subcommand { */ public HelpAccountSubcommand() { setSubcommandData(new SubcommandData("account", "Shows an overview of your Help Account.") - .addOption(OptionType.USER, "user", "The user to check.", false) + .addOption(OptionType.USER, "user", "If set, show the Help Account of the specified user instead.", false) + .addOption(OptionType.BOOLEAN, "show-transactions", "Should the recent transactions be shown?", false) ); } @Override public void execute(@NotNull SlashCommandInteractionEvent event) { User user = event.getOption("user", event::getUser, OptionMapping::getAsUser); + boolean showTransactions = event.getOption("show-transactions", false, OptionMapping::getAsBoolean); long totalThanks = DbActions.count( "SELECT COUNT(id) FROM help_channel_thanks WHERE helper_id = ?", s -> s.setLong(1, user.getIdLong()) @@ -51,28 +53,28 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { ); try { HelpAccount account = new HelpExperienceService(Bot.dataSource).getOrCreateAccount(user.getIdLong()); - event.replyEmbeds(buildHelpAccountEmbed(account, user, event.getGuild(), totalThanks, weekThanks)).queue(); + event.replyEmbeds(buildHelpAccountEmbed(account, user, event.getGuild(), totalThanks, weekThanks, showTransactions)).queue(); } catch (SQLException e) { ExceptionLogger.capture(e, getClass().getSimpleName()); Responses.error(event, e.getMessage()).queue(); } } - private MessageEmbed buildHelpAccountEmbed(HelpAccount account, User user, Guild guild, long totalThanks, long weekThanks) { - return new EmbedBuilder() + private @NotNull MessageEmbed buildHelpAccountEmbed(HelpAccount account, @NotNull User user, Guild guild, long totalThanks, long weekThanks, boolean showTransactions) { + return new EmbedBuilder() .setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl()) .setTitle("Help Account") .setThumbnail(user.getEffectiveAvatarUrl()) .setDescription("Here are some statistics about how you've helped others here.") - .addField("Experience (BETA)", String.format("%s\n\n**Recent Transactions**\n```diff\n%s```", - formatExperience(guild, account), - formatTransactionHistory(user.getIdLong())), false) + .addField("Experience (BETA)", String.format("%s%s", + formatExperience(guild, account), + showTransactions ? String.format("\n\n**Recent Transactions**\n```diff\n%s```", formatTransactionHistory(user.getIdLong())) : ""), false) .addField("Total Times Thanked", String.format("**%s**", totalThanks), true) .addField("Times Thanked This Week", String.format("**%s**", weekThanks), true) .build(); } - private String formatTransactionHistory(long userId) { + private @NotNull String formatTransactionHistory(long userId) { StringBuilder sb = new StringBuilder(); try { HelpExperienceService service = new HelpExperienceService(Bot.dataSource); From 0db7958e29f9a23e5a5e668baf0300b2f8197642 Mon Sep 17 00:00:00 2001 From: Dynxsty Date: Sun, 24 Jul 2022 10:53:28 +0200 Subject: [PATCH 2/2] fix checkstyle --- src/main/java/net/javadiscord/javabot/util/WebhookUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/javadiscord/javabot/util/WebhookUtil.java b/src/main/java/net/javadiscord/javabot/util/WebhookUtil.java index 7a8b9f106..daa71b18f 100644 --- a/src/main/java/net/javadiscord/javabot/util/WebhookUtil.java +++ b/src/main/java/net/javadiscord/javabot/util/WebhookUtil.java @@ -4,7 +4,6 @@ import club.minnced.discord.webhook.external.JDAWebhookClient; import club.minnced.discord.webhook.send.AllowedMentions; import club.minnced.discord.webhook.send.WebhookMessageBuilder; -import club.minnced.discord.webhook.send.component.Button; import club.minnced.discord.webhook.send.component.LayoutComponent; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message.Attachment; @@ -69,10 +68,11 @@ public static void ensureWebhookExists(@NotNull TextChannel channel, Consumer mirrorMessageToWebhook(@NotNull Webhook webhook, @NotNull Message originalMessage, String newMessageContent, long threadId, LayoutComponent... components) { + public static CompletableFuture mirrorMessageToWebhook(@NotNull Webhook webhook, @NotNull Message originalMessage, String newMessageContent, long threadId, LayoutComponent @NotNull ... components) { JDAWebhookClient client = new WebhookClientBuilder(webhook.getIdLong(), webhook.getToken()) .setThreadId(threadId).buildJDA(); WebhookMessageBuilder message = new WebhookMessageBuilder().setContent(newMessageContent)