Something went wrong. Try again.
A Bluesky Secret Santa Bot
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273/** * Organizer tools against the bot DB ($SANTA_DB, default santa.db). * * npm run admin -- participants * npm run admin -- pair <santa> <nicelister> # DIDs or handles * npm run admin -- unpair <santa> <nicelister> * npm run admin -- approve-pending # DEV ONLY: mark all pending answers clean * npm run admin -- phase <signup|matching|shipping|receiving|closed|released> */import { resolveDid } from '../bot/config.js'import { nowIso, openDb } from '../db/index.js'import type { ExchangePhase } from '../db/schema.js'import { exportPending, importResults } from '../moderation/queue.js'
const exchangeId = process.env.SANTA_EXCHANGE_ID ?? 'ss-2026'const db = await openDb(process.env.SANTA_DB ?? 'santa.db')const [cmd, ...args] = process.argv.slice(2)
async function participantId(who: string) { const did = await resolveDid(who) const p = await db.selectFrom('participant').select('id').where('exchange_id', '=', exchangeId).where('did', '=', did).executeTakeFirst() if (!p) throw new Error(`${who} (${did}) is not a participant`) return p.id}
try { switch (cmd) { case 'participants': { const rows = await db .selectFrom('participant') .leftJoin('match as gives', 'gives.santa_id', 'participant.id') .leftJoin('participant as nl', 'nl.id', 'gives.nicelister_id') .select(['participant.id', 'participant.did', 'participant.status', 'nl.did as gifting']) .where('participant.exchange_id', '=', exchangeId) .execute() console.table(rows) break } case 'pair': case 'unpair': { const [a, b] = args if (!a || !b) throw new Error(`usage: ${cmd} <santa> <nicelister>`) const santa_id = await participantId(a) const nicelister_id = await participantId(b) if (cmd === 'pair') { await db.insertInto('match').values({ exchange_id: exchangeId, santa_id, nicelister_id, kind: 'initial', created_at: nowIso() }).execute() } else { await db.deleteFrom('match').where('santa_id', '=', santa_id).where('nicelister_id', '=', nicelister_id).execute() } console.log('ok') break } case 'approve-pending': { const items = await exportPending(db) const s = await importResults(db, items.map((i) => ({ answer_id: i.answer_id, categorizer: 'manual-dev', categorizer_version: '0', verdict: 'clean' as const }))) console.log(s) break } case 'phase': { const phase = args[0] as ExchangePhase if (!phase) throw new Error('usage: phase <phase>') await db.updateTable('exchange').set({ phase }).where('id', '=', exchangeId).execute() console.log('ok') break } default: console.error('commands: participants | pair <santa> <nicelister> | unpair ... | approve-pending | phase <phase>') process.exitCode = 1 }} finally { await db.destroy()}