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
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Slopbot entry point.
|
||||
*
|
||||
* Scaffold only: the daemon does not import this yet. Checkpoint C4 adds the
|
||||
* scrape backend; docs/slopbot.md is the module contract.
|
||||
*/
|
||||
|
||||
import type { Client } from "discord.js";
|
||||
import { loadSlopbotConfig, type SlopbotConfig } from "./config.js";
|
||||
|
||||
/** Kept as a type so the discord.js dependency is type-checked before C4 uses it. */
|
||||
export type SlopbotClient = Client;
|
||||
|
||||
export { loadSlopbotConfig, type SlopbotConfig };
|
||||
|
||||
/** View Channels + Read Message History. The bot reads only; it never sends. */
|
||||
const PERMISSIONS = String((1 << 10) | (1 << 16));
|
||||
|
||||
/** The invite URL the Bot tab renders once a client ID is configured. */
|
||||
export function slopbotInviteUrl(clientId: string): string {
|
||||
return `https://discord.com/oauth2/authorize?client_id=${encodeURIComponent(
|
||||
clientId
|
||||
)}&scope=bot%20applications.commands&permissions=${PERMISSIONS}`;
|
||||
}
|
||||
Reference in New Issue
Block a user