47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
/*
|
|
* Slopbot — the dedicated bot core for media scraping.
|
|
*
|
|
* Scaffold only: nothing imports this yet. The scrape backend lands at
|
|
* checkpoint C4 (see ../CURRENT.md). Setup, limits, and security: docs/slopbot.md.
|
|
*/
|
|
|
|
import { readFileSync } from "node:fs";
|
|
|
|
export interface SlopbotConfig {
|
|
/** Kill switch. Off unless VESKSLOP_SLOPBOT_ENABLED=1 and a token exists. */
|
|
enabled: boolean;
|
|
/** Bot token. Never logged, never committed. */
|
|
token: string | null;
|
|
/** Application ID, used to render the invite URL. */
|
|
clientId: string | null;
|
|
}
|
|
|
|
interface SlopbotStateFile {
|
|
token?: string;
|
|
clientId?: string;
|
|
}
|
|
|
|
function readStateFile(path: string): SlopbotStateFile {
|
|
try {
|
|
return JSON.parse(readFileSync(path, "utf8")) as SlopbotStateFile;
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
/** Read the slopbot settings from the environment, then from the state file. */
|
|
export function loadSlopbotConfig(
|
|
env: NodeJS.ProcessEnv = process.env,
|
|
stateFilePath = env.VESKSLOP_SLOPBOT_STATE
|
|
): SlopbotConfig {
|
|
const state = stateFilePath ? readStateFile(stateFilePath) : {};
|
|
const token = env.VESKSLOP_SLOPBOT_TOKEN ?? state.token ?? null;
|
|
const clientId = env.VESKSLOP_SLOPBOT_CLIENT_ID ?? state.clientId ?? null;
|
|
|
|
return {
|
|
enabled: env.VESKSLOP_SLOPBOT_ENABLED === "1" && token !== null,
|
|
token,
|
|
clientId
|
|
};
|
|
}
|