Enhance bot and WebUI functionality with new features and environment updates
- Added support for new environment variables in `.env.example` for public site and legal operator information. - Integrated core commands into the bot's command structure for improved functionality. - Implemented a new `publishBotStatus` function to update bot status in Redis, enhancing monitoring capabilities. - Updated the landing page to include features, invite links, and support server access, improving user experience. - Enhanced localization with new keys for core commands and landing page elements in both English and German. - Improved error handling and logging for bot presence updates and status publishing.
This commit is contained in:
56
apps/webui/src/lib/public-status.ts
Normal file
56
apps/webui/src/lib/public-status.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { BOT_STATUS_REDIS_KEY, BotStatusPayloadSchema, PRESENCE_REDIS_KEY } from '@nexumi/shared';
|
||||
import { prisma } from './prisma';
|
||||
import { redis } from './redis';
|
||||
|
||||
export async function getPublicStatus() {
|
||||
const [rawStatus, rawPresence, updates] = await Promise.all([
|
||||
redis.get(BOT_STATUS_REDIS_KEY),
|
||||
redis.get(PRESENCE_REDIS_KEY),
|
||||
prisma.changelogEntry.findMany({
|
||||
orderBy: { publishedAt: 'desc' },
|
||||
take: 10
|
||||
})
|
||||
]);
|
||||
|
||||
let botStatus = null;
|
||||
if (rawStatus) {
|
||||
const parsed = BotStatusPayloadSchema.safeParse(JSON.parse(rawStatus));
|
||||
botStatus = parsed.success ? parsed.data : null;
|
||||
}
|
||||
|
||||
let maintenanceMode = false;
|
||||
if (rawPresence) {
|
||||
try {
|
||||
const presence = JSON.parse(rawPresence) as { maintenanceMode?: boolean };
|
||||
maintenanceMode = Boolean(presence.maintenanceMode);
|
||||
} catch {
|
||||
maintenanceMode = false;
|
||||
}
|
||||
} else {
|
||||
const row = await prisma.botPresenceConfig.findUnique({ where: { id: 'singleton' } });
|
||||
maintenanceMode = row?.maintenanceMode ?? false;
|
||||
}
|
||||
|
||||
const degraded = !botStatus;
|
||||
const overall = maintenanceMode ? 'maintenance' : degraded ? 'degraded' : 'operational';
|
||||
|
||||
return {
|
||||
ok: !maintenanceMode,
|
||||
overall,
|
||||
maintenanceMode,
|
||||
degraded,
|
||||
shards: botStatus?.shards ?? [],
|
||||
apiLatencyMs: botStatus?.apiLatencyMs ?? null,
|
||||
guildCount: botStatus?.guildCount ?? (await prisma.guild.count()),
|
||||
uptimeSeconds: botStatus?.uptimeSeconds ?? null,
|
||||
updates: updates.map((entry) => ({
|
||||
id: entry.id,
|
||||
version: entry.version,
|
||||
title: entry.title,
|
||||
body: entry.body,
|
||||
publishedAt: entry.publishedAt.toISOString(),
|
||||
isIncident: entry.version.toLowerCase().startsWith('incident')
|
||||
})),
|
||||
updatedAt: botStatus?.updatedAt ?? new Date().toISOString()
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user