2323import org .togetherjava .tjbot .config .Config ;
2424import org .togetherjava .tjbot .db .Database ;
2525
26+ import java .math .BigDecimal ;
2627import java .time .*;
2728import java .time .format .TextStyle ;
2829import java .util .*;
3839/**
3940 * Command that displays the top helpers of a given time range.
4041 * <p>
41- * Top helpers are measured by their message count in help channels, as set by
42+ * Top helpers are measured by their message length in help channels, as set by
4243 * {@link TopHelpersMessageListener}.
4344 */
4445public final class TopHelpersCommand extends SlashCommandAdapter {
@@ -53,7 +54,7 @@ public final class TopHelpersCommand extends SlashCommandAdapter {
5354 /**
5455 * Creates a new instance.
5556 *
56- * @param database the database containing the message counts of top helpers
57+ * @param database the database containing the message records of top helpers
5758 * @param config the config to use for this
5859 */
5960 public TopHelpersCommand (@ NotNull Database database , @ NotNull Config config ) {
@@ -138,12 +139,13 @@ private boolean handleHasAuthorRole(@NotNull Member author, @NotNull IReplyCallb
138139
139140 private @ NotNull List <TopHelperResult > computeTopHelpersDescending (long guildId ,
140141 @ NotNull TimeRange timeRange ) {
141- return database .read (context -> context .select (HELP_CHANNEL_MESSAGES .AUTHOR_ID , DSL .count ())
142+ return database .read (context -> context
143+ .select (HELP_CHANNEL_MESSAGES .AUTHOR_ID , DSL .sum (HELP_CHANNEL_MESSAGES .MESSAGE_LENGTH ))
142144 .from (HELP_CHANNEL_MESSAGES )
143145 .where (HELP_CHANNEL_MESSAGES .GUILD_ID .eq (guildId )
144146 .and (HELP_CHANNEL_MESSAGES .SENT_AT .between (timeRange .start (), timeRange .end ())))
145147 .groupBy (HELP_CHANNEL_MESSAGES .AUTHOR_ID )
146- .orderBy (DSL .count ().desc ())
148+ .orderBy (DSL .two ().desc ())
147149 .limit (TOP_HELPER_LIMIT )
148150 .fetch (Records .mapping (TopHelperResult ::new )));
149151 }
@@ -174,9 +176,9 @@ private static void handleTopHelpers(@NotNull Collection<TopHelperResult> topHel
174176 @ Nullable Member member ) {
175177 String id = Long .toString (topHelper .authorId ());
176178 String name = member == null ? "UNKNOWN_USER" : member .getEffectiveName ();
177- String messageCount = Integer .toString (topHelper .messageCount ());
179+ String messageLengths = Long .toString (topHelper .messageLengths (). longValue ());
178180
179- return List .of (id , name , messageCount );
181+ return List .of (id , name , messageLengths );
180182 }
181183
182184 private static @ NotNull String dataTableToString (@ NotNull Collection <List <String >> dataTable ,
@@ -185,7 +187,7 @@ private static void handleTopHelpers(@NotNull Collection<TopHelperResult> topHel
185187 List .of (new ColumnSetting ("Id" , HorizontalAlign .RIGHT ),
186188 new ColumnSetting ("Name" , HorizontalAlign .RIGHT ),
187189 new ColumnSetting (
188- "Message count (for %s)" .formatted (timeRange .description ()),
190+ "Message lengths (for %s)" .formatted (timeRange .description ()),
189191 HorizontalAlign .RIGHT )));
190192 }
191193
@@ -206,14 +208,15 @@ private static void handleTopHelpers(@NotNull Collection<TopHelperResult> topHel
206208 return AsciiTable .getTable (AsciiTable .BASIC_ASCII_NO_DATA_SEPARATORS , dataTable , columns );
207209 }
208210
209- private record TimeRange (Instant start , Instant end , String description ) {
211+ private record TimeRange (@ NotNull Instant start , @ NotNull Instant end ,
212+ @ NotNull String description ) {
210213 }
211214
212215
213- private record TopHelperResult (long authorId , int messageCount ) {
216+ private record TopHelperResult (long authorId , @ NotNull BigDecimal messageLengths ) {
214217 }
215218
216219
217- private record ColumnSetting (String headerName , HorizontalAlign alignment ) {
220+ private record ColumnSetting (@ NotNull String headerName , @ NotNull HorizontalAlign alignment ) {
218221 }
219222}
0 commit comments