mic-bot/config.ts

43 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2024-10-19 10:00:35 +00:00
import type { PoolConfig } from "npm:@types/pg";
2024-10-24 08:35:13 +00:00
import { BotMode, getConfig } from "./cfg/config.ts";
2024-10-19 10:00:35 +00:00
import type { BotConfig, CompiledConfig } from "./cfg/config.ts";
2024-10-19 10:14:06 +00:00
import * as path from "jsr:@std/path";
2024-10-19 10:00:35 +00:00
const MIC_CHAT_ID = -1002438254268
const MR_ANDERSON_ID = 1843444763
export const DEFAULT_DB_HOST = "localhost"
export const DEFAULT_DB_USER = "mic"
export const DEFAULT_DB_NAME = "mic"
export const DEFAULT_DB_PORT = 5432
export const DEFAULT_DB_TLS = false
export const LOCALES_DIR = "bot/locales"
2024-10-19 10:00:35 +00:00
2024-10-19 10:47:33 +00:00
export const loadConfig = (): CompiledConfig => {
2024-10-25 18:10:48 +00:00
const cfg = getConfig()
const pgPoolCfg: PoolConfig = {
host: cfg.db_host || DEFAULT_DB_HOST,
user: cfg.db_user || DEFAULT_DB_USER,
database: cfg.db_name || DEFAULT_DB_NAME,
port: cfg.db_port || DEFAULT_DB_PORT,
ssl: cfg.db_tls || DEFAULT_DB_TLS,
password: cfg.db_password,
}
const botCfg: BotConfig = {
mode: BotMode.normal,
bot_token: cfg.bot_token,
chat_id: MIC_CHAT_ID,
locales_dir: LOCALES_DIR,
admin_ids: [ MR_ANDERSON_ID ]
2024-10-25 18:10:48 +00:00
}
return {
pgPoolCfg, botCfg,
migrationCfg: {
dropDb: cfg.drop_db,
applyMigrations: cfg.apply_migrations,
migrationsPath: import.meta.dirname ?
path.join(import.meta.dirname, 'migrations') : '/app/migrations',
2024-10-19 10:00:35 +00:00
}
2024-10-25 18:10:48 +00:00
}
2024-10-25 17:35:12 +00:00
}