11package net .javadiscord .javabot .systems .help .commands ;
22
3- import xyz .dynxsty .dih4jda .interactions .commands .application .SlashCommand ;
43import net .dv8tion .jda .api .EmbedBuilder ;
54import net .dv8tion .jda .api .entities .Guild ;
65import net .dv8tion .jda .api .entities .MessageEmbed ;
1312import net .javadiscord .javabot .data .h2db .DbActions ;
1413import net .javadiscord .javabot .systems .help .HelpExperienceService ;
1514import net .javadiscord .javabot .systems .help .model .HelpAccount ;
16- import net .javadiscord .javabot .systems .help .model .HelpTransaction ;
1715import net .javadiscord .javabot .util .ExceptionLogger ;
1816import net .javadiscord .javabot .util .Pair ;
1917import net .javadiscord .javabot .util .Responses ;
2018import net .javadiscord .javabot .util .StringUtils ;
2119import org .jetbrains .annotations .NotNull ;
2220import org .springframework .dao .DataAccessException ;
21+ import xyz .dynxsty .dih4jda .interactions .commands .application .SlashCommand ;
2322
2423/**
2524 * <h3>This class represents the /help account command.</h3>
@@ -33,22 +32,21 @@ public class HelpAccountSubcommand extends SlashCommand.Subcommand {
3332
3433 /**
3534 * The constructor of this class, which sets the corresponding {@link SubcommandData}.
36- * @param dbActions An object responsible for various database actions
35+ *
36+ * @param dbActions An object responsible for various database actions
3737 * @param helpExperienceService Service object that handles Help Experience Transactions.
3838 */
3939 public HelpAccountSubcommand (DbActions dbActions , HelpExperienceService helpExperienceService ) {
4040 this .dbActions = dbActions ;
4141 this .helpExperienceService = helpExperienceService ;
4242 setCommandData (new SubcommandData ("account" , "Shows an overview of your Help Account." )
4343 .addOption (OptionType .USER , "user" , "If set, show the Help Account of the specified user instead." , false )
44- .addOption (OptionType .BOOLEAN , "show-transactions" , "Should the recent transactions be shown?" , false )
4544 );
4645 }
4746
4847 @ Override
4948 public void execute (@ NotNull SlashCommandInteractionEvent event ) {
5049 User user = event .getOption ("user" , event ::getUser , OptionMapping ::getAsUser );
51- boolean showTransactions = event .getOption ("show-transactions" , false , OptionMapping ::getAsBoolean );
5250 long totalThanks = dbActions .count (
5351 "SELECT COUNT(id) FROM help_channel_thanks WHERE helper_id = ?" ,
5452 s -> s .setLong (1 , user .getIdLong ())
@@ -59,40 +57,26 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
5957 );
6058 try {
6159 HelpAccount account = helpExperienceService .getOrCreateAccount (user .getIdLong ());
62- event .replyEmbeds (buildHelpAccountEmbed (account , user , event .getGuild (), totalThanks , weekThanks , showTransactions )).queue ();
60+ event .replyEmbeds (buildHelpAccountEmbed (account , user , event .getGuild (), totalThanks , weekThanks )).queue ();
6361 } catch (DataAccessException e ) {
6462 ExceptionLogger .capture (e , getClass ().getSimpleName ());
6563 Responses .error (event , e .getMessage ()).queue ();
6664 }
6765 }
6866
69- private @ NotNull MessageEmbed buildHelpAccountEmbed (HelpAccount account , @ NotNull User user , Guild guild , long totalThanks , long weekThanks , boolean showTransactions ) {
70- return new EmbedBuilder ()
67+ private @ NotNull MessageEmbed buildHelpAccountEmbed (HelpAccount account , @ NotNull User user , Guild guild , long totalThanks , long weekThanks ) {
68+ return new EmbedBuilder ()
7169 .setAuthor (user .getAsTag (), null , user .getEffectiveAvatarUrl ())
7270 .setTitle ("Help Account" )
7371 .setThumbnail (user .getEffectiveAvatarUrl ())
7472 .setDescription ("Here are some statistics about how you've helped others here." )
75- .addField ("Experience (BETA)" , String .format ("%s%s" ,
76- formatExperience (guild , account ),
77- showTransactions ? String .format ("\n \n **Recent Transactions**\n ```diff\n %s```" , formatTransactionHistory (user .getIdLong ())) : "" ), false )
73+ .addField ("Experience (BETA)" , formatExperience (guild , account ), false )
7874 .addField ("Total Times Thanked" , String .format ("**%s**" , totalThanks ), true )
7975 .addField ("Times Thanked This Week" , String .format ("**%s**" , weekThanks ), true )
8076 .build ();
8177 }
8278
83- private @ NotNull String formatTransactionHistory (long userId ) {
84- StringBuilder sb = new StringBuilder ();
85- try {
86- for (HelpTransaction t :helpExperienceService .getRecentTransactions (userId , 3 )) {
87- sb .append (t .format ()).append ("\n \n " );
88- }
89- } catch (DataAccessException e ) {
90- ExceptionLogger .capture (e , getClass ().getSimpleName ());
91- }
92- return sb .toString ().length () > 0 ? sb .toString () : "No recent transactions" ;
93- }
94-
95- private String formatExperience (Guild guild , HelpAccount account ) {
79+ private @ NotNull String formatExperience (Guild guild , @ NotNull HelpAccount account ) {
9680 Pair <Role , Double > previousRoleAndXp = account .getPreviousExperienceGoal (guild );
9781 Pair <Role , Double > currentRoleAndXp = account .getCurrentExperienceGoal (guild );
9882 Pair <Role , Double > nextRoleAndXp = account .getNextExperienceGoal (guild );
@@ -102,13 +86,13 @@ private String formatExperience(Guild guild, HelpAccount account) {
10286
10387 if (currentRoleAndXp .first () != null ) {
10488 // Show the current experience level on the first line.
105- sb .append (String .format ("%s\ n " , currentRoleAndXp .first ().getAsMention ()));
89+ sb .append (String .format ("%s% n" , currentRoleAndXp .first ().getAsMention ()));
10690 }
10791 // Below, show the progress to the next level, or just the XP if they've reached the max level.
10892 if (goalXp > 0 ) {
10993 double percentToGoalXp = (currentXp / goalXp ) * 100.0 ;
110- sb .append (String .format ("%.0f / %.0f XP (%.2f%%) until %s\ n " , currentXp , goalXp , percentToGoalXp , nextRoleAndXp .first ().getAsMention ()))
111- .append (String .format ("%.0f Total XP\ n " , account .getExperience ()))
94+ sb .append (String .format ("%.0f / %.0f XP (%.2f%%) until %s% n" , currentXp , goalXp , percentToGoalXp , nextRoleAndXp .first ().getAsMention ()))
95+ .append (String .format ("%.0f Total XP% n" , account .getExperience ()))
11296 .append (StringUtils .buildTextProgressBar (percentToGoalXp / 100.0 , 20 ));
11397 } else {
11498 sb .append (String .format ("%.0f Total XP (MAX. LEVEL)" , account .getExperience ()));
0 commit comments