Add the slopbot scaffold and discord.js dependency, unused
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user