SpinShare Referee Bot refbot.ellite.dev/overlay
at main 71 lines 1.5 kB view raw
1import path from 'node:path'; 2import fs from 'node:fs'; 3import { fileURLToPath } from 'node:url'; 4 5const __filename = fileURLToPath(import.meta.url); 6const __dirname = path.dirname(__filename); 7 8const SLUG = process.argv[2]; 9 10if (!SLUG) { 11 console.error('Usage: node scripts/dumpSets.js <tournament-slug>'); 12 process.exit(1); 13} 14 15async function query(q, variables = {}) { 16 const res = await fetch('https://api.start.gg/gql/alpha', { 17 method: 'POST', 18 headers: { 19 'Content-Type': 'application/json', 20 'Authorization': `Bearer ${process.env.STARTGG}`, 21 }, 22 body: JSON.stringify({ query: q, variables }), 23 }); 24 const json = await res.json(); 25 if (json.errors) throw new Error(json.errors[0].message); 26 return json.data; 27} 28 29async function main() { 30 const data = await query(` 31 query($slug: String!) { 32 tournament(slug: $slug) { 33 name 34 events { 35 name 36 phases { 37 name 38 phaseGroups(query: { page: 1, perPage: 20 }) { 39 nodes { 40 rounds { 41 number 42 bestOf 43 } 44 sets(sortType: CALL_ORDER) { 45 nodes { 46 id 47 round 48 fullRoundText 49 state 50 completedAt 51 winnerId 52 displayScore 53 slots { 54 entrant { name } 55 } 56 } 57 } 58 } 59 } 60 } 61 } 62 } 63 } 64 `, { slug: SLUG }); 65 66 const out = path.join(__dirname, 'sets_dump.json'); 67 fs.writeFileSync(out, JSON.stringify(data, null, 2)); 68 console.log(`written to ${out}`); 69} 70 71main().catch(console.error);