55import java .io .ByteArrayOutputStream ;
66import java .io .IOException ;
77import java .time .LocalDate ;
8- import java .util .ArrayList ;
9- import java .util .Comparator ;
10- import java .util .HashMap ;
11- import java .util .LinkedHashMap ;
12- import java .util .List ;
13- import java .util .Map ;
8+ import java .util .*;
149import java .util .Map .Entry ;
15- import java .util .PriorityQueue ;
1610
1711import javax .imageio .ImageIO ;
1812
2418import net .discordjug .javabot .util .Plotter ;
2519import net .dv8tion .jda .api .EmbedBuilder ;
2620import net .dv8tion .jda .api .events .interaction .command .SlashCommandInteractionEvent ;
21+ import net .dv8tion .jda .api .interactions .commands .OptionMapping ;
22+ import net .dv8tion .jda .api .interactions .commands .OptionType ;
2723import net .dv8tion .jda .api .interactions .commands .build .SubcommandData ;
2824import net .dv8tion .jda .api .utils .FileUpload ;
2925import xyz .dynxsty .dih4jda .interactions .commands .application .SlashCommand ;
3430public class HelpStatisticsSubcommand extends SlashCommand .Subcommand {
3531
3632 private static final List <Pair <String , Color >> COLORS = List .of (
37- new Pair <>("Red" , Color .RED ) , new Pair <>("Blue" , Color .BLUE ) , new Pair <>("Yellow" , Color .YELLOW ),
38- new Pair <>("Green" , Color .GREEN ) , new Pair <>("Cyan" , Color .CYAN ) , new Pair <>("Magenta" , Color .MAGENTA ),
39- new Pair <>("Orange" , Color .ORANGE ) , new Pair <>("Pink" , Color .PINK ) , new Pair <>("Light gray" , Color .LIGHT_GRAY )
33+ new Pair <>("Red" , Color .decode ( "#D62728" )) , new Pair <>("Blue" , Color .decode ( "#1F77B4" )) , new Pair <>("Yellow" , Color .decode ( "#BCBD22" ) ),
34+ new Pair <>("Green" , Color .decode ( "#2CA02C" )) , new Pair <>("Cyan" , Color .decode ( "#17BECF" )) , new Pair <>("Magenta" , Color .decode ( "#9467BD" ) ),
35+ new Pair <>("Orange" , Color .decode ( "#FF7F0E" )) , new Pair <>("Pink" , Color .decode ( "#E377C2" )) , new Pair <>("Light gray" , Color .decode ( "#7F7F7F" ) )
4036 );
4137
4238 private final HelpTransactionRepository transactionRepository ;
43-
39+
40+ /**
41+ * Creates the help statistics subcommand.
42+ *
43+ * @param transactionRepository repository for help transactions
44+ */
4445 public HelpStatisticsSubcommand (HelpTransactionRepository transactionRepository ) {
4546 this .transactionRepository = transactionRepository ;
46- setCommandData (new SubcommandData ("stats" , "Shows an general plot about help activity in this server" ));
47+ setCommandData (new SubcommandData ("stats" , "Shows an general plot about help activity in this server" )
48+ .addOption (OptionType .BOOLEAN , "darkmode" , "generate a plot in dark mode." , false )
49+ );
50+
4751 }
4852
4953 @ Override
5054 public void execute (SlashCommandInteractionEvent event ) {
51-
55+ boolean darkMode = event .getOption ("darkmode" , false , OptionMapping ::getAsBoolean );
56+
5257 event .deferReply ().queue ();
5358
5459 List <Pair <MonthInYear ,HelpAccount >> transactionWeights = transactionRepository .getTotalTransactionWeightByMonthAndUsers (LocalDate .now ().withDayOfMonth (1 ).minusYears (1 ).atStartOfDay ());
@@ -75,8 +80,8 @@ public void execute(SlashCommandInteractionEvent event) {
7580 }
7681 plotData .add (new Pair <>(position .getMonth () + " " + position .getYear (), new Plotter .Bar (entriesForThisMonth )));
7782 }
78-
79- BufferedImage plot = new Plotter (plotData , "General helper statistics" ).plot ();
83+
84+ BufferedImage plot = new Plotter (plotData , "Help Statistics" , "Monthly assistance provided to community members" , darkMode ).plot ();
8085 try (ByteArrayOutputStream os = new ByteArrayOutputStream ()){
8186 ImageIO .write (plot , "png" , os );
8287 FileUpload upload = FileUpload .fromData (os .toByteArray (), "image.png" );
0 commit comments