43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import type { PoolConfig } from "npm:@types/pg";
|
|
import { BotMode, getConfig } from "./cfg/config.ts";
|
|
import type { BotConfig, CompiledConfig } from "./cfg/config.ts";
|
|
import * as path from "jsr:@std/path";
|
|
|
|
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 loadConfig = (): CompiledConfig => {
|
|
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,
|
|
admin_ids: [
|
|
MR_ANDERSON_ID,
|
|
]
|
|
}
|
|
return {
|
|
pgPoolCfg, botCfg,
|
|
migrationCfg: {
|
|
dropDb: cfg.drop_db,
|
|
applyMigrations: cfg.apply_migrations,
|
|
migrationsPath: import.meta.dirname ?
|
|
path.join(import.meta.dirname, 'migrations') : '/app/migrations',
|
|
}
|
|
}
|
|
}
|