- 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.
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import { config } from 'dotenv';
|
|
import { z } from 'zod';
|
|
|
|
config();
|
|
|
|
const emptyToUndefined = (value: unknown) =>
|
|
value === '' || value === undefined || value === null ? undefined : value;
|
|
|
|
const EnvSchema = z.object({
|
|
NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),
|
|
BOT_TOKEN: z.string().min(1),
|
|
BOT_CLIENT_ID: z.string().min(1),
|
|
BOT_GUILD_ID: z.preprocess(emptyToUndefined, z.string().min(1).optional()),
|
|
DATABASE_URL: z.string().url(),
|
|
REDIS_URL: z.string().url(),
|
|
LOG_LEVEL: z.string().default('info'),
|
|
DEFAULT_LOCALE: z.enum(['de', 'en']).default('de'),
|
|
BACKUP_RETENTION_DAYS: z.coerce.number().int().positive().default(14),
|
|
BACKUP_CRON: z.string().default('0 3 * * *'),
|
|
BACKUP_DIR: z.string().default('/backups'),
|
|
METRICS_TOKEN: z.preprocess(emptyToUndefined, z.string().min(1).optional()),
|
|
HEALTH_PORT: z.coerce.number().int().positive().default(8080),
|
|
PUBLIC_BASE_URL: z.string().url().default('http://localhost:8080'),
|
|
TWITCH_CLIENT_ID: z.preprocess(emptyToUndefined, z.string().min(1).optional()),
|
|
TWITCH_CLIENT_SECRET: z.preprocess(emptyToUndefined, z.string().min(1).optional()),
|
|
OWNER_USER_IDS: z.preprocess(
|
|
emptyToUndefined,
|
|
z
|
|
.string()
|
|
.optional()
|
|
.transform((value) =>
|
|
value
|
|
? value
|
|
.split(',')
|
|
.map((id) => id.trim())
|
|
.filter((id) => id.length > 0)
|
|
: []
|
|
)
|
|
),
|
|
WEBUI_URL: z.preprocess(emptyToUndefined, z.string().url().optional()),
|
|
SUPPORT_SERVER_URL: z.preprocess(emptyToUndefined, z.string().url().optional())
|
|
});
|
|
|
|
export const env = EnvSchema.parse(process.env);
|
|
|
|
export function buildBotInviteUrl(clientId = env.BOT_CLIENT_ID): string {
|
|
const url = new URL('https://discord.com/api/oauth2/authorize');
|
|
url.searchParams.set('client_id', clientId);
|
|
url.searchParams.set('permissions', '8');
|
|
url.searchParams.set('scope', 'bot applications.commands');
|
|
return url.toString();
|
|
}
|