Skip to content

Commit

Permalink
Channel stats can now be filtered by author
Browse files Browse the repository at this point in the history
  • Loading branch information
SquirrelKiev committed Nov 15, 2024
1 parent a266c0d commit ee8cafd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Asahi/Modules/Statistics/StatisticsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,17 @@ await Context.Guild.GetCurrentUserAsync(),
public async Task ChannelsWithMostReactionsSlash(
[Summary(description: "Optional board to filter results by.")]
[Autocomplete(typeof(HighlightsNameAutocomplete))]
string? board = null
string board = "",
[Summary(description: "Optional user to filter results by.")]
IUser? user = null
)
{
await DeferAsync();

var postgresHappyUserId = user?.Id ?? 0;

await using var context = dbService.GetDbContext();

var postgresHappyBoard = board ?? "";

var results = await context.Database
.SqlQuery<IdToReactionCount>($"""
WITH UniqueMessages AS (
Expand All @@ -126,7 +128,8 @@ SELECT DISTINCT ON ("OriginalMessageId")
"TotalUniqueReactions"
FROM "CachedHighlightedMessages"
WHERE "HighlightBoardGuildId" = {Context.Guild.Id}
AND ({postgresHappyBoard} = '' OR "HighlightBoardName" = {postgresHappyBoard})
AND ({board} = '' OR "HighlightBoardName" = {board})
AND ({postgresHappyUserId} = 0 OR "AuthorId" = {postgresHappyUserId})
ORDER BY "OriginalMessageId", "TotalUniqueReactions" DESC
)
SELECT "OriginalMessageChannelId" AS Id, SUM("TotalUniqueReactions") as TotalReactions FROM UniqueMessages
Expand Down

0 comments on commit ee8cafd

Please sign in to comment.