Add consent site + consent-only follow recorder bot

Discord OAuth login -> explicit consent (3 checkboxes, versioned text) ->
bot follows consenting users into voice channels and records only their
per-user streams. Revoke stops recording immediately and optionally deletes
files; consent log kept; export to training wav only for active consents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-11 11:43:06 +09:00
parent 0abadfb7e2
commit 6e0801ea1c
19 changed files with 2550 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
import fs from 'node:fs';
import path from 'node:path';
export interface Config {
botToken: string;
clientId: string;
clientSecret: string;
/** 사이트 바깥 주소 (끝 / 없음). OAuth 돌아올 주소는 <publicUrl>/callback */
publicUrl: string;
host: string;
port: number;
dataDir: string;
operatorName: string;
/** 비어 있으면 봇이 들어간 모든 서버 */
allowedGuildIds: Set<string>;
channelNotice: boolean;
/** 테스트에서 가짜 디스코드 API 로 바꿀 때만 */
discordApi: string;
discordAuthorizeUrl: string;
}
/** KEY=VALUE 형식 .env (따옴표 · 주석 지원, 이미 있는 환경 변수는 덮어쓰지 않음) */
export function loadDotEnv(file: string): void {
if (!fs.existsSync(file)) return;
for (const line of fs.readFileSync(file, 'utf8').split(/\r?\n/)) {
const m = /^\s*([A-Z0-9_]+)\s*=\s*(.*?)\s*$/.exec(line);
if (!m || line.trimStart().startsWith('#')) continue;
let v = m[2];
if (/^(['"]).*\1$/.test(v)) v = v.slice(1, -1);
if (process.env[m[1]] === undefined) process.env[m[1]] = v;
}
}
export function loadConfig(env: NodeJS.ProcessEnv = process.env, needBot = true): Config {
const req = (k: string) => {
const v = env[k]?.trim();
if (!v) throw new Error(`환경 변수 ${k} 가 비어 있습니다 (.env.example 참고)`);
return v;
};
const publicUrl = req('PUBLIC_URL').replace(/\/+$/, '');
const u = new URL(publicUrl);
if (u.protocol !== 'https:' && !['localhost', '127.0.0.1'].includes(u.hostname)) {
throw new Error('PUBLIC_URL 은 https 여야 합니다 (localhost 만 예외)');
}
return {
botToken: needBot ? req('DISCORD_BOT_TOKEN') : env.DISCORD_BOT_TOKEN?.trim() ?? '',
clientId: req('DISCORD_CLIENT_ID'),
clientSecret: req('DISCORD_CLIENT_SECRET'),
publicUrl,
host: env.HOST?.trim() || '127.0.0.1',
port: Number(env.PORT || 8787),
dataDir: path.resolve(env.DATA_DIR?.trim() || './data'),
operatorName: env.OPERATOR_NAME?.trim() || '이 서비스 운영자',
allowedGuildIds: new Set((env.ALLOWED_GUILD_IDS ?? '').split(',').map((s) => s.trim()).filter(Boolean)),
channelNotice: (env.CHANNEL_NOTICE ?? '1') !== '0',
discordApi: env.DISCORD_API?.trim() || 'https://discord.com/api/v10',
discordAuthorizeUrl: env.DISCORD_AUTHORIZE_URL?.trim() || 'https://discord.com/oauth2/authorize',
};
}