Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435import { db } from '../src/db.js';
const [, , discordId, ...rest] = process.argv;if (!discordId) { console.error('usage: npm run user:add -- <discord_id> [--did <did>] [--inactive]'); process.exit(1);}
const flags = new Map();for (let i = 0; i < rest.length; i++) { if (rest[i].startsWith('--')) flags.set(rest[i].slice(2), rest[i + 1] ?? true);}
const did = flags.get('did') || null;const active = flags.has('inactive') ? 0 : 1;
db.prepare(` INSERT INTO users (discord_id, active) VALUES (?, ?) ON CONFLICT(discord_id) DO UPDATE SET active = excluded.active, updated_at = strftime('%s','now')`).run(discordId, active);
const user = db.prepare(`SELECT id, discord_id, active FROM users WHERE discord_id = ?`).get(discordId);
let job = null;if (did) { db.prepare(`INSERT OR IGNORE INTO jobs (user_id, did) VALUES (?, ?)`).run(user.id, did); job = db.prepare(`SELECT id, user_id, did FROM jobs WHERE user_id = ? AND did = ?`).get(user.id, did);}
console.log('upserted user', user);if (job) console.log('upserted job', job);