Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/javadiscord/javabot/util/WebhookUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,10 +68,11 @@ public static void ensureWebhookExists(@NotNull TextChannel channel, Consumer<?
* @param newMessageContent the new (custom) content
* @param threadId the thread to send the message in or {@code 0} if the
* message should be sent directly
* @param components An optional array of {@link LayoutComponent}s.
* @return a {@link CompletableFuture} representing the action of sending
* the message
*/
public static CompletableFuture<Void> mirrorMessageToWebhook(@NotNull Webhook webhook, @NotNull Message originalMessage, String newMessageContent, long threadId, LayoutComponent... components) {
public static CompletableFuture<Void> 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)
Expand Down