- Added 'enabled' property to FunConfigSchema with a default value of true for better configuration management. - Refactored getFunConfig to return a complete default configuration when no data is found. - Improved globals.css by expanding CSS variables for light and dark themes, enhancing styling consistency across the application.
27 lines
890 B
TypeScript
27 lines
890 B
TypeScript
import type { Redis } from 'ioredis';
|
|
import { z } from 'zod';
|
|
|
|
const FUN_CONFIG_PREFIX = 'fun:config:';
|
|
|
|
export const FunConfigSchema = z.object({
|
|
enabled: z.boolean().default(true),
|
|
mediaEnabled: z.boolean().default(true)
|
|
});
|
|
|
|
export type FunConfig = z.infer<typeof FunConfigSchema>;
|
|
|
|
const DEFAULT_FUN_CONFIG: FunConfig = { enabled: true, mediaEnabled: true };
|
|
|
|
export async function getFunConfig(redis: Redis, guildId: string): Promise<FunConfig> {
|
|
const raw = await redis.get(`${FUN_CONFIG_PREFIX}${guildId}`);
|
|
if (!raw) {
|
|
return { ...DEFAULT_FUN_CONFIG };
|
|
}
|
|
const parsed = FunConfigSchema.safeParse(JSON.parse(raw));
|
|
return parsed.success ? parsed.data : { ...DEFAULT_FUN_CONFIG };
|
|
}
|
|
|
|
export async function setFunConfig(redis: Redis, guildId: string, config: FunConfig): Promise<void> {
|
|
await redis.set(`${FUN_CONFIG_PREFIX}${guildId}`, JSON.stringify(config));
|
|
}
|