Skip to content

Commit 088b870

Browse files
Merge pull request #323 from Java-Discord/dynxsty/help_transactions
Optional Boolean For Disabling Recent Transaction in /help account
2 parents 0d51e76 + 0db7958 commit 088b870

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/main/java/net/javadiscord/javabot/systems/help/commands/subcommands/HelpAccountSubcommand.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ public class HelpAccountSubcommand extends SlashCommand.Subcommand {
3434
*/
3535
public HelpAccountSubcommand() {
3636
setSubcommandData(new SubcommandData("account", "Shows an overview of your Help Account.")
37-
.addOption(OptionType.USER, "user", "The user to check.", false)
37+
.addOption(OptionType.USER, "user", "If set, show the Help Account of the specified user instead.", false)
38+
.addOption(OptionType.BOOLEAN, "show-transactions", "Should the recent transactions be shown?", false)
3839
);
3940
}
4041

4142
@Override
4243
public void execute(@NotNull SlashCommandInteractionEvent event) {
4344
User user = event.getOption("user", event::getUser, OptionMapping::getAsUser);
45+
boolean showTransactions = event.getOption("show-transactions", false, OptionMapping::getAsBoolean);
4446
long totalThanks = DbActions.count(
4547
"SELECT COUNT(id) FROM help_channel_thanks WHERE helper_id = ?",
4648
s -> s.setLong(1, user.getIdLong())
@@ -51,28 +53,28 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
5153
);
5254
try {
5355
HelpAccount account = new HelpExperienceService(Bot.dataSource).getOrCreateAccount(user.getIdLong());
54-
event.replyEmbeds(buildHelpAccountEmbed(account, user, event.getGuild(), totalThanks, weekThanks)).queue();
56+
event.replyEmbeds(buildHelpAccountEmbed(account, user, event.getGuild(), totalThanks, weekThanks, showTransactions)).queue();
5557
} catch (SQLException e) {
5658
ExceptionLogger.capture(e, getClass().getSimpleName());
5759
Responses.error(event, e.getMessage()).queue();
5860
}
5961
}
6062

61-
private MessageEmbed buildHelpAccountEmbed(HelpAccount account, User user, Guild guild, long totalThanks, long weekThanks) {
62-
return new EmbedBuilder()
63+
private @NotNull MessageEmbed buildHelpAccountEmbed(HelpAccount account, @NotNull User user, Guild guild, long totalThanks, long weekThanks, boolean showTransactions) {
64+
return new EmbedBuilder()
6365
.setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl())
6466
.setTitle("Help Account")
6567
.setThumbnail(user.getEffectiveAvatarUrl())
6668
.setDescription("Here are some statistics about how you've helped others here.")
67-
.addField("Experience (BETA)", String.format("%s\n\n**Recent Transactions**\n```diff\n%s```",
68-
formatExperience(guild, account),
69-
formatTransactionHistory(user.getIdLong())), false)
69+
.addField("Experience (BETA)", String.format("%s%s",
70+
formatExperience(guild, account),
71+
showTransactions ? String.format("\n\n**Recent Transactions**\n```diff\n%s```", formatTransactionHistory(user.getIdLong())) : ""), false)
7072
.addField("Total Times Thanked", String.format("**%s**", totalThanks), true)
7173
.addField("Times Thanked This Week", String.format("**%s**", weekThanks), true)
7274
.build();
7375
}
7476

75-
private String formatTransactionHistory(long userId) {
77+
private @NotNull String formatTransactionHistory(long userId) {
7678
StringBuilder sb = new StringBuilder();
7779
try {
7880
HelpExperienceService service = new HelpExperienceService(Bot.dataSource);

src/main/java/net/javadiscord/javabot/util/WebhookUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import club.minnced.discord.webhook.external.JDAWebhookClient;
55
import club.minnced.discord.webhook.send.AllowedMentions;
66
import club.minnced.discord.webhook.send.WebhookMessageBuilder;
7-
import club.minnced.discord.webhook.send.component.Button;
87
import club.minnced.discord.webhook.send.component.LayoutComponent;
98
import net.dv8tion.jda.api.entities.Message;
109
import net.dv8tion.jda.api.entities.Message.Attachment;
@@ -69,10 +68,11 @@ public static void ensureWebhookExists(@NotNull TextChannel channel, Consumer<?
6968
* @param newMessageContent the new (custom) content
7069
* @param threadId the thread to send the message in or {@code 0} if the
7170
* message should be sent directly
71+
* @param components An optional array of {@link LayoutComponent}s.
7272
* @return a {@link CompletableFuture} representing the action of sending
7373
* the message
7474
*/
75-
public static CompletableFuture<Void> mirrorMessageToWebhook(@NotNull Webhook webhook, @NotNull Message originalMessage, String newMessageContent, long threadId, LayoutComponent... components) {
75+
public static CompletableFuture<Void> mirrorMessageToWebhook(@NotNull Webhook webhook, @NotNull Message originalMessage, String newMessageContent, long threadId, LayoutComponent @NotNull ... components) {
7676
JDAWebhookClient client = new WebhookClientBuilder(webhook.getIdLong(), webhook.getToken())
7777
.setThreadId(threadId).buildJDA();
7878
WebhookMessageBuilder message = new WebhookMessageBuilder().setContent(newMessageContent)

0 commit comments

Comments
 (0)