Implement Owner Panel features and maintenance mode handling

- Introduced the Owner Panel with new routes and UI components for managing guilds, user blacklists, feature flags, and bot presence.
- Added maintenance mode functionality to prevent non-owner users from executing commands during maintenance periods.
- Enhanced localization with new keys for Owner Panel features in both English and German.
- Updated job processing to include a presence refresh job, ensuring the bot's status is regularly updated.
- Improved environment configuration to support owner user IDs for access control.
This commit is contained in:
smueller
2026-07-22 16:10:30 +02:00
parent bcbfa07697
commit 8a8aefb4fb
42 changed files with 2385 additions and 50 deletions

View File

@@ -9,6 +9,7 @@ export * from './phase4.js';
export * from './phase5.js';
export * from './phase6.js';
export * from './dashboard.js';
export * from './owner.js';
export const LocaleSchema = z.enum(['de', 'en']);
export type Locale = z.infer<typeof LocaleSchema>;
@@ -49,6 +50,7 @@ const de: Dictionary = {
'generic.botMissingPermission': 'Dem Bot fehlt die erforderliche Berechtigung ({permission}).',
'generic.invalidRegex': 'Ungültiges Regex-Muster.',
'generic.error': 'Es ist ein Fehler aufgetreten.',
'generic.maintenance': 'Nexumi ist derzeit im Wartungsmodus. Bitte versuche es später erneut.',
'generic.unknownCommand': 'Unbekannter Befehl.',
'moderation.success': 'Aktion erfolgreich ausgeführt.',
'moderation.reason.none': 'Kein Grund angegeben',
@@ -523,6 +525,7 @@ const en: Dictionary = {
'generic.botMissingPermission': 'Bot lacks required permission ({permission}).',
'generic.invalidRegex': 'Invalid regex pattern.',
'generic.error': 'An error occurred.',
'generic.maintenance': 'Nexumi is currently in maintenance mode. Please try again later.',
'generic.unknownCommand': 'Unknown command.',
'moderation.success': 'Action executed successfully.',
'moderation.reason.none': 'No reason provided',

View File

@@ -0,0 +1,40 @@
import { describe, expect, it } from 'vitest';
import {
BotPresenceConfigSchema,
FeatureFlagUpsertSchema,
ownerRoleAtLeast,
OwnerTeamUpsertSchema
} from './owner.js';
describe('owner schemas', () => {
it('parses presence config', () => {
const parsed = BotPresenceConfigSchema.parse({
status: 'online',
activityType: 'Playing',
activityText: 'nexumi.de',
rotatingMessages: ['a', 'b'],
maintenanceMode: false,
maintenanceMessage: null
});
expect(parsed.activityText).toBe('nexumi.de');
});
it('ranks owner roles', () => {
expect(ownerRoleAtLeast('ADMIN', 'SUPPORT')).toBe(true);
expect(ownerRoleAtLeast('VIEWER', 'ADMIN')).toBe(false);
});
it('validates team and flags', () => {
expect(
OwnerTeamUpsertSchema.parse({ userId: '123456789012345678', role: 'SUPPORT', note: null }).role
).toBe('SUPPORT');
expect(
FeatureFlagUpsertSchema.parse({
key: 'new.module',
enabled: true,
rolloutPercent: 10,
whitelistGuildIds: []
}).rolloutPercent
).toBe(10);
});
});

View File

@@ -0,0 +1,103 @@
import { z } from 'zod';
const snowflake = z.string().regex(/^\d{17,20}$/);
export const OwnerRoleSchema = z.enum(['VIEWER', 'SUPPORT', 'ADMIN', 'OWNER']);
export type OwnerRole = z.infer<typeof OwnerRoleSchema>;
export const OWNER_ROLE_RANK: Record<OwnerRole, number> = {
VIEWER: 1,
SUPPORT: 2,
ADMIN: 3,
OWNER: 4
};
export function ownerRoleAtLeast(role: OwnerRole, minimum: OwnerRole): boolean {
return OWNER_ROLE_RANK[role] >= OWNER_ROLE_RANK[minimum];
}
export const BotPresenceStatusSchema = z.enum(['online', 'idle', 'dnd', 'invisible']);
export const BotActivityTypeSchema = z.enum(['Playing', 'Listening', 'Watching', 'Competing']);
export const BotPresenceConfigSchema = z.object({
status: BotPresenceStatusSchema,
activityType: BotActivityTypeSchema,
activityText: z.string().min(1).max(128),
rotatingMessages: z.array(z.string().min(1).max(128)).max(20),
maintenanceMode: z.boolean(),
maintenanceMessage: z.string().max(500).nullable()
});
export type BotPresenceConfig = z.infer<typeof BotPresenceConfigSchema>;
export const BotPresenceConfigPatchSchema = BotPresenceConfigSchema.partial().refine(
(value) => Object.keys(value).length > 0,
{ message: 'At least one field is required' }
);
export const OwnerTeamMemberSchema = z.object({
id: z.string().optional(),
userId: snowflake,
role: OwnerRoleSchema,
note: z.string().max(500).nullable().optional()
});
export type OwnerTeamMember = z.infer<typeof OwnerTeamMemberSchema>;
export const OwnerTeamUpsertSchema = OwnerTeamMemberSchema;
export const FeatureFlagSchema = z.object({
id: z.string().optional(),
key: z
.string()
.min(1)
.max(64)
.regex(/^[a-z0-9._-]+$/i),
enabled: z.boolean(),
rolloutPercent: z.number().int().min(0).max(100),
whitelistGuildIds: z.array(snowflake)
});
export type FeatureFlag = z.infer<typeof FeatureFlagSchema>;
export const FeatureFlagUpsertSchema = FeatureFlagSchema;
export const GlobalUserBlacklistSchema = z.object({
id: z.string().optional(),
userId: snowflake,
reason: z.string().max(500).nullable().optional(),
note: z.string().max(1000).nullable().optional()
});
export type GlobalUserBlacklist = z.infer<typeof GlobalUserBlacklistSchema>;
export const GuildBlacklistSchema = z.object({
id: z.string().optional(),
guildId: snowflake,
reason: z.string().max(500).nullable().optional()
});
export type GuildBlacklist = z.infer<typeof GuildBlacklistSchema>;
export const ChangelogEntrySchema = z.object({
id: z.string().optional(),
version: z.string().min(1).max(32),
title: z.string().min(1).max(200),
body: z.string().min(1).max(10000),
publishedAt: z.string().datetime().optional()
});
export type ChangelogEntry = z.infer<typeof ChangelogEntrySchema>;
export const OwnerAuditEntrySchema = z.object({
id: z.string(),
actorUserId: z.string(),
action: z.string(),
targetType: z.string().nullable(),
targetId: z.string().nullable(),
createdAt: z.string()
});
export type OwnerAuditEntry = z.infer<typeof OwnerAuditEntrySchema>;
export const PRESENCE_REDIS_KEY = 'bot:presence';