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:
103
packages/shared/src/owner.ts
Normal file
103
packages/shared/src/owner.ts
Normal 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';
|
||||
Reference in New Issue
Block a user