Something went wrong. Try again.
Track players on a Minecraft server through their Dynmap [tangled.org mirror]
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import { z } from "zod/v4";import { WebhookClient, type WebhookClientData } from "discord.js";import { Pool, type PoolConfig } from "pg";import type { Duration } from "date-fns";import * as fs from "node:fs";import logger from "./logger";import type { LaunchOptions } from "puppeteer";
const webhookConfigSchema = z.object({ client: z.custom<WebhookClientData>().transform((a) => new WebhookClient(a)), serverUrl: z.string(), schedules: z .record( z.string(), z.object({ cron: z.string(), range: z.custom<Duration>(), message: z .string() .default( "[Server activity](%url%) (%id%) for past %range%\n-# from <t:%from%:F>\n-# to <t:%to%:F>", ), }), ) .refine((a) => Object.keys(a).length >= 1), puppeteer: z.custom<LaunchOptions & { timezone?: string }>().optional(),});const configSchema = z.object({ dynmapLink: z.url(), db: z.custom<PoolConfig>().transform((a) => new Pool(a)), categories: z .record( z.string(), z.object({ uuids: z .string() .regex(/^[0-9a-fA-F]{32}$/u) .array(), colour: z.string().regex(/^#(?:[0-9a-f]{3}){1,2}$/u), }), ) .default({}), webhooks: webhookConfigSchema.optional(), deleteOldCategories: z.boolean().default(false), countsApproxMaxLength: z.int().gte(1).default(1000),});
export type Config = z.infer<typeof configSchema>;
// eslint-disable-next-line consistent-returnexport function getConfig(): Config { if (process.env.CONFIG) { logger.info("Using config found in `CONFIG`"); return configSchema.parse(JSON.parse(process.env.CONFIG)); }
const configPath = process.env.CONFIG_PATH ?? (process.env.DOCKER ? "../config.json" : "config.json"); if (fs.existsSync(configPath)) { logger.info(`Using config found in \`${configPath}\``); return configSchema.parse( JSON.parse(fs.readFileSync(configPath).toString()), ); }
logger.error(`Could not find config at ${configPath}`); process.exit(1);}export const config = getConfig();