/* * Live check: Discord search total_results for a channel or a date range. * * Usage (from poc/): * VESKSLOP_SLOPBOT_ENABLED=1 VESKSLOP_SLOPBOT_STATE=/path/to/slopbot.json \ * tsx ../media-scrape/test/live-count.ts [afterIso] [beforeIso] */ import { loadSlopbotConfig, startSlopbot, stopSlopbot } from "../slopbot/index.js"; function snowflakeFromIso(iso: string): string { return String((BigInt(Date.parse(iso) - 1420070400000) << 22n)); } async function main() { const [channelId, guildId, after, before] = process.argv.slice(2); if (!channelId || !guildId) { console.error("usage: live-count.ts [afterIso] [beforeIso]"); process.exit(1); } const config = loadSlopbotConfig(); if (!config.enabled) { console.error("slopbot disabled: set VESKSLOP_SLOPBOT_ENABLED=1 and a token"); process.exit(1); } const client = await startSlopbot(config); try { const query = new URLSearchParams({ channel_id: channelId, limit: "1" }); if (after) query.set("min_id", snowflakeFromIso(after)); if (before) query.set("max_id", snowflakeFromIso(before)); for (const [label, path] of [ ["guild", `/guilds/${guildId}/messages/search`], ["channel", `/channels/${channelId}/messages/search`] ] as const) { try { const data = (await client.rest.get(path, { query })) as Record; console.log(`${label}: total_results=${String(data?.total_results)} keys=${Object.keys(data ?? {}).join(",")}`); } catch (error) { console.log(`${label}: error ${(error as Error).message}`); } } } finally { await stopSlopbot(client); } } void main();