Enhance dashboard overview with activity summary and sidebar commands

- Integrated activity summary into the Guild Overview page, displaying message count, voice minutes, and active user count for the last 7 days.
- Updated sidebar to include a new "Commands" link for easier navigation.
- Added corresponding localization keys for activity metrics in both English and German JSON files.
This commit is contained in:
smueller
2026-07-22 15:54:03 +02:00
parent e0b4077552
commit 39cca96fed
8 changed files with 785 additions and 8 deletions

View File

@@ -0,0 +1,31 @@
import type { ActivityStatSummary } from '@nexumi/shared';
import { prisma } from './prisma';
const SUMMARY_WINDOW_DAYS = 7;
/**
* Aggregates `ActivityStat` rows (written by the bot's leveling/stats
* modules) for the last {@link SUMMARY_WINDOW_DAYS} days into totals shown
* on the guild overview page.
*/
export async function getActivitySummary(guildId: string): Promise<ActivityStatSummary> {
const since = new Date(Date.now() - SUMMARY_WINDOW_DAYS * 24 * 60 * 60 * 1000);
const [aggregate, activeUsers] = await Promise.all([
prisma.activityStat.aggregate({
where: { guildId, day: { gte: since } },
_sum: { messageCount: true, voiceMinutes: true }
}),
prisma.activityStat.findMany({
where: { guildId, day: { gte: since } },
distinct: ['userId'],
select: { userId: true }
})
]);
return {
messageCount: aggregate._sum.messageCount ?? 0,
voiceMinutes: aggregate._sum.voiceMinutes ?? 0,
activeUserCount: activeUsers.length
};
}